You are here

function hook_oauth2_server_default_scope in OAuth2 Server 7

Same name and namespace in other branches
  1. 8 oauth2_server.api.php \hook_oauth2_server_default_scope()
  2. 2.0.x oauth2_server.api.php \hook_oauth2_server_default_scope()

Returns the default scope for the provided server.

Invoked by OAuth2_Scope_Drupal. If no hook implementation returns a default scope for the current server, then the one from $server->settings['default_scope'] is used.

This hook runs on "authorize" and "token" requests and has access to the client_id in $_GET (for "authorize") or via oauth2_server_get_client_credentials() (for "token"). Note that client_id in this case corresponds to $client->client_key.

Parameters

OAuth2Server $server: The server entity.

Return value

string[] An array of default scopes (their machine names).

1 function implements hook_oauth2_server_default_scope()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

oauth2_server_test_oauth2_server_default_scope in tests/oauth2_server_test.module
Implements oauth2_server_default_scope().
1 invocation of hook_oauth2_server_default_scope()
Scope::getDefaultScope in lib/Drupal/oauth2_server/Scope.php

File

./oauth2_server.api.php, line 137
Hooks provided by the OAuth2 Server module.

Code

function hook_oauth2_server_default_scope(OAuth2Server $server) {

  // For the "test" server, grant the user any scope he has access to.
  $default_scopes = array();
  if ($server->name == 'test') {
    $query = new EntityFieldQuery();
    $query
      ->entityCondition('entity_type', 'oauth2_server_scope');
    $query
      ->propertyCondition('server', $server->name);
    $query
      ->addTag('oauth2_server_scope_access');
    $query
      ->addMetaData('oauth2_server', $server);
    $results = $query
      ->execute();
    if ($results) {
      $scope_ids = array_keys($results['oauth2_server_scope']);
      $scopes = entity_load('oauth2_server_scope', $scope_ids);
      foreach ($scopes as $scope) {
        $default_scopes[] = $scope->name;
      }
    }
  }
  return $default_scopes;
}