You are here

public function Oauth2Token::token in Simple OAuth (OAuth2) & OpenID Connect 8.3

Same name and namespace in other branches
  1. 8.4 src/Controller/Oauth2Token.php \Drupal\simple_oauth\Controller\Oauth2Token::token()
  2. 8.2 src/Controller/Oauth2Token.php \Drupal\simple_oauth\Controller\Oauth2Token::token()
  3. 5.x src/Controller/Oauth2Token.php \Drupal\simple_oauth\Controller\Oauth2Token::token()

Processes POST requests to /oauth/token.

1 string reference to 'Oauth2Token::token'
simple_oauth.routing.yml in ./simple_oauth.routing.yml
simple_oauth.routing.yml

File

src/Controller/Oauth2Token.php, line 41

Class

Oauth2Token

Namespace

Drupal\simple_oauth\Controller

Code

public function token(ServerRequestInterface $request) {

  // Extract the grant type from the request body.
  $body = $request
    ->getParsedBody();
  $grant_type_id = !empty($body['grant_type']) ? $body['grant_type'] : 'implicit';

  // Get the auth server object from that uses the League library.
  try {

    // Respond to the incoming request and fill in the response.
    $auth_server = $this->grantManager
      ->getAuthorizationServer($grant_type_id);
    $response = $this
      ->handleToken($request, $auth_server);
  } catch (OAuthServerException $exception) {
    watchdog_exception('simple_oauth', $exception);
    $response = $exception
      ->generateHttpResponse(new Response());
  }
  return $response;
}