You are here

function oauth2_client_test_authorized in OAuth2 Client 7.2

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

The oauth2 server will redirect to the registered redirect_uri, which is handled by the oauth2_client, but then oauth2_client will redirect to the path 'oauth2/test/authorized', which comes here. This is because we registered a redirect on the oauth2_client before jumping to $authentication_uri. While redirecting, oauth2_client will also append to the request the 'extra_param'.

1 string reference to 'oauth2_client_test_authorized'
oauth2_client_test_menu in tests/oauth2_client_test.module
Implements hook_menu().

File

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

Code

function oauth2_client_test_authorized() {
  if (!drupal_valid_token($_GET['state'], 'test_client')) {
    print "The parameter 'state' is wrong.\n";
    return;
  }
  $extra_param = $_GET['extra_param'];
  print "extra_param: {$extra_param} <br/>\n";
  $options = array(
    'method' => 'POST',
    'data' => http_build_query(array(
      'grant_type' => 'authorization_code',
      'code' => $_GET['code'],
      'redirect_uri' => oauth2_client_get_redirect_uri(),
    )),
    'headers' => array(
      'Content-Type' => 'application/x-www-form-urlencoded',
      'Authorization' => 'Basic ' . base64_encode('client2:secret2'),
    ),
    'context' => stream_context_create(array(
      'ssl' => array(
        'verify_peer' => FALSE,
        'verify_peer_name' => FALSE,
      ),
    )),
  );
  $token_endpoint = url('oauth2/token', array(
    'absolute' => TRUE,
  ));
  $result = drupal_http_request($token_endpoint, $options);
  $token = json_decode($result->data);
  print 'access_token: ' . $token->access_token;
}