public static function OAuth2Client::redirect in OAuth2 Client 8
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.
Overrides OAuth2ClientInterface::redirect
2 calls to OAuth2Client::redirect()
- OAuth2Client::getAccessToken in src/
Service/ OAuth2Client.php - OAuth2ClientController::redirectUrlPage in src/
Controller/ OAuth2ClientController.php - Callback for path oauth2/authorized.
File
- src/
Service/ OAuth2Client.php, line 270
Class
- OAuth2Client
- OAuth2Client service.
Namespace
Drupal\oauth2_client\ServiceCode
public static function redirect($clean = TRUE) {
if (!\Drupal::service('request_stack')
->getCurrentRequest()
->get('state')) {
return;
}
$state = \Drupal::service('request_stack')
->getCurrentRequest()
->get('state');
/** @var \Drupal\Core\TempStore\PrivateTempStore $tempstore */
$tempstore = \Drupal::service('tempstore.private')
->get('oauth2_client');
$redirects = $tempstore
->get('redirect');
if (!isset($redirects[$state])) {
return;
}
$redirect = $redirects[$state];
if ($redirect['client'] != 'oauth2_client') {
unset($redirects[$state]);
$tempstore
->set('redirect', $redirects);
$params = isset($redirect['params']) ? $redirect['params'] : [];
$params = $params + \Drupal::request()->query
->all();
$url = Url::fromUri($redirect['uri'], [
'query' => $params,
]);
$redirect = new RedirectResponse($url);
$redirect
->send();
exit;
}
else {
$params = \Drupal::request()->query
->all();
if ($clean) {
unset($redirects[$state]);
$tempstore
->set('redirect', $redirects);
unset($params['code']);
unset($params['state']);
}
if (isset($redirect['params'])) {
$params = $redirect['params'] + $params;
}
$url = Url::fromUri('internal:' . $redirect['uri'], [
'query' => $params,
]);
$redirect = new RedirectResponse($url
->toString());
$redirect
->send();
exit;
}
}