You are here

function farm_api_enable_oauth_client in farmOS 7

Helper function for enabling a farmOS OAuth2 Client.

Parameters

string $label: The human-readable label for the client.

string $client_key: The machine name of the client to enable.

string $client_secret: Optional client secret.

string $redirect_uri: Optional redirect URIs (separated by newlines).

array $settings: Optional array of client settings to override server-level defaults.

3 calls to farm_api_enable_oauth_client()
farm_api_modules_enabled in modules/farm/farm_api/farm_api.module
Implements hook_modules_enabled().
farm_api_oauth_settings_form_submit in modules/farm/farm_api/farm_api.oauth.inc
Form submit handler for farm_api_oauth_settings_form
farm_api_update_7002 in modules/farm/farm_api/farm_api.install
Enable default farmOS OAuth client.

File

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

Code

function farm_api_enable_oauth_client($label, $client_key, $client_secret = '', $redirect_uri = '', $settings = array()) {
  $server_name = variable_get('restws_oauth2_server_name', 'farmos_oauth');

  // Create OAuth2 Server Client Entity
  $new_client = entity_create('oauth2_server_client', array());
  $new_client->server = $server_name;
  $new_client->client_key = $client_key;
  $new_client->label = $label;

  // Add an optional client secret.
  if (!empty($client_secret)) {
    $new_client->client_secret = $client_secret;
  }

  // Add optional OAuth Client settings used to override OAuth2
  // server-level settings. Do not set this value as an empty array.
  if (!empty($settings)) {
    $new_client->settings = $settings;
  }

  // The module supports entering multiple redirect uris separated by a
  // newline. Both a dummy and the real uri are specified to confirm that
  // validation passes.
  $new_client->redirect_uri = $redirect_uri;
  $new_client->automatic_authorization = FALSE;
  $new_client
    ->save();
}