Lines
0.00%
0 / 6
Functions and Methods
0.00%
0 / 2
Classes and Traits
0.00%
0 / 1
| Name | Lines | Functions and Methods | CRAP | Classes and Traits | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| GoogleIdTokenVerifier | 0.00% | 0 / 6 | 0.00% | 0 / 2 | 20 | 0.00% | 0 / 1 | |||
| __construct | 0.00% | 0 / 1 | 0.00% | 0 / 1 | 2 | |||||
| verify | 0.00% | 0 / 5 | 0.00% | 0 / 1 | 12 | |||||
| 1 | <?php | |
| 2 | ||
| 3 | declare(strict_types=1); | |
| 4 | ||
| 5 | namespace App\Security; | |
| 6 | ||
| 7 | use Google\Client; | |
| 8 | use Symfony\Component\DependencyInjection\Attribute\AsAlias; | |
| 9 | use Symfony\Component\DependencyInjection\Attribute\Autowire; | |
| 10 | ||
| 11 | #[AsAlias(GoogleIdTokenVerifierInterface::class)] | |
| 12 | final readonly class GoogleIdTokenVerifier implements GoogleIdTokenVerifierInterface | |
| 13 | { | |
| 14 | public function __construct( | |
| 15 | #[Autowire(env: 'OAUTH_GOOGLE_ID')] private string $oauthGoogleId, | |
| 16 | ) { | |
| 17 | } | |
| 18 | ||
| 19 | #[\Override] | |
| 20 | public function verify(string $idToken): ?array | |
| 21 | { | |
| 22 | try { | |
| 23 | $payload = new Client(['client_id' => $this->oauthGoogleId]) | |
| 24 | ->verifyIdToken($idToken); | |
| 25 | } catch (\UnexpectedValueException|\LogicException) { | |
| 26 | return null; | |
| 27 | } | |
| 28 | ||
| 29 | return \is_array($payload) ? $payload : null; | |
| 30 | } | |
| 31 | } |