coderello / laravel-passport-social-grant

🔒 API authentication via social networks for your Laravel application
https://packagist.org/packages/coderello/laravel-passport-social-grant
MIT License
174 stars 20 forks source link

Ability to add auth_method as Login or Register #38

Closed bansalvinay closed 4 years ago

bansalvinay commented 4 years ago

Is it possible to specify the authentication type?

If we want to differentiate if the request is for login or registration?

Something like this :

RequestOptions::FORM_PARAMS => [
        'grant_type' => 'social', 
        'client_id' => $clientId, 
        'client_secret' => $clientSecret, 
        'provider' => $providerName, 
        'access_token' => $providerAccessToken,
        'method' => 'register',
    ],

This way, we can reject users trying to login without registering. They may be having multiple google accounts, and by mistake select wrong account.

ankurk91 commented 4 years ago

You can send anything in payload , and can retrieve in resolveUserByProviderCredentials() method.

<?php

namespace App\Resolvers;

use Coderello\SocialGrant\Resolvers\SocialUserResolverInterface;
use Illuminate\Contracts\Auth\Authenticatable;
use Laravel\Socialite\Facades\Socialite;

class SocialUserResolver implements SocialUserResolverInterface
{
    /**
     * Resolve user by provider credentials.
     *
     * @param string $provider
     * @param string $accessToken
     *
     * @return Authenticatable|null
     */
    public function resolveUserByProviderCredentials(string $provider, string $accessToken): ?Authenticatable
    {
       $requestType = request("method");
       // Take decision based on user input
    }
}