|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the HWIOAuthBundle package. |
| 5 | + * |
| 6 | + * (c) Hardware Info <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace HWI\Bundle\OAuthBundle\OAuth\ResourceOwner; |
| 13 | + |
| 14 | +use Symfony\Component\OptionsResolver\Options; |
| 15 | +use Symfony\Component\OptionsResolver\OptionsResolver; |
| 16 | +use Symfony\Component\Security\Core\Exception\AuthenticationException; |
| 17 | + |
| 18 | +final class PassageResourceOwner extends GenericOAuth2ResourceOwner |
| 19 | +{ |
| 20 | + public const TYPE = 'passage'; |
| 21 | + |
| 22 | + /** |
| 23 | + * {@inheritdoc} |
| 24 | + */ |
| 25 | + protected array $paths = [ |
| 26 | + 'identifier' => 'sub', |
| 27 | + 'email' => 'email', |
| 28 | + 'phone_number' => 'phone_number', |
| 29 | + 'email_verified' => 'email_verified', |
| 30 | + 'phone_number_verified' => 'phone_number_verified', |
| 31 | + ]; |
| 32 | + |
| 33 | + /** |
| 34 | + * {@inheritdoc} |
| 35 | + */ |
| 36 | + public function revokeToken($token) |
| 37 | + { |
| 38 | + if (!isset($this->options['revoke_token_url'])) { |
| 39 | + throw new AuthenticationException('OAuth error: "Method unsupported."'); |
| 40 | + } |
| 41 | + |
| 42 | + $parameters = [ |
| 43 | + 'client_id' => $this->options['client_id'], |
| 44 | + 'client_secret' => $this->options['client_secret'], |
| 45 | + 'token' => $token, |
| 46 | + ]; |
| 47 | + |
| 48 | + $response = $this->httpRequest($this->normalizeUrl($this->options['revoke_token_url']), $parameters, [], 'POST'); |
| 49 | + |
| 50 | + return 200 === $response->getStatusCode(); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * {@inheritdoc} |
| 55 | + */ |
| 56 | + protected function configureOptions(OptionsResolver $resolver) |
| 57 | + { |
| 58 | + parent::configureOptions($resolver); |
| 59 | + |
| 60 | + $resolver->setDefaults([ |
| 61 | + 'authorization_url' => 'https://{sub_domain}.withpassage.com/authorize', |
| 62 | + 'access_token_url' => 'https://{sub_domain}.withpassage.com/token', |
| 63 | + 'revoke_token_url' => 'https://{sub_domain}.withpassage.com/revoke', |
| 64 | + 'infos_url' => 'https://{sub_domain}.withpassage.com/userinfo', |
| 65 | + |
| 66 | + 'use_commas_in_scope' => false, |
| 67 | + 'scope' => 'openid email', |
| 68 | + ]); |
| 69 | + |
| 70 | + $resolver->setRequired([ |
| 71 | + 'sub_domain', |
| 72 | + ]); |
| 73 | + |
| 74 | + $normalizer = function (Options $options, $value) { |
| 75 | + return str_replace('{sub_domain}', $options['sub_domain'], $value); |
| 76 | + }; |
| 77 | + |
| 78 | + $resolver |
| 79 | + ->setNormalizer('authorization_url', $normalizer) |
| 80 | + ->setNormalizer('access_token_url', $normalizer) |
| 81 | + ->setNormalizer('revoke_token_url', $normalizer) |
| 82 | + ->setNormalizer('infos_url', $normalizer) |
| 83 | + ; |
| 84 | + } |
| 85 | +} |
0 commit comments