From 9d9c74b9ef84c2c98c1d8651192f559576f6ad21 Mon Sep 17 00:00:00 2001 From: Evan Sims Date: Mon, 17 Jul 2023 23:01:34 -0500 Subject: [PATCH] Update Validator.php --- src/Token/Validator.php | 53 +++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/Token/Validator.php b/src/Token/Validator.php index 4ebff333..89d56ad2 100644 --- a/src/Token/Validator.php +++ b/src/Token/Validator.php @@ -5,6 +5,7 @@ namespace Auth0\SDK\Token; use Auth0\SDK\Contract\Token\ValidatorInterface; +use Auth0\SDK\Exception\InvalidTokenException; use function in_array; use function is_array; @@ -27,7 +28,7 @@ public function __construct( * * @param array $expects An array of allowed values for the 'aud' claim. Successful if ANY match. * - * @throws \Auth0\SDK\Exception\InvalidTokenException when claim validation fails + * @throws InvalidTokenException when claim validation fails */ public function audience( array $expects, @@ -35,7 +36,7 @@ public function audience( $audience = $this->getClaim('aud'); if (null === $audience) { - throw \Auth0\SDK\Exception\InvalidTokenException::missingAudienceClaim(); + throw InvalidTokenException::missingAudienceClaim(); } if (! is_array($audience)) { @@ -46,7 +47,7 @@ public function audience( return $this; } - throw \Auth0\SDK\Exception\InvalidTokenException::mismatchedAudClaim(implode(', ', $expects), implode(', ', $audience)); + throw InvalidTokenException::mismatchedAudClaim(implode(', ', $expects), implode(', ', $audience)); } /** @@ -54,7 +55,7 @@ public function audience( * * @param array $expects An array of allowed values for the 'azp' claim. Successful if ANY match. * - * @throws \Auth0\SDK\Exception\InvalidTokenException when claim validation fails + * @throws InvalidTokenException when claim validation fails */ public function authorizedParty( array $expects, @@ -62,18 +63,18 @@ public function authorizedParty( $audience = $this->getClaim('aud'); if (null === $audience) { - throw \Auth0\SDK\Exception\InvalidTokenException::missingAudienceClaim(); + throw InvalidTokenException::missingAudienceClaim(); } if (is_array($audience)) { $azp = $this->getClaim('azp'); if (null === $azp || ! is_string($azp)) { - throw \Auth0\SDK\Exception\InvalidTokenException::missingAzpClaim(); + throw InvalidTokenException::missingAzpClaim(); } if (! in_array($azp, $expects, true)) { - throw \Auth0\SDK\Exception\InvalidTokenException::mismatchedAzpClaim(implode(', ', $expects), $azp); + throw InvalidTokenException::mismatchedAzpClaim(implode(', ', $expects), $azp); } } @@ -87,7 +88,7 @@ public function authorizedParty( * @param int $leeway leeway in seconds to allow during time calculations * @param null|int $now Optional. Unix timestamp representing the current point in time to use for time calculations. * - * @throws \Auth0\SDK\Exception\InvalidTokenException when claim validation fails + * @throws InvalidTokenException when claim validation fails */ public function authTime( int $maxAge, @@ -98,13 +99,13 @@ public function authTime( $now ??= time(); if (null === $authTime || ! is_numeric($authTime)) { - throw \Auth0\SDK\Exception\InvalidTokenException::missingAuthTimeClaim(); + throw InvalidTokenException::missingAuthTimeClaim(); } $validUntil = (int) $authTime + $maxAge + $leeway; if ($now > $validUntil) { - throw \Auth0\SDK\Exception\InvalidTokenException::mismatchedAuthTimeClaim($now, $validUntil); + throw InvalidTokenException::mismatchedAuthTimeClaim($now, $validUntil); } return $this; @@ -116,7 +117,7 @@ public function authTime( * @param int $leeway leeway in seconds to allow during time calculations * @param null|int $now Optional. Unix timestamp representing the current point in time to use for time calculations. * - * @throws \Auth0\SDK\Exception\InvalidTokenException when claim validation fails + * @throws InvalidTokenException when claim validation fails */ public function expiration( int $leeway = 60, @@ -126,13 +127,13 @@ public function expiration( $now ??= time(); if (null === $expires || ! is_numeric($expires)) { - throw \Auth0\SDK\Exception\InvalidTokenException::missingExpClaim(); + throw InvalidTokenException::missingExpClaim(); } $expires = (int) $expires + $leeway; if ($now > $expires) { - throw \Auth0\SDK\Exception\InvalidTokenException::mismatchedExpClaim($now, $expires); + throw InvalidTokenException::mismatchedExpClaim($now, $expires); } return $this; @@ -141,14 +142,14 @@ public function expiration( /** * Validate the 'iat' claim is present. * - * @throws \Auth0\SDK\Exception\InvalidTokenException when claim validation fails + * @throws InvalidTokenException when claim validation fails */ public function issued(): self { $issued = $this->getClaim('iat'); if (null === $issued) { - throw \Auth0\SDK\Exception\InvalidTokenException::missingIatClaim(); + throw InvalidTokenException::missingIatClaim(); } return $this; @@ -159,7 +160,7 @@ public function issued(): self * * @param string $expects the value to compare with the claim * - * @throws \Auth0\SDK\Exception\InvalidTokenException when claim validation fails + * @throws InvalidTokenException when claim validation fails */ public function issuer( string $expects, @@ -167,11 +168,11 @@ public function issuer( $claim = $this->getClaim('iss'); if (null === $claim || ! is_string($claim)) { - throw \Auth0\SDK\Exception\InvalidTokenException::missingIssClaim(); + throw InvalidTokenException::missingIssClaim(); } if ($claim !== $expects) { - throw \Auth0\SDK\Exception\InvalidTokenException::mismatchedIssClaim($expects, $claim); + throw InvalidTokenException::mismatchedIssClaim($expects, $claim); } return $this; @@ -182,7 +183,7 @@ public function issuer( * * @param string $expects the value to compare with the claim * - * @throws \Auth0\SDK\Exception\InvalidTokenException when claim validation fails + * @throws InvalidTokenException when claim validation fails */ public function nonce( string $expects, @@ -190,11 +191,11 @@ public function nonce( $claim = $this->getClaim('nonce'); if (null === $claim || ! is_string($claim)) { - throw \Auth0\SDK\Exception\InvalidTokenException::missingNonceClaim(); + throw InvalidTokenException::missingNonceClaim(); } if ($claim !== $expects) { - throw \Auth0\SDK\Exception\InvalidTokenException::mismatchedNonceClaim($expects, $claim); + throw InvalidTokenException::mismatchedNonceClaim($expects, $claim); } return $this; @@ -205,7 +206,7 @@ public function nonce( * * @param array $expects An array of allowed values for the 'org_id' claim. Successful if ANY match. * - * @throws \Auth0\SDK\Exception\InvalidTokenException when claim validation fails + * @throws InvalidTokenException when claim validation fails */ public function organization( array $expects, @@ -213,11 +214,11 @@ public function organization( $claim = $this->getClaim('org_id'); if (null === $claim || ! is_string($claim)) { - throw \Auth0\SDK\Exception\InvalidTokenException::missingOrgIdClaim(); + throw InvalidTokenException::missingOrgIdClaim(); } if (! in_array($claim, $expects, true)) { - throw \Auth0\SDK\Exception\InvalidTokenException::mismatchedOrgIdClaim(implode(', ', $expects), $claim); + throw InvalidTokenException::mismatchedOrgIdClaim(implode(', ', $expects), $claim); } return $this; @@ -226,14 +227,14 @@ public function organization( /** * Validate the 'sub' claim is present. * - * @throws \Auth0\SDK\Exception\InvalidTokenException when claim validation fails + * @throws InvalidTokenException when claim validation fails */ public function subject(): self { $claim = $this->getClaim('sub'); if (null === $claim) { - throw \Auth0\SDK\Exception\InvalidTokenException::missingSubClaim(); + throw InvalidTokenException::missingSubClaim(); } return $this;