gpt4 book ai didi

php - League\OAuth2\Client\Provider\GenericProvider SSL 错误

转载 作者:太空宇宙 更新时间:2023-11-03 13:30:34 25 4
gpt4 key购买 nike

我使用了“league/oauth2-client”库并尝试从提供商处获取访问 token 。我的第一步是让授权码正常工作。当我向提供者请求访问 token 时,出现异常,例如“cURL 错误 51:SSL:没有替代证书主题名称与目标主机名‘XXX.XXX.com’匹配”。

我使用 Postman 通过给定的适当参数手动获取访问 token 。它运行良好,提供商将访问 token 返回给 postman 。

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 库使用 GuzzleHttp\Client 所以我们需要设置

GuzzleHttp\RequestOptions::VERIFY => 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);

关于php - League\OAuth2\Client\Provider\GenericProvider SSL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56681332/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com