Skip to content

Commit 46e8ef0

Browse files
committed
Add support for OAuth2 authentication against MediaWiki installs
This uses [[Extension:OAuth]], which is installed on Wikimedia wikis.
1 parent 99e2594 commit 46e8ef0

File tree

4 files changed

+78
-2
lines changed

4 files changed

+78
-2
lines changed

docs/config-oauth2.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ specify it with `oauth2_CallbackURL`.
2121

2222
You might also need to tell Federated Wiki how to look up usernames:
2323
* `oauth2_UserInfoURL` -- from login provider's documentation
24+
* If this endpoint expects an HTTP Authorization header (instead of
25+
a token in the query string) set `oauth2_UseHeader` to `true`.
2426
* `oauth2_IdField`, `oauth2_DisplayNameField`, `oauth2_UsernameField` -- starting with
2527
* `params` for information returned in the original token request, or
2628
* `profile` for data returned from `oauth2_UserInfoURL`, if you provided it.

docs/config-wikimedia.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
## Wikimedia
2+
3+
MediaWiki instances running
4+
[Extension:OAuth](https://www.mediawiki.org/wiki/Special:MyLanguage/Extension:OAuth),
5+
including all Wikimedia wikis (like Wikipedia), can be used as an
6+
OAuth authentication source.
7+
8+
### Register an application with Wikimedia
9+
10+
* Review the [OAuth app
11+
guidelines](https://meta.wikimedia.org/wiki/OAuth_app_guidelines) on
12+
meta.wikimedia.org.
13+
* As described on that page, propose a new client registration at
14+
[Special:OAuthConsumerRegistration/propose](https://meta.wikimedia.org/wiki/Special:OAuthConsumerRegistration/propose).
15+
Use the "Propose an OAuth 2.0 client" link.
16+
* Provide your wiki details:
17+
** An application name; presumably the name of your wiki. If you
18+
include "test" in the name or "localhost" in the callback URL
19+
the authorization will work only on your own account and only
20+
for 30 days.
21+
** Set the Consumer version to `1.0`
22+
** Describe your application; you might want to mention that the
23+
software is open-source and available at
24+
https://github.com/fedwiki/wiki-security-passportjs/
25+
** You can click "This consumer is for use only by..." if this will
26+
be a single-user wiki.
27+
** You will need to specify a callback URL. For local testing this
28+
will be http://localhost:3000/auth/oauth2/callback but for a wiki
29+
visible to the external internet you will need to update the host
30+
portion. This is a callback provided by `wiki-security-passport`.
31+
** You will need an "Authorization code" grant type, and probably a
32+
"Refresh token" grant as well; you don't need "Client credentials".
33+
** You will probably check "User identity verification only", either
34+
with "access to real name..." if you want to use the
35+
`oauth2_DisplayNameField` feature or without that otherwise.
36+
"Request authorization for specific permissions" is only needed if
37+
you are working on a deeper integration with MediaWiki.
38+
39+
When you click on "Propose registration" you will get a client
40+
application key and client application secret which you will use
41+
to create a `config.json`. Note that you can access the details
42+
of your registration later at
43+
[Special:OAuthConsumerRegistration/list](https://meta.wikimedia.org/wiki/Special:OAuthConsumerRegistration/list).
44+
45+
### Configure Wiki
46+
47+
The Wiki is configured by adding the `Consumer Key` and `Consumer Secret` to the configuration. As long as we have not selected `Enable Callback Locking` these can be added outside the `wikiDomains` definition, so they apply to the entire farm. The `wikiDomains` definition is required so that the security plugin knows what is required.
48+
49+
This example will work for a test server running on `localhost:3000`:
50+
```JSON
51+
{
52+
"admin": {"oauth2": "ID VALUE FROM OWNER.JSON FILE OF ADMIN"},
53+
"security_type": "passportjs",
54+
"oauth2_clientID": "CLIENT APPLICATION ID",
55+
"oauth2_clientSecret": "CLIENT APPLICATION SECRET",
56+
"oauth2_CallbackURL": "http://localhost:3000/auth/oauth2/callback",
57+
"oauth2_AuthorizationURL": "https://www.mediawiki.org/w/rest.php/oauth2/authorize",
58+
"oauth2_TokenURL": "https://www.mediawiki.org/w/rest.php/oauth2/access_token",
59+
"oauth2_UserInfoURL": "https://www.mediawiki.org/w/rest.php/oauth2/resource/profile",
60+
"oauth2_UseHeader": true,
61+
"oauth2_IdField": "profile.sub",
62+
"oauth2_DisplayNameField": "profile.realname",
63+
"oauth2_UsernameField": "profile.username",
64+
"wikiDomains": {
65+
"localhost": {}
66+
}
67+
}
68+
```
69+
70+
Note that Wikimedia wikis (the global user accounts on mediawiki.org)
71+
don't export "realname". If you are running against a local mediawiki
72+
instance you will need to update the `https://www.media.org/w/` prefix
73+
to match your local install.

docs/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ See, depending on which identity provider you choose to use:
1717
* [GitHub](./config-github.md)
1818
* [Google](./config-google.md)
1919
* [Twitter](./config-twitter.md)
20+
* [Wikimedia](./config-wikimedia.md)
2021
* [Generic OAuth](./config-oauth2.md)

server/social.coffee

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ https = require 'https'
1515
url = require 'url'
1616

1717
_ = require 'lodash'
18-
glob = require 'glob'
1918

2019
passport = require('passport')
2120

@@ -166,7 +165,8 @@ module.exports = exports = (log, loga, argv) ->
166165
OAuth2Strategy::userProfile = (accesstoken, done) ->
167166
console.log "hello"
168167
console.log accesstoken
169-
@_oauth2._request "GET", argv.oauth2_UserInfoURL, null, null, accesstoken, (err, data) ->
168+
@_oauth2.useAuthorizationHeaderforGET argv.oauth2_UseHeader?
169+
@_oauth2.get argv.oauth2_UserInfoURL, accesstoken, (err, data) ->
170170
if err
171171
return done err
172172
try

0 commit comments

Comments
 (0)