You are here

function oauth2_server_client_form_validate in OAuth2 Server 7

Validation callback.

File

includes/oauth2_server.client_admin.inc, line 295
Admin UI for clients.

Code

function oauth2_server_client_form_validate($form, &$form_state) {
  entity_form_field_validate('oauth2_server_client', $form, $form_state);

  // The client key must be unique across servers.
  $client = $form_state['build_info']['args'][0];
  $client_key = $form_state['values']['client_key'];
  if (empty($client->client_id) || $client->client_key != $client_key) {
    if ($client = oauth2_server_client_load($client_key)) {
      form_set_error('client_key', t('The chosen Client ID is already in use.'));
    }
  }
  $form_state['client_secret'] = '';
  if (!empty($form_state['values']['require_client_secret'])) {
    if (!empty($form_state['values']['client_secret'])) {
      $form_state['client_secret'] = oauth2_server_hash_client_secret($form_state['values']['client_secret']);
      if (!$form_state['client_secret']) {
        throw new \Exception("Failed to hash client secret");
      }
    }
    elseif (!empty($client->client_secret)) {
      $form_state['client_secret'] = $client->client_secret;
    }
    else {
      form_set_error('client_secret', t('A client secret is required.'));
    }
  }
}