Can't use Facebook PHP SDK with Laravel Social Sentry Auth - oauth-2.0

I've installed sentry social auth (http://www.getplatform.com/manuals/sentrysocial) on my site http://ratewait.com and it works fine.
I'd like to offer functionality with the Facebook SDK now and having trouble. I installed the SDK with the bundle github.com/kapv89/laravel-fb-sdk-bundle and as a name spaced library like: wrttn.in/b6df85
But every time I call $user = $facebook->getUser( ); it returns 0.
I'm guessing it has something to do with the fact that I'm using Sentry to authenticate people. Can anyone help?
Thanks
adam

So I figured this out.
The Sentry Social bundle for laravel stores your access token in a field called Token in a table called social_authentication.
I made a model called social, which links to that table and created a relationship to my User.
Then, added the following code in my controller (this should be moved to a model...)
$user = Sentry::user();
$user = $user->id;
$user = User::with('social')->find($user);
$access_token = $user->social->token;
$facebook->setAccessToken($access_token);
$friends = $facebook->api('/me/');
This is probably not the most efficient way, but it works.

Related

Facing problem in Create AD user using Microsoft Graph APIs

I have to use Microsoft Active Directory APIs to create an active directory account which will then be synced with Azure. I am using Microsoft Graph SDK for PHP to implement the functionality.
Created APP in AD account
Retrieved TenantId, ClientId and Secreat keys.
Using SDK, retrieved access token.
Next called function to create user.
Here I initially got permission related issues. In AD APP, I gave full permission for directory read. In permissions section I could not find any permission option related to Create User. Also in "Microsoft Graph SDK for PHP", while using create user function, I am getting "Class 'User' not found in D:\xampp\htdocs\test\vendor\microsoft\microsoft-graph\src\Http\GraphResponse.php" error.
Here I would like to confirm if this is possible to create an active directory account which will then return license key in response to be used by the newly created user?
Any help would be greatly appreciated.
Many Thanks.
The permissions required for creating the user:
The request body for creating the user:
please refer this example:
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new User();
$requestBody->setAccountEnabled(true);
$requestBody->setDisplayName('Adele Vance');
$requestBody->setMailNickname('AdeleV');
$requestBody->setUserPrincipalName('AdeleV#contoso.onmicrosoft.com');
$passwordProfile = new PasswordProfile();
$passwordProfile->setForceChangePasswordNextSignIn(true);
$passwordProfile->setPassword('xWwvJ]6NMw+bWH-d');
$requestBody->setPasswordProfile($passwordProfile);
$requestResult = $graphServiceClient->users()->post($requestBody);
Hope this helps.

Setting up Google Calendar API

I'm trying to use the Google Calendar API in one of my projects. To do so, I need to set up OAuth access in the Google API console.
But when creating the consent-form (which is required to use OAuth), I get a meaningless error message:
The translation is as follows:
A problem occured. Please check your data and try again . If you have
not given any details, the problem may solve itself . In this case, we
recommend that you wait and try again later.
I have set the E-Mail address and project name. The optional fields were left blank.
So far I have not been able to solve the problem. I tried to wait for hours/days. I tried three different browsers. I also tried to contact Google support. All without success.
After days of trying, this is the solution:
Create another Google account
Using your old account, add the new account as an owner to your Google API project in the console
Log in with your new user account and accept the invitation
Create the OAuth consent form with the new user account
I have no idea WHY this worked, but it did.

Login with facebook or google using Oauth2 library in symfony2

