You are here

function farm_api_check_scope in farmOS 7

Helper function to allow modules to check for an authorized scope in the current request before providing info in an API endpoint.

Parameters

string $scope: A single OAuth Scope to check.

Return value

bool Return TRUE if request is authorized with specified scope. FALSE otherwise.

1 call to farm_api_check_scope()
farm_api_info in modules/farm/farm_api/farm_api.module
Farm info API callback.

File

modules/farm/farm_api/farm_api.module, line 220
Farm API module.

Code

function farm_api_check_scope($scope) {

  // Load the OAuth2 Server name
  $server_name = variable_get('restws_oauth2_server_name', FALSE);
  if (!$server_name) {
    return FALSE;
  }

  // Check OAuth scope.
  $result = oauth2_server_check_access($server_name, $scope);

  // Check if a Token was returned, or an error Response.
  if ($result instanceof \OAuth2\Response) {
    return FALSE;
  }

  // Return True if request is authorized with specified scope.
  return TRUE;
}