使用 JWT 在 Laravel 中进行 SSO 客户端身份验证
SSO Client Authentication in Laravel by using JWT
我正在尝试基于 JWT 令牌在 Laravel 上创建身份验证系统。在项目中,我向 API 发送登录请求,如果用户成功登录,我将获得 Web Token。我正在为请求使用 Guzzle 包。
我搜索了很多关于它的文章,但其中 none 是有意义的。
我的控制器:
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);
}
}
使用 JWT,您可以使用此令牌从数据库中检索用户。所以把这个令牌放在用户的会话中,每次他做一些 "logged in" 相关的事情时,将他的令牌发送到你的 API 以检查是否是他。
我正在尝试基于 JWT 令牌在 Laravel 上创建身份验证系统。在项目中,我向 API 发送登录请求,如果用户成功登录,我将获得 Web Token。我正在为请求使用 Guzzle 包。
我搜索了很多关于它的文章,但其中 none 是有意义的。
我的控制器:
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);
}
}
使用 JWT,您可以使用此令牌从数据库中检索用户。所以把这个令牌放在用户的会话中,每次他做一些 "logged in" 相关的事情时,将他的令牌发送到你的 API 以检查是否是他。