You are here

function _oauth2_proxy_login in OAuth2 Login 7.2

Same name and namespace in other branches
  1. 7 oauth2_login.module \_oauth2_proxy_login()

Function for: oauth2/proxy/login.

1 call to _oauth2_proxy_login()
oauth2_proxy_callback in ./oauth2_login.module
Callback function for the menu oauth2/proxy. The parameter $action can be: login|logout|refresh

File

./oauth2_login.module, line 117
Provides OAuth2 Login functionality.

Code

function _oauth2_proxy_login() {
  if (user_is_anonymous()) {
    $query = [
      'proxy' => 'true',
    ] + $_GET;
    unset($query['q']);
    drupal_goto('user/oauth2_login', [
      'query' => $query,
    ]);
  }
  else {

    // Get the token.
    $oauth2 = new OAuth2\Client(oauth2_login_get_oauth2_settings());
    $oauth2
      ->getAccessToken();

    // Return the token to the mobile app.
    $json_token = json_encode($oauth2
      ->token());
    print "<script>opener.postMessage({$json_token}, '*');</script>";
    drupal_exit();
  }
}