简体   繁体   English

如何基于JWT API认证用户-Laravel 5.8?

[英]How to authenticate user base on JWT API - Laravel 5.8?

I'm using PHP 7.2 on Laravel 5.8. 我在Laravel 5.8上使用PHP 7.2。

I current use Auth provider that came with Laravel to log my users in. 我目前使用Laravel随附的Auth提供程序登录我的用户。

It currently check if the email, and password match in the database configured. 当前,它将检查配置的数据库中的电子邮件和密码是否匹配。

I did this 我做了这个

$dbAuth = Auth::attempt(array(
    'email' => $email,
    'password' => $password
));

if ($dbAuth) {

    return Redirect::to('/dashboard')->with('success', 'You have been successfully logged in.');

} else {
    return Redirect::to('/')->with('error', 'Username/Password Wrong')->with('email', $email)->withErrors($validator);
} 

I can't do that anymore, I have to talk to call an API that return a token. 我不能再这样做了,我不得不谈谈调用返回令牌的API。


Just to clarify : 只是澄清一下:

My main goal is to call JWT API, and logged my user in if I got the 200 response. 我的主要目标是调用JWT API,如果收到200响应,则登录我的用户。

How do log my users in now? 现在如何登录我的用户?

I would recommend you use this package for JWT auth, it has a good documentation as well. 我建议您将此包用于JWT身份验证,它也有一个很好的文档。

https://github.com/tymondesigns/jwt-auth https://github.com/tymondesigns/jwt-auth

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

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