public function loadUserByUsername($username)
    {
        try {
            $payload = $this->googleClient->verifyIdToken($username);
            $email = $payload['email'];
            $googleUserId = $payload['sub'];

            $user = $this->userService->findByGoogleUserId($googleUserId);

            if (!empty($user)) {
                return $user;
            }

            $user = $this->userService->findUserByEmail($email);

            // This means that the user is registering for the first time
            if (!empty($user)) {
                $this->updateUserWithGoogleUserId($user, $googleUserId);
                return $user;
            }

            return $this->registerUser($email, $googleUserId);
        }
        catch (\LogicException $ex) {
            throw new UsernameNotFoundException("Google AuthToken Did Not validate, ERROR MESSAGE " . $ex->getMessage(), ProgrammerException::GOOGLE_USER_PROVIDER_LOGIC_EXCEPTION);

        }
        catch (\Exception $ex) {
            throw new UsernameNotFoundException("Google AuthToken Did Not validate, ERROR MESSAGE " . $ex->getMessage(), ProgrammerException::GOOGLE_USER_PROVIDER_EXCEPTION);
        }
    }
public function loadUserByUsername($username)
    {
        try {
            $payload = $this->googleClient->verifyIdToken($username);
            $email = $payload['email'];
            $googleUserId = $payload['sub'];

            $user = $this->userService->findByGoogleUserId($googleUserId);

            if (!empty($user)) {
                return $user;
            }

            $user = $this->userService->findUserByEmail($email);

            // This means that the user is registering for the first time
            if (!empty($user)) {
                $this->updateUserWithGoogleUserId($user, $googleUserId);
                return $user;
            }

            return $this->registerUser($email, $googleUserId);
        }
        catch (\LogicException $ex) {
            throw new UsernameNotFoundException("Google AuthToken Did Not validate, ERROR MESSAGE " . $ex->getMessage(), ProgrammerException::GOOGLE_USER_PROVIDER_LOGIC_EXCEPTION);

        }
        catch (\Exception $ex) {
            throw new UsernameNotFoundException("Google AuthToken Did Not validate, ERROR MESSAGE " . $ex->getMessage(), ProgrammerException::GOOGLE_USER_PROVIDER_EXCEPTION);
        }
    }
public function loadUserByUsername ( $ username ) { try { $ payload = $ this -> googleClient -> verifyIdToken ( $ username ) ; $ email = $ payload [ 'email' ] ; $ googleUserId = $ payload [ 'sub' ] ; $ user = $ this -> userService -> findByGoogleUserId ( $ googleUserId ) ; if ( ! empty ( $ user ) ) { return $ user ; } $ user = $ this -> userService -> findUserByEmail ( $ email ) ; // This means that the user is registering for the first time if ( ! empty ( $ user ) ) { $ this -> updateUserWithGoogleUserId ( $ user , $ googleUserId ) ; return $ user ; } return $ this -> registerUser ( $ email , $ googleUserId ) ; } catch ( \ LogicException $ ex ) { throw new UsernameNotFoundException ( "Google AuthToken Did Not validate, ERROR MESSAGE " . $ ex -> getMessage ( ) , ProgrammerException :: GOOGLE_USER_PROVIDER_LOGIC_EXCEPTION ) ; } catch ( \ Exception $ ex ) { throw new UsernameNotFoundException ( "Google AuthToken Did Not validate, ERROR MESSAGE " . $ ex -> getMessage ( ) , ProgrammerException :: GOOGLE_USER_PROVIDER_EXCEPTION ) ; } }
1) We validate the access token by fetching the user information
2) We search for google user id and if one is found we return that user
3) Then we search by email and if one is found we update the user to have that google user id
4) If nothing is found we register the user with google user id
@param string $username
@return BaseUser
1 ) We validate the access token by fetching the user information 2 ) We search for google user id and if one is found we return that user 3 ) Then we search by email and if one is found we update the user to have that google user id 4 ) If nothing is found we register the user with google user id