diff --git a/src/Auth/Auth.php b/src/Auth/Auth.php index d0efbc3..deac17c 100644 --- a/src/Auth/Auth.php +++ b/src/Auth/Auth.php @@ -5,8 +5,9 @@ namespace Ray\Auth0Module\Auth; use Auth0\SDK\Configuration\SdkConfiguration; +use Auth0\SDK\Contract\TokenInterface; use Auth0\SDK\Exception\InvalidTokenException; -use Auth0\SDK\Token\Parser; +use Auth0\SDK\Token; use Ray\Auth0Module\Annotation\Auth0Config; use Ray\Auth0Module\Exception\InvalidToken; @@ -19,22 +20,18 @@ class Auth implements AuthInterface #[Auth0Config('config')] public function __construct(array $config) { - $this->configuration = new SdkConfiguration([ - 'domain' => $config['domain'], - 'clientId' => $config['clientId'], - 'clientSecret' => $config['clientSecret'] ?? null, - 'cookieSecret' => $config['cookieSecret'] ?? null, - ]); + $this->configuration = new SdkConfiguration($config); } - public function verifyToken(string $token): Parser + public function verifyToken(string $token) : TokenInterface { try { - $parser = new parser($this->configuration, $token); - $parser->parse(); - $parser->verify(jwksUri: 'https://' . $this->configuration->getDomain() . '/.well-known/jwks.json'); + $token = new Token($this->configuration, $token); + $token + ->verify() + ->validate(); - return $parser; + return $token; } catch (InvalidTokenException $e) { throw new InvalidToken($e->getMessage()); } diff --git a/src/Auth/AuthInterface.php b/src/Auth/AuthInterface.php index 29126c1..811c2f9 100644 --- a/src/Auth/AuthInterface.php +++ b/src/Auth/AuthInterface.php @@ -4,9 +4,9 @@ namespace Ray\Auth0Module\Auth; -use Auth0\SDK\Token\Parser; +use Auth0\SDK\Contract\TokenInterface; interface AuthInterface { - public function verifyToken(string $token): Parser; + public function verifyToken(string $token) : TokenInterface; } diff --git a/src/Provider/ManagementClientProvider.php b/src/Provider/ManagementClientProvider.php index e695553..184420b 100644 --- a/src/Provider/ManagementClientProvider.php +++ b/src/Provider/ManagementClientProvider.php @@ -24,15 +24,10 @@ class ManagementClientProvider implements ProviderInterface #[Auth0Config('config')] public function __construct(private $config) { - $this->configuration = new SdkConfiguration([ - 'domain' => $config['domain'], - 'clientId' => $config['clientId'], - 'clientSecret' => $config['clientSecret'] ?? null, - 'cookieSecret' => $config['cookieSecret'] ?? null, - ]); + $this->configuration = new SdkConfiguration($config); } - public function get(): Management + public function get() : Management { return new Management($this->configuration); } diff --git a/tests/Auth/AuthTest.php b/tests/Auth/AuthTest.php index e69de29..e8d9ed7 100644 --- a/tests/Auth/AuthTest.php +++ b/tests/Auth/AuthTest.php @@ -0,0 +1,33 @@ + 'test.auth0.com', + 'clientId' => 'test-client-id', + 'clientSecret' => 'test-client-secret', + 'cookieSecret' => 'test-cookie-secret', + 'audience' => ['test-audience'] + ]; + + public function testConstructorWithValidConfig(): void + { + $auth = new Auth($this->validConfig); + $this->assertInstanceOf(Auth::class, $auth); + } + + public function testVerifyTokenWithInvalidToken(): void + { + $auth = new Auth($this->validConfig); + $invalidTokenString = 'invalid.token'; + + $this->expectException(InvalidToken::class); + $auth->verifyToken($invalidTokenString); + } +} diff --git a/tests/Auth0ModuleTest.php b/tests/Auth0ModuleTest.php index f1eb8f8..21db62d 100644 --- a/tests/Auth0ModuleTest.php +++ b/tests/Auth0ModuleTest.php @@ -1,27 +1,20 @@ module = new class extends AbstractModule {