You are here

function oauth2_client_test_client_integration in OAuth2 Client 7.2

Same name and namespace in other branches
  1. 7 tests/oauth2_client_test.module \oauth2_client_test_client_integration()

Use the client 'client2' for getting an authorization code. This is done with the help of the module oauth2_client, because 'client2' is registered for it (its return_uri belongs to oauth2_client). Before jumping to $authentication_uri, register an internal redirect with oauth2_client.

Try it by opening in browser:

  • $base_url/oauth2/test-client-integration
1 string reference to 'oauth2_client_test_client_integration'
oauth2_client_test_menu in tests/oauth2_client_test.module
Implements hook_menu().

File

tests/oauth2_client_test.module, line 196
Testing OAuth2 client functionality.

Code

function oauth2_client_test_client_integration() {
  $state = drupal_get_token('test_client');
  oauth2_client_set_redirect($state, array(
    'uri' => 'oauth2/test-authorized',
    'params' => array(
      'extra_param' => 'This will be appended to the request on redirect.',
    ),
  ));
  $query_params = array(
    'response_type' => 'code',
    'client_id' => 'client2',
    'redirect_uri' => oauth2_client_get_redirect_uri(),
    'state' => $state,
  );
  $endpoint = url('oauth2/authorize', array(
    'absolute' => TRUE,
  ));
  $authentication_uri = $endpoint . '?' . http_build_query($query_params);
  drupal_goto($authentication_uri);
}