src/Synapse/SocialLogin/SocialLoginService.php
public function handleLinkRequest(LoginRequest $request, $userId)
    {
        $socialLogin = $this->socialLoginMapper->findByProviderUserId(
            $request->getProvider(),
            $request->getProviderUserId()
        );

        if ($socialLogin) {
            throw new LinkedAccountExistsException;
        }

        $user = $this->userService->findById($userId);

        if (! $user) {
            throw new OutOfBoundsException('Account not found', self::EXCEPTION_ACCOUNT_NOT_FOUND);
        }

        $socialLoginEntity = new SocialLoginEntity;
        $socialLoginEntity->setUserId($user->getId())
            ->setProvider($request->getProvider())
            ->setProviderUserId($request->getProviderUserId())
            ->setAccessToken($request->getAccessToken())
            ->setAccessTokenExpires($request->getAccessTokenExpires())
            ->setRefreshToken($request->getRefreshToken());

        $socialLogin = $this->socialLoginMapper->persist($socialLoginEntity);

        return $this->handleLogin($user, $request);
    }
public function handleLinkRequest(LoginRequest $request, $userId)
    {
        $socialLogin = $this->socialLoginMapper->findByProviderUserId(
            $request->getProvider(),
            $request->getProviderUserId()
        );

        if ($socialLogin) {
            throw new LinkedAccountExistsException;
        }

        $user = $this->userService->findById($userId);

        if (! $user) {
            throw new OutOfBoundsException('Account not found', self::EXCEPTION_ACCOUNT_NOT_FOUND);
        }

        $socialLoginEntity = new SocialLoginEntity;
        $socialLoginEntity->setUserId($user->getId())
            ->setProvider($request->getProvider())
            ->setProviderUserId($request->getProviderUserId())
            ->setAccessToken($request->getAccessToken())
            ->setAccessTokenExpires($request->getAccessTokenExpires())
            ->setRefreshToken($request->getRefreshToken());

        $socialLogin = $this->socialLoginMapper->persist($socialLoginEntity);

        return $this->handleLogin($user, $request);
    }
public function handleLinkRequest ( LoginRequest $ request , $ userId ) { $ socialLogin = $ this -> socialLoginMapper -> findByProviderUserId ( $ request -> getProvider ( ) , $ request -> getProviderUserId ( ) ) ; if ( $ socialLogin ) { throw new LinkedAccountExistsException ; } $ user = $ this -> userService -> findById ( $ userId ) ; if ( ! $ user ) { throw new OutOfBoundsException ( 'Account not found' , self :: EXCEPTION_ACCOUNT_NOT_FOUND ) ; } $ socialLoginEntity = new SocialLoginEntity ; $ socialLoginEntity -> setUserId ( $ user -> getId ( ) ) -> setProvider ( $ request -> getProvider ( ) ) -> setProviderUserId ( $ request -> getProviderUserId ( ) ) -> setAccessToken ( $ request -> getAccessToken ( ) ) -> setAccessTokenExpires ( $ request -> getAccessTokenExpires ( ) ) -> setRefreshToken ( $ request -> getRefreshToken ( ) ) ; $ socialLogin = $ this -> socialLoginMapper -> persist ( $ socialLoginEntity ) ; return $ this -> handleLogin ( $ user , $ request ) ; }
Handle a request to link a social account to a non-social account

@param  LoginRequest $request
@param  string       $userId  ID of the non-social account to link with the social account
@return array        Access token
Handle a request to link a social account to a non - social account