You are here

function mo_oauth_client_initiateLogin in Drupal OAuth & OpenID Connect Login - OAuth2 Client SSO Login 7

This function initiates the oauth sso flow

2 calls to mo_oauth_client_initiateLogin()
miniorange_oauth_client_mologin in ./miniorange_oauth_client.module
test_mo_config in ./miniorange_oauth_client.module

File

includes/Handler.php, line 6

Code

function mo_oauth_client_initiateLogin() {
  global $base_url;
  $_SESSION['redirect_url'] = $_SERVER['HTTP_REFERER'];
  $app_name = variable_get('miniorange_auth_client_app_name', '');
  $client_id = variable_get('miniorange_auth_client_client_id', '');
  $client_secret = variable_get('miniorange_auth_client_client_secret', '');
  $scope = variable_get('miniorange_auth_client_scope', '');
  $authorizationUrl = variable_get('miniorange_auth_client_authorize_endpoint', '');
  $callback_uri = variable_get('miniorange_auth_client_callback_uri', '');
  $state = base64_encode($app_name);
  if (strpos($authorizationUrl, '?') !== false) {
    $authorizationUrl = $authorizationUrl . "&client_id=" . $client_id . "&scope=" . $scope . "&redirect_uri=" . $callback_uri . "&response_type=code&state=" . $state;
  }
  else {
    $authorizationUrl = $authorizationUrl . "?client_id=" . $client_id . "&scope=" . $scope . "&redirect_uri=" . $callback_uri . "&response_type=code&state=" . $state;
  }
  $_SESSION['oauth2state'] = $state;
  $_SESSION['appname'] = $app_name;
  header('Location: ' . $authorizationUrl);
  drupal_goto($authorizationUrl);
}