You are here

public function OAuth2Controller::tokens in OAuth2 Server 8

Same name and namespace in other branches
  1. 2.0.x src/Controller/OAuth2Controller.php \Drupal\oauth2_server\Controller\OAuth2Controller::tokens()

Tokens.

Parameters

\Drupal\Core\Routing\RouteMatchInterface $route_match: The route match object.

\Symfony\Component\HttpFoundation\Request $request: The request object.

Return value

\OAuth2\HttpFoundationBridge\Response|\Symfony\Component\HttpFoundation\JsonResponse The response object.

1 string reference to 'OAuth2Controller::tokens'
oauth2_server.routing.yml in ./oauth2_server.routing.yml
oauth2_server.routing.yml

File

src/Controller/OAuth2Controller.php, line 201

Class

OAuth2Controller
Class OAuth2 Controller.

Namespace

Drupal\oauth2_server\Controller

Code

public function tokens(RouteMatchInterface $route_match, Request $request) {
  $token = $route_match
    ->getRawParameter('oauth2_server_token');
  $token = $this->storage
    ->getAccessToken($token);

  // No token found. Stop here.
  if (!$token || $token['expires'] <= time()) {
    return new BridgeResponse([], 404);
  }

  // Return the token, without the server and client_id keys.
  unset($token['server']);
  return new JsonResponse($token);
}