You are here

protected function AuthenticationController::getAuthorizationCode in Janrain Registration 8

Returns the authorization code.

Parameters

\Symfony\Component\HttpFoundation\Request $request: The current request.

Return value

string The OAuth authorization code.

1 call to AuthenticationController::getAuthorizationCode()
AuthenticationController::login in src/Controller/AuthenticationController.php
Login or reset a password for a user using Janrain API.

File

src/Controller/AuthenticationController.php, line 174

Class

AuthenticationController
Authentication controller.

Namespace

Drupal\janrain_capture\Controller

Code

protected function getAuthorizationCode(Request $request) : string {

  // If the request has no "code" it means it's malformed.
  if (!$request->query
    ->has('code')) {
    throw new BadRequestHttpException($this
      ->t('Malformed request. Authorization code is missing.'));
  }
  $code = $request->query
    ->get('code');

  // The code must be read first and then removed from the request. This
  // is required for an operation, for instance, for resetting the password.
  // The link that user will get via email will look the following:
  // https://a.com/janrain_capture/oauth?url_type=forgot&code=8uy9j8quyj3tam
  // The Janrain will expect "redirect_uri" without the "code":
  // https://a.com/janrain_capture/oauth?url_type=forgot
  // If the domain will differ, OAuth will throw the "redirect_uri does not
  // match expected value" error.
  $request->query
    ->remove('code');

  // Override global variables to ensure the "code" is no longer presented.
  $request
    ->overrideGlobals();

  // Return ejected value.
  return $code;
}