public function authenticateByCode($provider, string $code)
    {
        $provider_user = $provider->user();

        /** @var \Railken\Amethyst\Repositories\UserRepository */
        $repository = $this->manager->getRepository();

        $user = $repository->findOneByEmail($provider_user->getEmail());

        if (!$user) {
            $result = $this->manager->create([
                'name'     => $provider_user->getNickname() ? $provider_user->getNickname() : $provider_user->getName(),
                'role'     => 'user',
                'password' => str_random(32),
                'email'    => $provider_user->getEmail(),
            ]);

            if (!$result->ok()) {
                return $this->response(['errors' => $result->getSimpleErrors()], Response::HTTP_BAD_REQUEST);
            }

            $user = $result->getResource();
        }

        $token = Container::getInstance()->make(\Laravel\Passport\PersonalAccessTokenFactory::class)->make(
            $user->getKey(),
            'login',
            []
        );

        return $this->response([
            'token_type'   => 'Bearer',
            'expires_in'   => 0,
            'access_token' => $token->accessToken,
        ], Response::HTTP_OK);
    }
public function authenticateByCode($provider, string $code)
    {
        $provider_user = $provider->user();

        /** @var \Railken\Amethyst\Repositories\UserRepository */
        $repository = $this->manager->getRepository();

        $user = $repository->findOneByEmail($provider_user->getEmail());

        if (!$user) {
            $result = $this->manager->create([
                'name'     => $provider_user->getNickname() ? $provider_user->getNickname() : $provider_user->getName(),
                'role'     => 'user',
                'password' => str_random(32),
                'email'    => $provider_user->getEmail(),
            ]);

            if (!$result->ok()) {
                return $this->response(['errors' => $result->getSimpleErrors()], Response::HTTP_BAD_REQUEST);
            }

            $user = $result->getResource();
        }

        $token = Container::getInstance()->make(\Laravel\Passport\PersonalAccessTokenFactory::class)->make(
            $user->getKey(),
            'login',
            []
        );

        return $this->response([
            'token_type'   => 'Bearer',
            'expires_in'   => 0,
            'access_token' => $token->accessToken,
        ], Response::HTTP_OK);
    }
public function authenticateByCode ( $ provider , string $ code ) { $ provider_user = $ provider -> user ( ) ; /** @var \Railken\Amethyst\Repositories\UserRepository */ $ repository = $ this -> manager -> getRepository ( ) ; $ user = $ repository -> findOneByEmail ( $ provider_user -> getEmail ( ) ) ; if ( ! $ user ) { $ result = $ this -> manager -> create ( [ 'name' => $ provider_user -> getNickname ( ) ? $ provider_user -> getNickname ( ) : $ provider_user -> getName ( ) , 'role' => 'user' , 'password' => str_random ( 32 ) , 'email' => $ provider_user -> getEmail ( ) , ] ) ; if ( ! $ result -> ok ( ) ) { return $ this -> response ( [ 'errors' => $ result -> getSimpleErrors ( ) ] , Response :: HTTP_BAD_REQUEST ) ; } $ user = $ result -> getResource ( ) ; } $ token = Container :: getInstance ( ) -> make ( \ Laravel \ Passport \ PersonalAccessTokenFactory :: class ) -> make ( $ user -> getKey ( ) , 'login' , [ ] ) ; return $ this -> response ( [ 'token_type' => 'Bearer' , 'expires_in' => 0 , 'access_token' => $ token -> accessToken , ] , Response :: HTTP_OK ) ; }
Authenticate a user by the "code" of oauth2.

@param \Laravel\Socialite\Two\AbstractProvider $provider
@param string                                  $code

@return \Symfony\Component\HttpFoundation\Response
Authenticate a user by the code of oauth2 .