You are here

protected function OAuth2ServerAuthentication::getOAuth2Info in RESTful 7.2

Get OAuth2 information from the request.

Parameters

\Drupal\restful\Http\RequestInterface $request: The request.

Return value

array|null Simple associative array with the following keys:

  • server: The OAuth2 server to authenticate against.
  • scope: The scope required for the resource.
2 calls to OAuth2ServerAuthentication::getOAuth2Info()
OAuth2ServerAuthentication::applies in src/Plugin/authentication/OAuth2ServerAuthentication.php
Determines if the request can be checked for authentication. For example, when authenticating with HTTP header, return FALSE if the header values do not exist.
OAuth2ServerAuthentication::authenticate in src/Plugin/authentication/OAuth2ServerAuthentication.php
Authenticate the request by trying to match a user.

File

src/Plugin/authentication/OAuth2ServerAuthentication.php, line 71

Class

OAuth2ServerAuthentication
Authentication support for oauth2_server.

Namespace

Drupal\restful\Plugin\authentication

Code

protected function getOAuth2Info(RequestInterface $request) {
  $plugin_id = $this
    ->getResourcePluginIdFromRequest();
  if (!$plugin_id) {

    // If the plugin can't be determined, it is probably not a request to the
    // resource but something else that is just loading all the plugins.
    return NULL;
  }
  $plugin_definition = ResourcePluginManager::create('cache', $request)
    ->getDefinition($plugin_id);
  if (empty($plugin_definition['oauth2Server'])) {
    return NULL;
  }
  $server = $plugin_definition['oauth2Server'];
  $scope = !empty($plugin_definition['oauth2Scope']) ? $plugin_definition['oauth2Scope'] : '';
  return [
    'server' => $server,
    'scope' => $scope,
  ];
}