You are here

public static function Client::redirect in OAuth2 Client 7

Same name and namespace in other branches
  1. 7.2 src/Client.php \OAuth2\Client::redirect()

Redirect to the original path.

Redirects are registered with OAuth2\Client::setRedirect() The redirect contains the url to go to and the parameters to be sent to it.

2 calls to Client::redirect()
Client::getAccessToken in ./oauth2_client.inc
Get and return an access token.
oauth2_client_authorized in ./oauth2_client.module
Callback for path oauth2/authorized.

File

./oauth2_client.inc, line 391
Class OAuth2\Client

Class

Client
The class OAuth2\Client is used to get authorization from an oauth2 server. Its only goal is to get an access_token from the oauth2 server, so the only public function (besides the constructor) is getAccessToken().

Namespace

OAuth2

Code

public static function redirect($clean = TRUE) {
  if (!isset($_REQUEST['state'])) {
    return;
  }
  $state = $_REQUEST['state'];
  if (!isset($_SESSION['oauth2_client']['redirect'][$state])) {
    return;
  }
  $redirect = $_SESSION['oauth2_client']['redirect'][$state];

  // We don't expect a 'destination' query argument coming from the oauth2 server.
  // This would confuse and misguide the function drupal_goto() that is called below.
  if (isset($_GET['destination'])) {
    unset($_GET['destination']);
  }
  if ($redirect['client'] !== 'oauth2_client') {
    unset($_SESSION['oauth2_client']['redirect'][$state]);
  }
  else {
    if ($clean) {
      unset($_SESSION['oauth2_client']['redirect'][$state]);
      unset($_REQUEST['code']);
      unset($_REQUEST['state']);
    }
  }
  unset($_REQUEST['q']);
  drupal_goto($redirect['uri'], array(
    'query' => $redirect['params'] + $_REQUEST,
  ));
}