You are here

function hook_openid_connect_pre_authorize in OpenID Connect / OAuth client 7

Same name and namespace in other branches
  1. 8 openid_connect.api.php \hook_openid_connect_pre_authorize()
  2. 2.x openid_connect.api.php \hook_openid_connect_pre_authorize()

Pre authorize hook that runs before a user is authorized.

Parameters

array $tokens: ID token and access token that we received as a result of the OpenID Connect flow.

object $account: The user account if it exists, false if not.

array $userinfo: The user claims returned by the OpenID Connect provider.

string $client_name: The machine name of the OpenID Connect client plugin.

Return value

bool TRUE if user should be logged into Drupal. FALSE if not.

2 invocations of hook_openid_connect_pre_authorize()
openid_connect_complete_authorization in ./openid_connect.module
Complete the authorization after tokens have been retrieved.
openid_connect_connect_current_user in ./openid_connect.module
Connect the current user's account to an external provider.

File

./openid_connect.api.php, line 29
Hooks provided by the OpenID Connect module.

Code

function hook_openid_connect_pre_authorize(array $tokens, $account, array $userinfo, $client_name) {
  $allowed_users = array(
    'user1@example.com',
    'user2@example.com',
  );

  // Allow only specific users to log in.
  if (in_array($userinfo['email'], $allowed_users)) {
    return TRUE;
  }

  // Block all others.
  return FALSE;
}