Closed steve228uk closed 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.
<?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!
Closing, since this can be achieved without the need of any modification in package.
Fixes #7 by adding an optional
access_token_secret
parameter to requests.