protected function AuthController::processUserLogin in Auth0 Single Sign On 8.2
Same name and namespace in other branches
- 8 src/Controller/AuthController.php \Drupal\auth0\Controller\AuthController::processUserLogin()
Process the Auth0 user profile and sign in or sign the user up.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The current request.
array $userInfo: The user data info.
string $idToken: ID token received during code exchange.
string $refreshToken: The refresh token.
int $expiresAt: When the token expires.
string $returnTo: The return url.
Return value
\Symfony\Component\HttpFoundation\RedirectResponse The redirect url.
Throws
\Exception An exception.
1 call to AuthController::processUserLogin()
- AuthController::callback in src/
Controller/ AuthController.php - Handles the callback for the oauth transaction.
File
- src/
Controller/ AuthController.php, line 544 - Contains \Drupal\auth0\Controller\AuthController.
Class
- AuthController
- Controller routines for auth0 authentication.
Namespace
Drupal\auth0\ControllerCode
protected function processUserLogin(Request $request, array $userInfo, $idToken, $refreshToken, $expiresAt, $returnTo) {
$this->auth0Logger
->notice('process user login');
$event = new Auth0UserPreLoginEvent($userInfo);
$this->eventDispatcher
->dispatch(Auth0UserPreLoginEvent::NAME, $event);
try {
$this
->validateUserEmail($userInfo);
// See if there is a user in the auth0_user table with the user
// info client ID.
$this->auth0Logger
->notice($userInfo['user_id'] . ' looking up Drupal user by Auth0 user_id');
$user = $this
->findAuth0User($userInfo['user_id']);
if ($user) {
$this->auth0Logger
->notice('uid of existing Drupal user found');
// User exists, update the auth0_user with the new userInfo object.
$this
->updateAuth0User($userInfo);
// Update field and role mappings.
$this
->auth0UpdateFieldsAndRoles($userInfo, $user);
$event = new Auth0UserSigninEvent($user, $userInfo, $refreshToken, $expiresAt);
$this->eventDispatcher
->dispatch(Auth0UserSigninEvent::NAME, $event);
}
else {
$this->auth0Logger
->notice('existing Drupal user NOT found');
$user = $this
->signupUser($userInfo);
$this
->insertAuth0User($userInfo, $user
->id());
$event = new Auth0UserSignupEvent($user, $userInfo);
$this->eventDispatcher
->dispatch(Auth0UserSignupEvent::NAME, $event);
}
} catch (EmailNotSetException $e) {
return $this
->failLogin($this
->t('This account does not have an email associated. Please login with a different provider.'), 'No Email Found');
} catch (EmailNotVerifiedException $e) {
return $this
->auth0FailWithVerifyEmail($idToken);
}
user_login_finalize($user);
if ($returnTo) {
return new RedirectResponse($returnTo);
}
elseif ($request->request
->has('destination')) {
return new RedirectResponse($request->request
->get('destination'));
}
return $this
->redirect('entity.user.canonical', [
'user' => $user
->id(),
]);
}