You are here

function oauth_common_form_authorization in OAuth 1.0 7.3

Same name and namespace in other branches
  1. 6.3 oauth_common.authorizations.inc \oauth_common_form_authorization()
  2. 7.4 oauth_common.authorizations.inc \oauth_common_form_authorization()

Provide a form to edit and add authorizations.

Despite what appears above, this function is actually invoked by `drupal_retrieve_form` (by way of `drupal_build_form`, by way of `drupal_get_form`), so the second argument isn't the token, but a reference to the form state. Luckily, PHP made that incredibly non-obvious by neglecting to notify me that this function was being called with one too few arguments. Go team.

2 string references to 'oauth_common_form_authorization'
oauth_common_authorization_add in ./oauth_common.authorizations.inc
Page callback to authorize a consumer.
oauth_common_providerui_menu in ./oauth_common_providerui.module
Implements hook_menu().

File

./oauth_common.authorizations.inc, line 99
Functions related to a user's authorization section

Code

function oauth_common_form_authorization($form_id, &$form_state, $token) {
  $form = array();
  $consumer = $token->consumer;
  $context = oauth_common_context_load($consumer->context);
  drupal_set_title(t('Authorization for @app', array(
    '@app' => $consumer->name,
  )), PASS_THROUGH);
  $form['token_object'] = array(
    '#type' => 'value',
    '#value' => $token,
  );
  $form['authorized'] = array(
    '#type' => 'checkbox',
    '#title' => t('Authorized'),
    '#default_value' => $token->authorized,
  );
  $form['created'] = array(
    '#type' => 'item',
    '#title' => t('Created'),
    '#markup' => format_date($token->created),
  );
  $form['changed'] = array(
    '#type' => 'item',
    '#title' => t('Changed'),
    '#markup' => format_date($token->changed),
  );
  $form['key'] = array(
    '#type' => 'item',
    '#title' => t('Key'),
    '#markup' => $token->key,
  );
  if ($token->in_database) {
    $form['secret'] = array(
      '#type' => 'item',
      '#prefix' => '<div id="token-secret-wrapper">',
      '#title' => t('Secret'),
      '#markup' => substr($token->secret, 0, 6) . '...',
    );
    $form['show_secret'] = array(
      '#type' => 'button',
      '#value' => t('Show secret'),
      '#ajax' => array(
        'callback' => 'oauth_common_form_authorization_secret_ajax_callback',
        'wrapper' => 'token-secret-wrapper',
      ),
      '#suffix' => '</div>',
    );
  }
  else {
    $form['secret'] = array(
      '#type' => 'item',
      '#title' => t('Secret'),
      '#markup' => $token->secret,
    );
  }
  $form['allowed'] = array(
    '#type' => 'fieldset',
    '#title' => t('Permissions'),
  );
  global $user;
  oauth_common_permissions_form($user, $form['allowed'], $consumer, $context, $token->services);
  $form['actions'] = array(
    '#type' => 'actions',
  );
  $form['actions']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save'),
  );
  return $form;
}