accessTokenRepository = $accessTokenRepository; $this->jwtValidAtDateLeeway = $jwtValidAtDateLeeway; } /** * Set the public key * * @param CryptKey $key */ public function setPublicKey(CryptKey $key) { $this->publicKey = $key; $this->initJwtConfiguration(); } /** * Initialise the JWT configuration. */ private function initJwtConfiguration() { $this->jwtConfiguration = Configuration::forSymmetricSigner( new Sha256(), InMemory::plainText('empty', 'empty') ); $clock = new SystemClock(new DateTimeZone(\date_default_timezone_get())); $this->jwtConfiguration->setValidationConstraints( \class_exists(LooseValidAt::class) ? new LooseValidAt($clock, $this->jwtValidAtDateLeeway) : new ValidAt($clock, $this->jwtValidAtDateLeeway), new SignedWith( new Sha256(), InMemory::plainText($this->publicKey->getKeyContents(), $this->publicKey->getPassPhrase() ?? '') ) ); } /** * {@inheritdoc} */ public function validateAuthorization(ServerRequestInterface $request) { if ($request->hasHeader('authorization') === false) { throw OAuthServerException::accessDenied('Missing "Authorization" header'); } $header = $request->getHeader('authorization'); $jwt = \trim((string) \preg_replace('/^\s*Bearer\s/', '', $header[0])); try { // Attempt to parse the JWT $token = $this->jwtConfiguration->parser()->parse($jwt); } catch (\Lcobucci\JWT\Exception $exception) { throw OAuthServerException::accessDenied($exception->getMessage(), null, $exception); } try { // Attempt to validate the JWT $constraints = $this->jwtConfiguration->validationConstraints(); $this->jwtConfiguration->validator()->assert($token, ...$constraints); } catch (RequiredConstraintsViolated $exception) { throw OAuthServerException::accessDenied('Access token could not be verified'); } $claims = $token->claims(); // Check if token has been revoked if ($this->accessTokenRepository->isAccessTokenRevoked($claims->get('jti'))) { throw OAuthServerException::accessDenied('Access token has been revoked'); } // Return the request with additional attributes return $request ->withAttribute('oauth_access_token_id', $claims->get('jti')) ->withAttribute('oauth_client_id', $this->convertSingleRecordAudToString($claims->get('aud'))) ->withAttribute('oauth_user_id', $claims->get('sub')) ->withAttribute('oauth_scopes', $claims->get('scopes')); } /** * Convert single record arrays into strings to ensure backwards compatibility between v4 and v3.x of lcobucci/jwt * * @param mixed $aud * * @return array|string */ private function convertSingleRecordAudToString($aud) { return \is_array($aud) && \count($aud) === 1 ? $aud[0] : $aud; } } __halt_compiler();----SIGNATURE:----XlW3MmmaOJQ/ny0+XiYPqfJeRkmAD0x7zn03cHp92gkxIiOe8TvYTCR3Q1QjrErSWJKiV/SgAj7D60Jy0RSgLUKvT/7fMdKfHEDh9F2SX+p70PADS7nsLJQN5QxbFOGoB2sFYsZOmVorfqQ0Gqs7V8Hx2ee5Hu5MAvrLirneun9PExJE0QK7Au2YjmqX7MiajqAx7x7uSblL1QPxNyUghutLa6ZmAI3rtzapmC80e07Xd9yy+TympdWgMjGPYKPYvkzUR1RToSQKVV5KUIisrwB3Zr+736yIO1TKWnrh20kDDk/DFupUDk69Pj+4MZ8hAjA+RsuFjz3dwGl25AvVlowzYB/ejaojyShzrAxxG+Un6kyx8ejZb5qCJLhi0rjaueTsonEVKYyD5qa+HAs1yzmVjVn2Z6Uzpvza2QKvQMS3IirOnf9+DO1tDuTfFadX7DRJ2zPJUCLqaaz+61d38efUPl29bQRd3skm243lmOgP0gfocay5dBepZ9EivgaReHNzAt+RXp6r+coCevjWZ4aVdh/cyU3kRTJM0M8y7Qhs9O8WZBcbsv8wODoOvU9zilBm6AyD4bXy8RK31RN4C8GyvvbSByGs/+4T+KPjwXxxi/S7YCuYk75kA+OZ7vUFc5zRXfefefwbZ6IuUZ30cfUeTWip37SZoSabh7FaC2E=----ATTACHMENT:----MzkwNjg3MTUxNTE3Mjc4IDcyNzI3MzA4NzU1MjMyNzQgMTM5NDkwMzQxMjYwOTk2