You are here

class OAuth2ServerRestfulAuthentication in OAuth2 Server 7

A simple OAuth2 authentication type.

Hierarchy

Expanded class hierarchy of OAuth2ServerRestfulAuthentication

1 string reference to 'OAuth2ServerRestfulAuthentication'
oauth2.inc in plugins/authentication/oauth2.inc

File

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

View source
class OAuth2ServerRestfulAuthentication extends \RestfulAuthenticationBase {

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  public function applies(array $request = array(), $method = \RestfulInterface::GET) {

    // Don't attempt to authenticate during a Drush call, for example registry
    // rebuild.
    // @todo perhaps this should be a patch upstream (for the restful module)
    if (drupal_is_cli()) {
      return FALSE;
    }
    return parent::applies($request, $method);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OAuth2ServerRestfulAuthentication::applies public function 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. Overrides RestfulAuthenticationBase::applies
OAuth2ServerRestfulAuthentication::authenticate public function Authenticate the request by trying to match a user. Overrides RestfulAuthenticationInterface::authenticate
RestfulAuthenticationBase::$settings protected property Settings from the plugin definition.
RestfulAuthenticationBase::getName public function Get the name of the authentication plugin. Overrides RestfulAuthenticationInterface::getName
RestfulAuthenticationBase::__construct public function Constructor. Overrides RestfulPluginBase::__construct
RestfulPluginBase::$plugin protected property The plugin definition array.
RestfulPluginBase::getPlugin public function Gets information about the restful plugin. Overrides RestfulPluginInterface::getPlugin
RestfulPluginBase::getPluginKey public function Gets information about the restful plugin key. Overrides RestfulPluginInterface::getPluginKey
RestfulPluginBase::setPlugin public function Sets information about the restful plugin. Overrides RestfulPluginInterface::setPlugin
RestfulPluginBase::setPluginKey public function Gets information about the restful plugin key. Overrides RestfulPluginInterface::setPluginKey