adaojunior / passport-social-grant Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
can you help me, where I create SocialUserResover?
and where I can implement this ?
I have a code like this in AuthController
` public function providerCallback(Request $request, $provider)
{
try {
$account = \Socialite::driver($provider)->stateless()->user();
$user = User::firstOrNew(['email' => $account->email]);
// update details
$user->name = $account->name;
$user->avatar = $account->avatar;
$user->save();
$provider = UserProvider::firstOrNew(['provider' => $provider, 'provider_id' => $account->id]);
$provider->user_id = $user->id;
$provider->save();
$http = new \GuzzleHttp\Client;
$response = $http->post('http://api.blazbluz.dev/oauth/token', [
'form_params' => [
'grant_type' => 'social',
'client_id' => 2,
'client_secret' => 'NQ7QZP49VmBEAEaOOWCWIONvpzU4T6MBDF4oWUdU',
'network' => 'facebook', /// or any other network that your server is able to resolve.
'access_token' => $account->token,
],
]);
} catch (InvalidArgumentException $e) {
return abort(404, 'Driver undefined.');
} catch (\GuzzleHttp\Exception\ClientException $e) {
return redirect('auth/login');
}
}`
is that wrong ? because it give me error 500
The scope is usually empty when using your package, even when yo uadd the scope. Is there anyway to make it non empty?
Hi @adaojunior
I've updated my code with the latest version.
I saw that you have changed the parameter "network" by "provider". It's OK but an app for TV that I can't update at all, is using the old version "network". So I can't do the update, the biggest problem is my update is concerning the Laravel 6 upgrade, so with Passport 8 and your latest version too.
Do you have an idea how I can override your logic in my project API to allow both "provider" and "network" values because I can't break the TV app, please?
Idea: allow to customize the parameter name instead of an hard-coded string
Bests
Any plan?
Thank 1k !
See #50
Hi,
@adaojunior what do you think about pass the request object as additional argument in the resolve() method ?
(hintypeless to make it backward compatible, expecting ServerRequestInterface instance)
I think it may make it more powerfull and more customizable. For example, allowing to check more expected form parameters, or headers.
Laravel 5.6 is out and passport 5.0 too ! You should update your composer.json to make it work with it !
Thanks
Hi i have created a function and return data but i am always getting same output
{"error":"invalid_credentials","message":"The user credentials were incorrect."}
How can i escape above return
I am testing the library and this error is killing me
Target [Adaojunior\Passport\SocialUserResolverInterface] is not instantiable while building [\Laravel\Passport\Http\Controllers\AccessTokenController].
thanks :-)
Hi! After installing adaojunior/passport-social-grant package and followed installation steps my app generate this error.Can someone help me?
How do you actually use this package, could someone post a complete example?
The example repository is down and after installing and following the instructions of the readme I only get this error:
Class Adaojunior\PassportSocialGrant\SocialGrantServiceProvider not found
Edit: No error after fixing the provider registration. An implementation example would still be appreciated.
Hi,
Laravel 9 now requires PHP 8.0.2 or greater.
I got this error (obviously) :
- Root composer.json requires adaojunior/passport-social-grant ^v4.2.0 -> satisfiable by adaojunior/passport-social-grant[v4.2.0].
- adaojunior/passport-social-grant v4.2.0 requires php ^7.2 -> your php version (8.1.2) does not satisfy that requirement.
hey,
I got this error while installing it, I am using laravel 5.4 and passport 2.0 ...
how can i fix this issue ?
[ReflectionException]
Class hash does not exist
Script php artisan optimize handling the post-update-cmd event returned with error code 1
Installation failed, reverting ./composer.json to its original content.
Hi there!
I'd like to use this package in my project but I can't see a license for it. Is it ok to use this?
I need some help about the implementation (never used socialite with passport before), and found that this package seems to be the answer for me.
So the routes I have:
Route::get('login/{provider}', 'SocialLoginController@redirect')->where(['provider' => 'facebook|google']);
Route::get('login/{provider}/callback', 'SocialLoginController@handleRedirectCallback')->where(['provider' => 'facebook|google']);
And my current SocialLoginController.php:
public function redirect($provider)
{
return Socialite::driver($provider)->stateless()->redirect();
}
public function handleRedirectCallback($provider)
{
$socialUserInfo = Socialite::driver($provider)->stateless()->user();
// etc..
}
So the code above is the very basic authentication for socialite (without passport), and since I want to combine the API to be able to get the access token and refresh token, I need to use passport.
So what I have done until now:
$this->app->singleton(SocialUserResolverInterface::class, SocialUserResolver::class);
class SocialUserResolver implements SocialUserResolverInterface
public function resolve($network, $accessToken, $accessTokenSecret = null)
{
switch ($network) {
case 'facebook':
return $this->authWithFacebook($accessToken);
break;
case 'google':
return $this->authWithGoogle($accessToken);
break;
default:
throw SocialGrantException::invalidNetwork();
break;
}
}
protected function authWithFacebook($accessToken)
{
$account = Socialite::driver('facebook')->userFromToken($accessToken);
}
protected function authWithGoogle($accessToken)
{
$account = Socialite::driver('google')->userFromToken($accessToken);
}
So the questions:
use SocialUserResolver
inside SocialLoginController?function resolve
from SocialUserResolver class,Please help me to clarify things up..
Any suggestion gladly appreciated. Thank you!
Hi, good work @adaojunior but I think it's good to add oauth1 compatibility with using access_token_secret, I made this by modifying these two files:
SocialGrant.php
protected function validateUser(ServerRequestInterface $request)
{
$user = $this->resolver->resolve(
$this->getParameter('network', $request),
$this->getParameter('access_token', $request),
$this->getParameter('access_token_secret', $request) <-- add this line
);
SocialUserResolverInterface.php
public function resolve($network, $accessToken, $accessTokenSecret); <-- add accessTokenSecret param
No more an issue
Hi, i tried to make a test request but im getting this error using github login with socialite
The error indicates that my access_token is incorrect but this is my token that github gave me back after authenticating.
This is my SocialUserResolver, i placed it in App\Http\Controllers\Auth
namespace App\Http\Controllers\Auth;
use Adaojunior\Passport\SocialGrantException;
use Adaojunior\Passport\SocialUserResolverInterface;
class SocialUserResolver implements SocialUserResolverInterface
{
/**
* Resolves user by given network and access token.
*
* @param string $network
* @param string $accessToken
* @return \Illuminate\Contracts\Auth\Authenticatable
*/
public function resolve($network, $accessToken, $accessTokenSecret = null)
{
switch ($network) {
case 'github':
return $this->authWithGithub($accessToken);
break;
default:
throw SocialGrantException::invalidNetwork();
break;
}
}
/**
* Resolves user by facebook access token.
*
* @param string $accessToken
* @return \App\User
*/
protected function authWithGithub($accessToken)
{
}
}
And this is my AppServiceProvider
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Adaojunior\Passport\SocialUserResolverInterface;
use App\Http\Controllers\Auth\SocialUserResolver;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->singleton(SocialUserResolverInterface::class, SocialUserResolver::class);
}
}
Using version ^4.0 for adaojunior/passport-social-grant ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Your requirements could not be resolved to an installable set of packages. Problem 1 - Installation request for laravel/passport (locked at v7.5.1, required as ^7.2) -> satisfiable by laravel/passport[v7.5.1]. - adaojunior/passport-social-grant v4.0 requires laravel/passport ^8.0 -> satisfiable by laravel/passport[8.x-dev]. - adaojunior/passport-social-grant v4.0-beta.1 requires laravel/passport ^8.0 -> satisfiable by laravel/passport[8.x-dev]. - Conclusion: don't install laravel/passport 8.x-dev - Installation request for adaojunior/passport-social-grant ^4.0 -> satisfiable by adaojunior/passport-social-grant[v4.0, v4.0-beta.1]. Installation failed, reverting ./composer.json to its original content.
I have code like this
`
namespace App\Modules\User;
use Adaojunior\Passport\SocialGrantException;
use Adaojunior\Passport\SocialUserResolverInterface;
class SocialUserResolver implements SocialUserResolverInterface
{
/**
* Resolves user by given network and access token.
*
* @param string $network
* @param string $accessToken
* @return \Illuminate\Contracts\Auth\Authenticatable
*/
public function resolve($network, $accessToken, $accessTokenSecret = null)
{
switch ($network) {
case 'facebook':
return $this->authWithFacebook($accessToken);
break;
default:
throw SocialGrantException::invalidNetwork();
break;
}
}
/**
* Resolves user by facebook access token.
*
* @param string $accessToken
* @return \App\User
*/
protected function authWithFacebook($accessToken)
{
// dd($accessToken);
$account = \Socialite::driver('facebook')->userFromToken($accessToken);
}
}`
And AuthController.php
stateless()->redirect(); } catch (InvalidArgumentException $e) { return abort(404, 'Driver tidak dikenal.'); } } public function providerCallback(Request $request, $provider) { try { $account = \Socialite::driver($provider)->stateless()->user(); // dd($account->accessToken); $user = User::firstOrNew(['email' => $account->email]); // update details $user->name = $account->name; $user->avatar = $account->avatar; $user->save(); $provider = UserProvider::firstOrNew(['provider' => $provider, 'provider_id' => $account->id]); $provider->user_id = $user->id; $provider->save(); // \Auth::login($user, true); /*$user = \Socialite::driver('facebook')->userFromToken($account->token); dd($user);*/ $http = new \GuzzleHttp\Client; return $response = $http->post('http://api.blazbluz.dev/oauth/token', [ 'form_params' => [ 'grant_type' => 'social', 'client_id' => 2, 'client_secret' => 'NQ7QZP49VmBEAEaOOWCWIONvpzU4T6MBDF4oWUdU', 'network' => 'facebook', /// or any other network that your server is able to resolve. 'access_token' => $account->token, ], ]); } catch (InvalidArgumentException $e) { return abort(404, 'Driver tidak dikenal.'); }/* catch (\GuzzleHttp\Exception\ClientException $e) { dd('dd'); }*/ } /** * Resolves user by given network and access token. * * @param string $network * @param string $accessToken * @return \Illuminate\Contracts\Auth\Authenticatable */ } ` ![Uploading Screenshot_358.png…]() I have code like this ` namespace App\Modules\User; use Adaojunior\Passport\SocialGrantException; use Adaojunior\Passport\SocialUserResolverInterface; class SocialUserResolver implements SocialUserResolverInterface { /** * Resolves user by given network and access token. * * @param string $network * @param string $accessToken * @return \Illuminate\Contracts\Auth\Authenticatable */ public function resolve($network, $accessToken, $accessTokenSecret = null) { switch ($network) { case 'facebook': return $this->authWithFacebook($accessToken); break; default: throw SocialGrantException::invalidNetwork(); break; } } /** * Resolves user by facebook access token. * * @param string $accessToken * @return \App\User */ protected function authWithFacebook($accessToken) { // dd($accessToken); $account = \Socialite::driver('facebook')->userFromToken($accessToken); } }` And AuthController.php ` ![Uploading Screenshot_358.png…]() stateless()->redirect(); } catch (InvalidArgumentException $e) { return abort(404, 'Driver tidak dikenal.'); } } public function providerCallback(Request $request, $provider) { try { $account = \Socialite::driver($provider)->stateless()->user(); // dd($account->accessToken); $user = User::firstOrNew(['email' => $account->email]); // update details $user->name = $account->name; $user->avatar = $account->avatar; $user->save(); $provider = UserProvider::firstOrNew(['provider' => $provider, 'provider_id' => $account->id]); $provider->user_id = $user->id; $provider->save(); // \Auth::login($user, true); /*$user = \Socialite::driver('facebook')->userFromToken($account->token); dd($user);*/ $http = new \GuzzleHttp\Client; return $response = $http->post('http://api.blazbluz.dev/oauth/token', [ 'form_params' => [ 'grant_type' => 'social', 'client_id' => 2, 'client_secret' => 'NQ7QZP49VmBEAEaOOWCWIONvpzU4T6MBDF4oWUdU', 'network' => 'facebook', /// or any other network that your server is able to resolve. 'access_token' => $account->token, ], ]); } catch (InvalidArgumentException $e) { return abort(404, 'Driver tidak dikenal.'); }/* catch (\GuzzleHttp\Exception\ClientException $e) { dd('dd'); }*/ } /** * Resolves user by given network and access token. * * @param string $network * @param string $accessToken * @return \Illuminate\Contracts\Auth\Authenticatable */ } `I'm using Laravel Passport with https://github.com/dusterio/lumen-passport because my application is based on Lumen so the question is: Is this extension is supported for lumen ?
Thanks
When using any other grants provided with the Passport
.. i can always find the user object by $request->user()
or Auth::user()
by when using social
grant the user is null
I successfully set up passport-social-grant package in my project, and it works well, but i am trying to return the user details such as (first name, last name, email) but i am not getting these details to return.
Hey adaojunior, I'm trying to install the package through Composer and getting this error:
satisfiable by laravel/passport[1.0.x-dev, v1.0.0, v1.0.1, v1.0.10, v1.0.11, v1.0. 12, v1.0.13, v1.0.14, v1.0.15, v1.0.16, v1.0.17, v1.0.2, v1.0.3, v1.0.4, v1.0.5, v1.0.6, v1.0.7, v1.0.8, v1.0.9] but these conflict with your requirements or minimum-s tability.
Your package requires laravel/passport: ^1.0, is it possible to use it somehow with passports actual version?
I have implemented as described. But i still getting this error: 'The authorization grant type is not supported by the authorization server. Do i miss something?
Hello, I'm having some trouble when trying to use the package. I've:
composer require adaojunior/passport-social-grant
config\app.php
(had to do it manually, don't know why Laravel didn't registered automatically - v5.5): /*
* Package Service Providers...
*/
Adaojunior\Passport\SocialGrantServiceProvider::class,
AppServiceProvider.php
: public function register()
{
$this->app->singleton(
'Adaojunior\Passport\SocialUserResolverInterface',
'App\Utils\SocialUserResolver');
}
namespace App\Utils;
use Adaojunior\Passport\SocialGrantException;
use Adaojunior\Passport\SocialUserResolverInterface;
use Laravel\Socialite\Facades\Socialite;
class SocialUserResolver implements SocialUserResolverInterface
{
/**
* Resolves user by given network and access token.
*
* @param string $network
* @param string $accessToken
* @param null $accessTokenSecret
* @return \Illuminate\Http\JsonResponse|mixed
* @throws SocialGrantException
*/
public function resolve($network, $accessToken, $accessTokenSecret = null)
{
switch ($network) {
case 'facebook':
return $this->authWithFacebook($accessToken);
break;
default:
throw SocialGrantException::invalidNetwork();
break;
}
}
/**
* Resolves user by facebook access token.
*
* @param string $accessToken
* @return \Illuminate\Http\JsonResponse
*/
protected function authWithFacebook($accessToken)
{
$user = Socialite::driver('facebook')->userFromToken($accessToken);
if ( ! is_null($user) ) {
return $user;
}
else {
return response()->json([
"message" => "invalid_credentials",
"errors" => "The facebook's id of the user does not exist in the system.",
], 404);
}
}
}
AuthController
:// some other code
public function facebookLogin(FacebookLoginRequest $request)
$request->request->add([
'grant_type' => 'social',
'client_id' => 'YYYYYYYYYYYY',
'client_secret' => 'XXXXXXXXXXXXXXXXXXXXX',
'network' => 'facebook',
'access_token' => $request->facebook_token,
]);
$proxy = Request::create(
'/oauth/token',
'POST'
);
return Route::dispatch($proxy);
}
// some other code
But after all that, i'me getting this error response, it seems that Passport doesn't recognize the grant_type
that the package defines:
{
"error": "unsupported_grant_type",
"message": "The authorization grant type is not supported by the authorization server.",
"hint": "Check the `grant_type` parameter"
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.