简体   繁体   English

使用JWT在Laravel中进行SSO客户端身份验证

[英]SSO Client Authentication in Laravel by using JWT

I am trying to create a authentication system on Laravel based on JWT token. 我正在尝试基于JWT令牌在Laravel上创建身份验证系统。 In the project, I am sending a login request to API and get Web Token if user succesfully login. 在项目中,如果用户成功登录,我将向API发送登录请求并获取Web令牌。 I am using Guzzle package for the requests. 我正在对请求使用Guzzle软件包。

I search lots of article about it but none of them make sense. 我搜索了很多有关它的文章,但没有一篇是有意义的。

My Controller : 我的控制器:

public function sigin()
{
    $client = new Client();
    $url = "https://localhost:8080/users/login";     

    $user->email = Input::get("email");
    $user->password = Input::get("password");

    $json_data = json_encode($user);

    try{
        $response = $client->request('POST',$url,[
            GuzzleHttp\RequestOptions::JSON => $json_data
        ]);

        // geting the Token in the response object. What should I do after get it 

    }
    catch(ServerException $exception)
    {
        $responseBody = $exception->getResponse()->getBody(true);
    }
}

With JWT you can retrieve a user from your database with this token. 使用JWT,您可以使用此令牌从数据库中检索用户。 So put this token in the user's session and every time he does something "logged in" related, send his token to your API to check if it's him. 因此,将此令牌放入用户的会话中,并在他每次进行“登录”相关的操作时,都将其令牌发送到您的API,以检查是否是他。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM