You are here

public function OAuth2ServerRestfulAuthentication::authenticate in OAuth2 Server 7

Authenticate the request by trying to match a user.

Parameters

array $request: The request.

string $method: The HTTP method. Defaults to "get".

Return value

\stdClass|null The user object.

Overrides RestfulAuthenticationInterface::authenticate

File

plugins/authentication/OAuth2ServerRestfulAuthentication.class.php, line 16
Contains RestfulOAuth2Authentication and OAuth2ServerRestfulException.

Class

OAuth2ServerRestfulAuthentication
A simple OAuth2 authentication type.

Code

public function authenticate(array $request = array(), $method = \RestfulInterface::GET) {
  if (!($server = variable_get('oauth2_server_restful_server'))) {
    return NULL;
  }
  $result = oauth2_server_check_access($server, variable_get('oauth2_server_restful_scope'));
  if ($result instanceof OAuth2\Response) {
    throw new \OAuth2ServerRestfulException($result);
  }
  elseif (is_array($result) && !empty($result['user_id'])) {
    return user_load($result['user_id']);
  }
  return NULL;
}