[英]League\OAuth2\Client\Provider\GenericProvider SSL error
I used "league/oauth2-client" library and tried to get access token from provider. 我使用了“ league / oauth2-client”库,并尝试从提供程序获取访问令牌。 My first step that getting authorization code working properly.
我的第一步是使授权代码正常工作。 When i request for access token to provider, i got exception like "cURL error 51: SSL: no alternative certificate subject name matches target host name 'XXX.XXX.com'" .
当我请求提供者访问令牌时,出现了类似“ cURL错误51:SSL:没有其他证书主题名称与目标主机名'XXX.XXX.com”匹配的异常”。
I used Postman to get access token manually with given proper parameters. 我使用邮递员通过给定适当参数手动获取访问令牌。 It worked fine and provider returned access token to postman.
工作正常,提供商将访问令牌返回给邮递员。
https://github.com/thephpleague/oauth2-client https://github.com/thephpleague/oauth2-client
$provider = new \League\OAuth2\Client\Provider\GenericProvider([
'clientId' => 'XXX',
'clientSecret' => 'YYY',
'redirectUri' => 'https://exampleclient.com/oauth',
'urlAuthorize' => 'https://example.com/OAuth2AuthorizationServer/AuthorizationController',
'urlAccessToken' => 'https://example.com/oauth/AccessTokenController',
'urlResourceOwnerDetails' => 'https://example.com/oauth/ResourceController',
'scopes' => array('BLABLA'),
'verify' => false,
]);
try {
$accessToken = $provider->getAccessToken('authorization_code', [
'code' => $_GET['code']
]);
echo 'Access Token: ' . $accessToken->getToken() . "<br>";
echo 'Refresh Token: ' . $accessToken->getRefreshToken() . "<br>";
echo 'Expired in: ' . $accessToken->getExpires() . "<br>";
echo 'Already expired? ' . ($accessToken->hasExpired() ? 'expired' : 'not expired') . "<br>";
$resourceOwner = $provider->getResourceOwner($accessToken);
var_export($resourceOwner->toArray());
die;
} catch (Exception $e) {
// Failed to get the access token or user details.
exit($e->getMessage());
}
league/oauth2-client library uses GuzzleHttp\\Client so we need to set League / oauth2-client库使用GuzzleHttp \\ Client,因此我们需要设置
GuzzleHttp\\RequestOptions::VERIFY => false
The easiest way to do this create a new GuzzleHttp\\Client and set its VERIFY option to false. 执行此操作的最简单方法是创建一个新的GuzzleHttp \\ Client并将其VERIFY选项设置为false。
$guzzyClient = new GuzzleHttp\Client([
'defaults' => [
\GuzzleHttp\RequestOptions::CONNECT_TIMEOUT => 5,
\GuzzleHttp\RequestOptions::ALLOW_REDIRECTS => true],
\GuzzleHttp\RequestOptions::VERIFY => false,
]);
$provider->setHttpClient($guzzyClient);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.