Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| SocialUserResolver | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 1 |
| resolveUserByProviderCredentials | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Resolvers; |
| 4 | |
| 5 | use App\Http\Services\SocialAccountService; |
| 6 | use Coderello\SocialGrant\Resolvers\SocialUserResolverInterface; |
| 7 | use Exception; |
| 8 | use Illuminate\Contracts\Auth\Authenticatable; |
| 9 | use Illuminate\Support\Facades\Log; |
| 10 | use Laravel\Socialite\Facades\Socialite; |
| 11 | use Google\Client; |
| 12 | |
| 13 | class SocialUserResolver implements SocialUserResolverInterface |
| 14 | { |
| 15 | public function resolveUserByProviderCredentials(string $provider, string $accessToken): ?Authenticatable |
| 16 | { |
| 17 | $providerUser = null; |
| 18 | |
| 19 | try { |
| 20 | if ('google' === $provider) { |
| 21 | $googleClient = new Client(['client_id' => config('services.google.client_id')]); |
| 22 | $providerUser = $googleClient->verifyIdToken($accessToken); |
| 23 | } else { |
| 24 | $providerUser = Socialite::driver($provider)->stateless()->userFromToken($accessToken); |
| 25 | } |
| 26 | } catch (Exception $exception) { |
| 27 | Log::error($exception->getMessage()); |
| 28 | } |
| 29 | |
| 30 | if ($providerUser) { |
| 31 | return (new SocialAccountService())->findOrCreate($providerUser, $provider); |
| 32 | } |
| 33 | |
| 34 | return null; |
| 35 | } |
| 36 | } |