GG资源网

单点登录从WordPress到媒体维基

问题描述:

I am trying to create Single sign-on from WordPress to MediaWiki. I have WPOauthServer running on my WordPress (WordPress plugin). And on my wiki I have Extension:OAuth2 Client installed. I want that my users only log in to WordPress and from there they can go to the wiki without logging to wiki again. The WPOauthServer is working fine, I am using the Grant type Authorization Code. I have tested by using curl and I am able to get the authorization code and using the authorization code I can acquire authentication token.

I have a button on my wordpress page with client id:

When I open the authorization link, I am redirected to the following redirect-URI that was set in client settings at server side:

and here I get an internal error:

Fatal exception of type \"GuzzleHttp\\Exception\\RequestException

upon digging i found out that this exception is caused in the extension file AbstractProvider.php in the sendRequest function:

the exception is caused in $response = $this->getHttpClient()->send($request);

I think maybe there is something wrong with my request, doing a var_dump on request reveals the following:

The stack trace from apache logs:

EDIT:
From the stack trace, I realized that scope is not defined in the media wiki client settings in localsettings.php, so after setting the scope I don\'t get any errors in the apache logs but media wiki still shows internal error Fatal exception of type \"GuzzleHttp\\Exception\\RequestException

Upon more digging, I found out that I was getting a curl: (60) SSL certificate: unable to get local issuer certificate error which I solved by adding the CA Root to my trusted CA for more information see this post

After solving this issue I just needed to correct the following:

see the answer for implenting SSO from WordPress

网友观点:

I was able to setup SSO (Single sign-on) from WordPress to media wiki, by following these steps:

  1. First you need an OAuth 2.0 server, you could implement it your self see details here Run your own OAuth 2.0 Server or the easiest way is to use the WordPress plugin WP Oauth 2.0 server you don\'t have to buy the pro, you can also implement SSO by using the Grant type Authorization codes which comes free.

  2. You need OAuth 2.0 client extension installed on your media wiki, the extension can be found here, follow the installation instructions there.

  3. Go to WordPress plugin page and activate OAuth server, then navigate to OAuth Server and add a new client, give your client a name and in Redirect URI add the link mention on the media wiki extension page i.e http://your.wiki.domain/path/to/wiki/Special:OAuth2Client/callback, then go to OAuth>clients page where you can see your newly created client, click edit and here you can see clientID and Client secret add this ID and secret in the localSettings.php of your media wiki.

  4. Create a page on WordPress and put the following button with your client id in it

    < a href=\\\"https://your-Domain-Where-OAuth-server-is-running.de/oauth/authorize?response_type=code&client_id=YOURCLIENTID&state=RANDOM-STRING&scope=basic\\\">
    go to wiki</a>

    don\'t forget to put scope otherwise you will get a media wiki internal error.

  5. If everything worked fine then you should automatically go to the media wiki main page after clicking this button from your WordPress. media wiki will show you as logged in. It took me some time to figure it out I hope this helps anyone who comes here.

###

I followed Ahmad\'s answer above and got part way there. However I had to make a one line source code change and additionally configure the LocalSettings for media wiki as originally posted here: https://www.mediawiki.org/wiki/Topic:Ux1crr4vosyw0tjl

Repeated for convenience:
I finally got it working with these additional steps - editing my LocalSettings.php; xxxx is my website starting with https://

In addition to setting the secret and ID I had to fill in the the configuration parameters with these settings - these are from my site.

$wgOAuth2Client[\'configuration\'][\'authorize_endpoint\'] = \'xxxx/oauth/authorize\'; // Authorization URL

$wgOAuth2Client[\'configuration\'][\'access_token_endpoint\'] = \'xxxx/oauth/token\'; // Token URL

$wgOAuth2Client[\'configuration\'][\'api_endpoint\'] = \'xxxx/oauth/me?access_token=\'; // URL to fetch user JSON

$wgOAuth2Client[\'configuration\'][\'redirect_uri\'] = \'xxxx/mediawiki/index.php?title=Special:OAuth2Client/redirect&returnto=Special%3AUserLogin\';

$wgOAuth2Client[\'configuration\'][\'username\'] = \'user_login\'; // JSON path to username

$wgOAuth2Client[\'configuration\'][\'email\'] = \'user_email\'; // JSON path to email

$wgOAuth2Client[\'configuration\'][\'scopes\'] = \'openid email profile\'; //Permissions

$wgWhitelistRead = array(\\\"Special:OAuth2Client\\\");

Then I also had to make one code change in .../mediawiki/extensions/MW-OAuth2Client/vendors/oauth2-client/src/Provider/AbstractProvider.php

protected function fetchResourceOwnerDetails(AccessToken $token)

After that the plugin worked as expected.

Note on installation of the mediawiki extension I got these composer warnings - I believe they can be safely ignored...

Package guzzle/guzzle is abandoned, you should avoid using it. Use guzzlehttp/guzzle instead.

Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.

Package satooshi/php-coveralls is abandoned, you should avoid using it. Use php-coveralls/php-coveralls instead.

Also I found this link useful in understanding how to use the wordpress plugin: https://wp-oauth.com/docs/how-to/setup-wp-oauth-server-for-single-sign-on-with-wordpress/

And I found you can just add the OAUTH plugin to wordpress from your site\'s WP admin page - just click the Add Plugins button - or search for \\\"oath\\\" by WP Oauth Server There is no need to get it from their WP OATH website where you can only find the paid version.

由于网站搬家,部分链接失效,如无法下载,请联系站长!谢谢支持!
1. 带 [亲测] 说明源码已经被站长亲测过!
2. 下载后的源码请在24小时内删除,仅供学习用途!
3. 分享目的仅供大家学习和交流,请不要用于商业用途!
4. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
5. 本站所有资源来源于站长上传和网络,如有侵权请邮件联系站长!
6. 没带 [亲测] 代表站长时间紧促,站长会保持每天更新 [亲测] 源码 !
7. 盗版ripro用户购买ripro美化无担保,若设置不成功/不生效我们不支持退款!
8. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
9. 如果你也有好源码或者教程,可以到审核区发布,分享有金币奖励和额外收入!
10.如果您购买了某个产品,而我们还没来得及更新,请联系站长或留言催更,谢谢理解 !
GG资源网 » 单点登录从WordPress到媒体维基

发表回复

CAPTCHAis initialing...