JellyBool 讲师
在上一个视频我们实现 login 的时候,直接将敏感的 secret 信息写到了 js 代码当中,这是极其不推荐的做法。然后本节视频主要着重引入一层 Proxy 代理,将敏感的信息直接保存到后端,但在这基础之上,我们的 token 分发和校验还是成功的。
此视频为收费视频,需登录后购买方可观看
JellyBool 讲师
在上一个视频我们实现 login 的时候,直接将敏感的 secret 信息写到了 js 代码当中,这是极其不推荐的做法。然后本节视频主要着重引入一层 Proxy 代理,将敏感的信息直接保存到后端,但在这基础之上,我们的 token 分发和校验还是成功的。
class TokenProxy {
protected $http;
public function __construct(\GuzzleHttp\Client $http) {
$this->http = $http;
}
public function proxy($grantType, array $data = [] ) {
// /oauth/token
$data = array_merge($data, [
'client_id' => env('PASSPORT_CLIENT_ID'),
'client_secret' => env('PASSPORT_CLIENT_SECRET'),
'grant_type' => $grantType
]);
$response = $this->http->post('http://phpstudy/oauth/token', [
'form_params' => $data
]);
$token = json_decode((string) $response->getBody(), true);
return $response()->json([
'token' => $token['access_token'],
'expires_in' => $token['expires_in']
])->cookie('refreshToken', $token['refresh_token'], 864000, null, null, false, true);
}
}
下面是接口返回的报错
我是照着视频上写的,不知道为什么会出现这个错误。根据视频确认了好几遍,也没有发现有什么问题,请问这个应该怎么修改?
public function proxy($grantType, array $data = [])
{
$data = array_merge($data, [
'client_id' => env('PASSPORT_CLIENT_ID'),
'client_secret' => env('PASSPORT_CLIENT_SEERET'),
'grant_type' => $grantType,
]);
$response = $this->http->post("http://laravel-el.test/oauth/token", [
'form_params' => $data
]);
$token = json_decode((string) $response->getBody(), true);
return response()->json([
'token' => $token['access_token'],
'expires_in' => $token['expires_in'],
])->cookie('refreshToken', $token['refresh_token'], 864000, null, null, false, true);
}
上面这个接口请求的时候报错:
exception: "GuzzleHttp\Exception\ConnectException"
file: "/Users/chicv/www/laravel-el/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php"
line: 185
message: "cURL error 6: Could not resolve: laravel-el.test (Domain name not found)
说明:http://laravel-el.test这个域名是我从我的项目地址栏直接复制下来的,是可以打开我的页面的,但是报这个错,请问是啥原因呀?