You are here

public function AuthController::login in Auth0 Single Sign On 8.2

Same name and namespace in other branches
  1. 8 src/Controller/AuthController.php \Drupal\auth0\Controller\AuthController::login()

Handles the login page override.

Parameters

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

Return value

array|\Drupal\Core\Routing\TrustedRedirectResponse The redirect or a renderable array.

1 string reference to 'AuthController::login'
auth0.routing.yml in ./auth0.routing.yml
auth0.routing.yml

File

src/Controller/AuthController.php, line 247
Contains \Drupal\auth0\Controller\AuthController.

Class

AuthController
Controller routines for auth0 authentication.

Namespace

Drupal\auth0\Controller

Code

public function login(Request $request) {
  global $base_root;
  $lockExtraSettings = $this->config
    ->get('auth0_lock_extra_settings');
  if (trim($lockExtraSettings) == "") {
    $lockExtraSettings = "{}";
  }
  $returnTo = $request->request
    ->get('returnTo', $request->query
    ->get('returnTo', NULL));

  // If supporting SSO, redirect to the hosted login page for authorization.
  if ($this->redirectForSso) {
    return new TrustedRedirectResponse($this
      ->buildAuthorizeUrl(NULL, $returnTo));
  }

  /* Not doing SSO, so show login page */
  return [
    '#theme' => 'auth0_login',
    '#loginCSS' => $this->config
      ->get('auth0_login_css'),
    '#attached' => [
      'library' => [
        'auth0/auth0.lock',
      ],
      'drupalSettings' => [
        'auth0' => [
          'clientId' => $this->config
            ->get('auth0_client_id'),
          'domain' => $this->helper
            ->getAuthDomain(),
          'lockExtraSettings' => $lockExtraSettings,
          'configurationBaseUrl' => $this->helper
            ->getTenantCdn($this->config
            ->get('auth0_domain')),
          'showSignup' => $this->config
            ->get('auth0_allow_signup'),
          'callbackURL' => "{$base_root}/auth0/callback",
          'state' => $this
            ->getNonce($returnTo),
          'scopes' => AUTH0_DEFAULT_SCOPES,
          'offlineAccess' => $this->offlineAccess,
          'formTitle' => $this->config
            ->get('auth0_form_title'),
          'jsonErrorMsg' => $this
            ->t('There was an error parsing the "Lock extra settings" field.'),
        ],
      ],
    ],
  ];
}