diff --git a/src/TokenTypes/JsonWebTokenType.php b/src/TokenTypes/JsonWebTokenType.php new file mode 100644 index 00000000..7ea5051a --- /dev/null +++ b/src/TokenTypes/JsonWebTokenType.php @@ -0,0 +1,125 @@ + $this->accessToken->getIdentifier(), + 'token_type' => 'Bearer', + 'expires_in' => $this->accessToken->getExpiryDateTime()->getTimestamp() - (new \DateTime())->getTimestamp() + ]; + + if (!is_null($this->getParam('refresh_token'))) { + $return['refresh_token'] = $this->getParam('refresh_token'); + } + + $return['id_token'] = $this->generateJWT(); + + return $return; + } + + /** + * Generate an JWT + * @return string + */ + public function generateJWT() + { + $now = new \DateTime(); + + $token = [ + 'iss' => self::$issuer, + 'aud' => self::$audience, + 'sub' => $this->accessToken->getOwnerIdentifier(), + 'exp' => $this->accessToken->getExpiryDateTime()->getTimestamp(), + 'nbf' => $now->getTimestamp(), + 'iat' => $now->getTimestamp(), + 'jti' => SecureKey::generate() + ]; + + return JWT::encode($token, self::$encryptionKey); + } + + /** + * @return \Symfony\Component\HttpFoundation\Response + */ + public function generateHttpResponse() + { + return new Response( + json_encode([ + $this->generateResponse() + ]), + 200, + [ + 'Content-type' => 'application/json', + 'Cache-Control' => 'no-store', + 'Pragma' => 'no-cache' + ] + ); + } + + /** + * Determine the access token in the authorization header + * + * @param \Symfony\Component\HttpFoundation\Request $request + * + * @return string + */ + public function determineAccessTokenInHeader(Request $request) + { + // TODO: Implement determineAccessTokenInHeader() method. + } +}