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

OAuth 1 Support #21

Closed steve228uk closed 4 years ago

steve228uk commented 4 years ago

Fixes #7 by adding an optional access_token_secret parameter to requests.

ankurk91 commented 4 years ago

What about getting such extra parameter via request itself.

<?php

namespace App\Resolvers;

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

class SocialUserResolver implements SocialUserResolverInterface
{
    public function resolveUserByProviderCredentials(string $provider, string $accessToken): ?Authenticatable
    {
        $access_token_secret = request('access_token_secret');
        $anyOtherParameterSentWithRequest = request()->input('whatever');

        // Return the user that corresponds to provided credentials.
        // If the credentials are invalid, then return NULL.
    }
}

This way, we no need to introduce new parameter to this method, and end consumer is responsible to capture any other input sent in request.

imnpc commented 4 years ago
<?php

public function resolveUserByProviderCredentials(string $provider, string $accessToken): ?Authenticatable
    {
        $providerUser = null;
        try {
            if ($provider == 'twitter') {
                $accessTokenSecret = request('access_token_secret');
                $providerUser = Socialite::driver($provider)->userFromTokenAndSecret($accessToken, $accessTokenSecret);
            } else {
                $providerUser = Socialite::driver($provider)->userFromToken($accessToken);
            }
        } catch (Exception $exception) {
        }

Test OK. Thanks!

ankurk91 commented 4 years ago

Closing, since this can be achieved without the need of any modification in package.