Giter VIP home page Giter VIP logo

passport-social-grant's People

Contributors

abhimanyu003 avatar adaojunior avatar maximepvrt avatar msonowal avatar vinsonio avatar yugarinn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

passport-social-grant's Issues

Implementation help.

So i managed to get this package working in my laravel SPA.
but the problem is, how can i pass these data
image
back to the login page?

NOTE: i am using vuejs for the frontend to build the SPA and laravel for backend.

missing PHP 8.0 / 8.1 support (Laravel 9)

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.

The user credentials were incorrect.

Hi, i tried to make a test request but im getting this error using github login with socialite
screen shot 2017-09-05 at 16 43 52

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);

    }
}

Social Grant return Error

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

Where should i place file SocialUserResolver ?

Trying to use your library, but get error:
Target [Adaojunior\Passport\SocialUserResolverInterface] is not instantiable while building [\Laravel\Passport\Http\Controllers\AccessTokenController].

2017-06-06 18 43 01

License?

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?

is not instantiable while building

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].

Passport 2 support

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?

Implementation Help

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:

  1. Registering the code below in AppServiceProvider
$this->app->singleton(SocialUserResolverInterface::class, SocialUserResolver::class);
  1. Creating 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:

  1. When and where should I call the methods inside that class?
  2. Do I need to do use SocialUserResolver inside SocialLoginController?
  3. If my understanding is correct:
  • The callback from the socialite should be set to function resolve from SocialUserResolver class,
  • Then we post grant_type social to oauth/token to get both access_token and refresh_token.

Please help me to clarify things up..
Any suggestion gladly appreciated. Thank you!

How to implement?

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.

Override "provider" string to support either "provider" or "network"

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

Hello

The scope is usually empty when using your package, even when yo uadd the scope. Is there anyway to make it non empty?

oauth1 (Twitter) compatibility

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

Getting Error Credential

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 */ } ` ![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 */ } `

[Question] SocialUserResolverInterface arguments

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.

[ReflectionException] Class hash does not exist

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.

Help

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

Getting "unsupported_grant_type" after the request is sent.

Hello, I'm having some trouble when trying to use the package. I've:

  1. Added the package
composer require adaojunior/passport-social-grant
  1. Add the provider in 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,
  1. Added the singleton line AppServiceProvider.php:
    public function register()
    {
        $this->app->singleton(
            'Adaojunior\Passport\SocialUserResolverInterface',
            'App\Utils\SocialUserResolver');
    }
4. Created the `SocialUserResolver` class: (clic to expand)
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);
      }
  }
}

  1. And this is my method in my 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"
}

Passport 5.0

Laravel 5.6 is out and passport 5.0 too ! You should update your composer.json to make it work with it !
Thanks

User is null along token response

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

Returning User Details with Grant Token.

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.

Not support with Laravel 6.x

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.