I am using fosuserbundle for login and registration in my symfony 2.6 project.
Now I want to allow user to login via facebook or google account.
I want to use Oauth2 library of friendsofsymfony getting from here https://packagist.org/packages/friendsofsymfony/oauth2-php
I have installed library using "friendsofsymfony/oauth2-php": "1.1.*#dev" in composer.phar and updated vendors. But I am not able to find out the documentation which can show the steps to configure and use in login.
It should work with fosuserbundle. Can anyone suggest me where can I get steps how can I use Oauth2 library in my project?
You can use HWIOAuthBundle to enable login with facebook or google and many more social networks.
Here is a tutorial on how to setup this bundle in your application : https://gist.github.com/danvbe/4476697
Also if you use this bundle you should check my gist : https://gist.github.com/antoinemineau/8836621#file-fosubuserprovider-php-L47, i added an if statement which prevents the code to be executed if the api are not responding as expected.
Here is example how to login via Facebook https://github.com/stfalcon-studio/lost-and-found
It uses HWIOAuthBundle + FOSUserBundle + custom user provider
You can easily add Google or any other resource owner which is present in HWIOAuthBundle. But then you also need to rewrite a bit user provider.
This answer is correct: https://stackoverflow.com/a/28879098/2400373
I used this manual for the integration:
https://gist.github.com/danvbe/4476697
But is necesary two changes for Symfony3.
First:
In the code of file: services.yml on Symfony3 is other location, the correct location is: //app/config/services.yml and change this line:
arguments: [#fos_user.user_manager,{facebook: facebook_id, google: google_id}]
for this:
arguments: ['#fos_user.user_manager',{facebook: facebook_id, google: google_id}]
Second change is in the file: //app/config/routing.yml
change this line:
pattern: /login/check-facebook
for this:
path: /login/facebook

How to configure scope of information I gather from Google OAuth in MeteorJS package?

Tried searching google and StackOverflow but with no luck, perhaps your knowledge of Google-OAuth can help...
I installed the base google-oauth package via meteor.
meteor add accounts-ui
meteor add accounts-google
Then I tested it out and saw that it requests the user to permit access to 2 main groups on information, the first being the user's email and the second being "basic information" about the users account, e.g. Name, Gender, Public Profile URL etc etc.
I only want the email and no other information. I tried to look for where the URI request is built in my meteor app, someurlprobablygoogle.com/scope=email&profile or whatever, but I can't seem to find it.
To configure Google OAuth in Meteor you need to meteor add service-configuration and meteor add accounts-google.
You should be able to modify the requestPermissions setting when calling your login method like so:
Meteor.loginWithGoogle({
requestPermissions: ['email']
}, function (err) {
if (err)
Session.set('errorMessage', err.reason || 'Unknown error');
});
Shooooots

Google calendar v3 returns 403 Insufficient Permission

I've been trying to access Calendar v3 API with a service account. I have already added the scope https://www.googleapis.com/auth/calendar from the admin console and shared my calendar with that service account's email address.
I have also been accessing https://www.googleapis.com/auth/coordinate scope with the very same service account and it works fine.
Also, tried revoking access as said here: Why is Google Calendar API (oauth2) responding with 'Insufficient Permission'?
All that, and I am still getting;
{"error"=>
{"errors"=>
[{"domain"=>"global",
"reason"=>"insufficientPermissions",
"message"=>"Insufficient Permission"}],
"code"=>403,
"message"=>"Insufficient Permission"}}
Am i missing something?
Try to add to you scope 'userinfo.email' and enable in Developers console "Contacts API" and "Google+ API". I've spent 2 weeks searching for answer to this question, and this trick has worked for me.
Did you have any joy with this? I've hit the same brick wall.
UPDATE:
$key = file_get_contents($key_file_location);
$scopes = array('https://www.googleapis.com/auth/calendar');
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
$scopes,
$key
);
This worked for my authorization, after sharing the calendar with the service email account.
I think if you use Google Calendar Quickstart for Ruby, I think you should delete your credentials in the specified path...I try it and it works well... You can see where the credentials is put in here
CREDENTIALS_PATH = File.join(Dir.home, '.credentials',
"calendar-ruby-quickstart.yaml")
In your home dir, you may find a dir which Google store your credentials after you approve Google request to access your data.
first of all change
static string[] Scopes = { CalendarService.Scope.CalendarReadonly };
to
static string[] Scopes = { CalendarService.Scope.Calendar };
and then in your documents folder delete .credentials folder
and run again.
this worked for me!

Resources