jwsBuilder = $jwsBuilder; $this->jwsSerializer = $jwsSerializer ?? new CompactSerializer(); } #[Override] public function getSupportedMethod(): string { return 'client_secret_jwt'; } private function getJwsBuilder(): JWSBuilder { if (null !== $this->jwsBuilder) { return $this->jwsBuilder; } if (! class_exists(HS256::class)) { throw new LogicException('To use the client_secret_jwt auth method you should install web-token/jwt-signature-algorithm-hmac package'); } return $this->jwsBuilder = new JWSBuilder(new AlgorithmManager([new HS256()])); } #[Override] protected function createAuthJwt(OpenIDClient $client, array $claims = []): string { $clientSecret = $client->getMetadata()->getClientSecret(); if (null === $clientSecret) { throw new InvalidArgumentException($this->getSupportedMethod() . ' cannot be used without client_secret metadata'); } $clientId = $client->getMetadata()->getClientId(); $jwk = jose_secret_key($clientSecret); $time = time(); $jti = base64url_encode(random_bytes(32)); $payload = json_encode($claims + [ 'iss' => $clientId, 'sub' => $clientId, 'aud' => get_endpoint_uri($client, 'token_endpoint'), 'iat' => $time, 'exp' => $time + 60, 'jti' => $jti, ], JSON_THROW_ON_ERROR); $jws = $this->getJwsBuilder()->create() ->withPayload($payload) ->addSignature($jwk, ['alg' => 'HS256', 'jti' => $jti]) ->build(); return $this->jwsSerializer->serialize($jws, 0); } }