You are here

public function UserAuthenticator::authenticateWithProvider in Social Auth 8.2

Same name and namespace in other branches
  1. 3.x src/User/UserAuthenticator.php \Drupal\social_auth\User\UserAuthenticator::authenticateWithProvider()

Authenticates user using provider.

Parameters

int $user_id: The Drupal user id.

Return value

bool True is user provider could be associated. False otherwise.

1 call to UserAuthenticator::authenticateWithProvider()
UserAuthenticator::authenticateUser in src/User/UserAuthenticator.php
Creates and/or authenticates an user.

File

src/User/UserAuthenticator.php, line 193

Class

UserAuthenticator
Manages Drupal authentication tasks for Social Auth.

Namespace

Drupal\social_auth\User

Code

public function authenticateWithProvider($user_id) {
  try {

    // Load the user by their Drupal user id.
    $drupal_user = $this->userManager
      ->loadUserByProperty('uid', $user_id);
    if ($drupal_user) {

      // Authenticates and redirect existing user.
      $this
        ->authenticateExistingUser($drupal_user);
      return TRUE;
    }
    return FALSE;
  } catch (\Exception $ex) {
    $this->loggerFactory
      ->get($this
      ->getPluginId())
      ->error('Failed to authenticate user. Exception: @message', [
      '@message' => $ex
        ->getMessage(),
    ]);
    return FALSE;
  }
}