Authorization Code
。我已通过curl
进行测试,并且能够获得授权代码,使用授权代码我可以获取身份验证令牌。我在我的WordPress页面上放置了一个按钮并附带客户端ID。
<a href="https://xxxxxx.de/oauth/authorize?response_type=code&client_id=XXXXXXXXX&state=123">Connect Your Account</a>
当我打开授权链接时,我被重定向到服务器端客户端设置中所设置的以下
redirect-URI
页面:https://wiki.XXXXXXXXXXXXX.de/wiki/Special:OAuth2Client/callback?code=farkmm4ttuwxnne8a9firwtdikmite788hwpyhzg&state=123
在这里,我遇到了一个内部错误:
Fatal exception of type "GuzzleHttp\Exception\RequestException
深入研究后,我发现这个异常是由扩展文件AbstractProvider.php
中的sendRequest
函数引起的:
/**
* Sends a request instance and returns a response instance.
*
* @param RequestInterface $request
* @return ResponseInterface
*/
protected function sendRequest(RequestInterface $request)
{
try {
var_dump($request);
$response = $this->getHttpClient()->send($request);
var_dump($response);
} catch (BadResponseException $e) {
$response = $e->getResponse();
}
return $response;
}
异常原因出现在$response = $this->getHttpClient()->send($request);
我认为可能是我的请求有问题,在请求上使用var_dump
显示如下:
/var/www/mediawiki/w/extensions/MW-OAuth2Client/vendors/oauth2-client/src/Provider/AbstractProvider.php:629:
object(GuzzleHttp\Psr7\Request)[278]
private 'method' => string 'POST' (length=4)
private 'requestTarget' => null
private 'uri' =>
object(GuzzleHttp\Psr7\Uri)[279]
private 'scheme' => string 'https' (length=5)
private 'userInfo' => string '' (length=0)
private 'host' => string 'xxxxxxx.de' (length=13)
private 'port' => null
private 'path' => string '/oauth/token/' (length=13)
private 'query' => string '' (length=0)
private 'fragment' => string '' (length=0)
private 'headers' =>
array (size=2)
'Host' =>
array (size=1)
0 => string 'xxxxxx.de' (length=13)
'content-type' =>
array (size=1)
0 => string 'application/x-www-form-urlencoded' (length=33)
private 'headerNames' =>
array (size=2)
'content-type' => string 'content-type' (length=12)
'host' => string 'Host' (length=4)
private 'protocol' => string '1.1' (length=3)
private 'stream' =>
object(GuzzleHttp\Psr7\Stream)[287]
private 'stream' => resource(18, stream)
private 'size' => null
private 'seekable' => boolean true
private 'readable' => boolean true
private 'writable' => boolean true
private 'uri' => string 'php://temp' (length=10)
private 'customMetadata' =>
array (size=0)
empty
来自Apache日志的堆栈跟踪:
Notice: Undefined index: scopes in /var/www/mediawiki/w/extensions/MW-OAuth2Client/SpecialOAuth2Client.php on line 54, referer: https://XXXXXXerv.de/sso-test/
Stack trace:, referer: https://XXXXXXerv.de/sso-test/
1. {main}() /var/www/mediawiki/w/index.php:0, referer: https://XXXXXXerv.de/sso-test/
2. MediaWiki->run() /var/www/mediawiki/w/index.php:42, referer: https://XXXXXXerv.de/sso-test/
3. MediaWiki->main() /var/www/mediawiki/w/includes/MediaWiki.php:524, referer: https://XXXXXXerv.de/sso-test/
4. MediaWiki->performRequest() /var/www/mediawiki/w/includes/MediaWiki.php:861, referer: https://XXXXXXerv.de/sso-test/
5. SpecialPageFactory::getPage() /var/www/mediawiki/w/includes/MediaWiki.php:255, referer: https://XXXXXXerv.de/sso-test/
6. SpecialOAuth2Client->__construct() /var/www/mediawiki/w/includes/specialpage/SpecialPageFactory.php:382, referer: https://XXXXXXerv.de/sso-test/
Notice: Undefined index: scopes in /var/www/mediawiki/w/extensions/MW-OAuth2Client/SpecialOAuth2Client.php on line 54, referer: https://XXXXXXerv.de/sso-test/
Stack trace:, referer: https://XXXXXXerv.de/sso-test/
1. {main}() /var/www/mediawiki/w/index.php:0, referer: https://XXXXXXerv.de/sso-test/
2. MediaWiki->run() /var/www/mediawiki/w/index.php:42, referer: https://XXXXXXerv.de/sso-test/
3. MediaWiki->main() /var/www/mediawiki/w/includes/MediaWiki.php:524, referer: https://XXXXXXerv.de/sso-test/
4. MediaWiki->performRequest() /var/www/mediawiki/w/includes/MediaWiki.php:861, referer: https://XXXXXXerv.de/sso-test/
5. SpecialPageFactory::executePath() /var/www/mediawiki/w/includes/MediaWiki.php:288, referer: https://XXXXXXerv.de/sso-test/
6. SpecialPageFactory::getPage() /var/www/mediawiki/w/includes/specialpage/SpecialPageFactory.php:513, referer: https://XXXXXXerv.de/sso-test/
7. SpecialOAuth2Client->__construct() /var/www/mediawiki/w/includes/specialpage/SpecialPageFactory.php:382, referer: https://XXXXXXerv.de/sso-test/
编辑:
根据堆栈跟踪,我意识到在localsettings.php
中的mediawiki客户端设置中未定义scope
,因此在设置了范围之后,我的apache日志中没有任何错误,但是mediawiki仍然显示内部错误,Fatal exception of type "GuzzleHttp\Exception\RequestException
。更深入地挖掘后,我发现出现了
curl: (60) SSL certificate: unable to get local issuer certificate
错误,通过将CA根添加到我的受信任CA中解决了这个问题,有关更多信息,请参见此帖子。解决了这个问题后,我只需要纠正以下内容即可:
$wgOAuth2Client['configuration']['username'] = 'user_login'; // JSON path to username
$wgOAuth2Client['configuration']['email'] = 'user_email'; // JSON path to email
请参见有关从WordPress实施SSO的答案。
guzzlehttp
,命名空间为League\OAuth2\Client\Provider;
- Ahmad Karim