我正在尝试使用Angular 6获取包含在JWT令牌中的数据。
我可以执行登录操作,并使用Lumen 5.6返回令牌-tymondesigns / jwt-auth
但是,当我在JS中打印时,我得到了:
iat: 1531073200
iss: "https://api.kz-api.test/auth/login"
jti: "taCmXQoo0jWs4y7t"
nbf: 1531073200
prv: "87e0af1ef9fd15812fdec97153a14e0b047546aa"
sub: 1
我认为我应该将用户对象放在“ sub”数组中,因为它标识了JWT的主题,但我只能找到1…。 我的代码有什么问题:
/**
* Authenticate a user and return the token if the provided credentials are correct.
*
* @return mixed
*/
public function authenticate()
{
// Find the user by email
$user = User::where('email', $this->request->input('email'))->first();
if (!$user) {
return response()->json('login.wrong_email', HttpResponse::HTTP_UNAUTHORIZED);
}
$credentials = Input::only('email', 'password');
if (!$token = JWTAuth::attempt($credentials)) {
return response()->json('login.wrong_password', HttpResponse::HTTP_UNAUTHORIZED);
}
return response()->json(compact('token'), HttpResponse::HTTP_ACCEPTED);
}