You are here

function oauth2_client_test_oauth2_clients in OAuth2 Client 7.2

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

Implements hook_oauth2_clients().

File

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

Code

function oauth2_client_test_oauth2_clients() {
  $oauth2_clients = array();
  $common = array(
    'token_endpoint' => url('oauth2/token', array(
      'absolute' => TRUE,
    )),
    'client_id' => 'client1',
    'client_secret' => 'secret1',
  );

  // For testing client-credentials flow.
  $oauth2_clients['client-credentials'] = array(
    'auth_flow' => 'client-credentials',
  ) + $common;

  // For testing user-password flow.
  $oauth2_clients['user-password'] = array(
    'auth_flow' => 'user-password',
    'username' => 'user1',
    'password' => 'pass1',
  ) + $common;

  // For testing server-side flow.
  $oauth2_clients['server-side'] = array(
    'auth_flow' => 'server-side',
    'authorization_endpoint' => url('oauth2/authorize', array(
      'absolute' => TRUE,
    )),
    'redirect_uri' => url('oauth2/authorized', array(
      'absolute' => TRUE,
    )),
    'scope' => 'scope1 scope2',
  ) + $common;

  // For testing server-side flow with automatic authorization client..
  $oauth2_clients['server-side-auto'] = array(
    'token_endpoint' => url('oauth2/token', array(
      'absolute' => TRUE,
    )),
    'client_id' => 'client2',
    'client_secret' => 'secret2',
    'auth_flow' => 'server-side',
    'authorization_endpoint' => url('oauth2/authorize', array(
      'absolute' => TRUE,
    )),
    'redirect_uri' => url('oauth2/authorized', array(
      'absolute' => TRUE,
    )),
    'scope' => 'scope1 scope2',
  );

  // Test error handling.
  $oauth2_clients['wrong-client-id'] = array(
    'token_endpoint' => url('oauth2/token', array(
      'absolute' => TRUE,
    )),
    'client_id' => 'client_1',
    'client_secret' => 'secret1',
    'auth_flow' => 'client-credentials',
  );
  $oauth2_clients['wrong-client-secret'] = array(
    'token_endpoint' => url('oauth2/token', array(
      'absolute' => TRUE,
    )),
    'client_id' => 'client1',
    'client_secret' => 'secret_1',
    'auth_flow' => 'client-credentials',
  );
  $oauth2_clients['wrong-token-endpoint'] = array(
    'token_endpoint' => url('oauth2/token_1', array(
      'absolute' => TRUE,
    )),
    'client_id' => 'client1',
    'client_secret' => 'secret1',
    'auth_flow' => 'client-credentials',
  );
  $oauth2_clients['wrong-auth-flow'] = array(
    'auth_flow' => 'client-credentials-1',
  ) + $common;
  $oauth2_clients['wrong-username'] = array(
    'auth_flow' => 'user-password',
    'username' => 'user_1',
    'password' => 'pass1',
  ) + $common;
  $oauth2_clients['wrong-password'] = array(
    'auth_flow' => 'user-password',
    'username' => 'user1',
    'password' => 'pass_1',
  ) + $common;
  $oauth2_clients['wrong-scope'] = array(
    'token_endpoint' => url('oauth2/token', array(
      'absolute' => TRUE,
    )),
    'client_id' => 'client1',
    'client_secret' => 'secret1',
    'auth_flow' => 'client-credentials',
    'scope' => 'scope1 scope2 scope3',
  ) + $common;
  $oauth2_clients['wrong-authorization-endpoint'] = array(
    'auth_flow' => 'server-side',
    'authorization_endpoint' => url('oauth2/authorize_1', array(
      'absolute' => TRUE,
    )),
    'redirect_uri' => url('oauth2/authorized', array(
      'absolute' => TRUE,
    )),
  ) + $common;
  $oauth2_clients['wrong-redirect-uri'] = array(
    'auth_flow' => 'server-side',
    'authorization_endpoint' => url('oauth2/authorize', array(
      'absolute' => TRUE,
    )),
    'redirect_uri' => url('oauth2/authorized_1', array(
      'absolute' => TRUE,
    )),
  ) + $common;
  return $oauth2_clients;
}