You are here

function _services_oauth_security_settings in Services 6.3

Same name and namespace in other branches
  1. 7.3 auth/services_oauth/services_oauth.inc \_services_oauth_security_settings()
1 string reference to '_services_oauth_security_settings'
services_oauth_services_authentication_info in auth/services_oauth/services_oauth.module
Implementation of hook_services_authentication().

File

auth/services_oauth/services_oauth.inc, line 96
Include file for services_oauth module.

Code

function _services_oauth_security_settings($settings, &$form_state) {
  if (isset($form_state['values']['services_oauth']['oauth_context'])) {
    $settings['oauth_context'] = $form_state['values']['services_oauth']['oauth_context'];
  }
  $form = array();
  $form['oauth_context'] = array(
    '#type' => 'select',
    '#options' => array(
      '' => t('-- Select an OAuth context'),
    ),
    '#default_value' => $settings['oauth_context'],
    '#title' => t('OAuth context'),
    '#description' => t('The OAuth contexts provides a scope for consumers and authorizations and have their own authorization levels. Different services endpoints may share OAuth contexts and thereby allow the use of consumers and tokens across the services endpoint boundraries.'),
  );
  $form['authorization'] = array(
    '#type' => 'select',
    '#options' => array(),
    '#default_value' => $settings['authorization'],
    '#title' => t('Default required OAuth Authorization level'),
    '#description' => t('The default OAuth authorization level that will be required to access resources.'),
  );
  $contexts = oauth_common_context_load_all();
  foreach ($contexts as $context) {
    $form['oauth_context']['#options'][$context->name] = $context->title;
    if (isset($context->authorization_levels) && $context->name == $settings['oauth_context']) {
      foreach ($context->authorization_levels as $name => $level) {
        $form['authorization']['#options'][$name] = t($level['title']) . " ({$context->name})";
      }
    }
  }
  if (empty($form['authorization']['#options'])) {
    $form['authorization'] = array(
      '#type' => 'item',
      '#title' => t('Select an OAuth context enable default required OAuth Authorization level'),
    ) + $form['authorization'];
  }
  else {
    $form['authorization']['#options'] = array(
      '' => t('None'),
    ) + $form['authorization']['#options'];
  }
  $form['credentials'] = array(
    '#type' => 'select',
    '#options' => array(
      'none' => t('None, OAuth authentication will be disabled by default'),
      'unsigned_consumer' => t('Unsigned with consumer key'),
      'consumer' => t('Consumer key, also known as 2-legged OAuth'),
      'token' => t('Consumer key and access token, also known as 3-legged OAuth'),
    ),
    '#default_value' => $settings['credentials'],
    '#title' => t('Default required authentication'),
    '#description' => t('Authorization levels will <em>not</em> be applied if the consumer isn\'t required to supply a access token.'),
  );
  return $form;
}