README.md in omniauth-mediawiki-0.0.2 vs README.md in omniauth-mediawiki-0.0.3
- old
+ new
@@ -23,17 +23,18 @@
provider :mediawiki, "consumer_key", "consumer_secret"
end
If you are using devise, this is how it looks like in your `config/initializers/devise.rb`:
- config.omniauth :mediawiki, "consumer_key", "consumer_secret", {:client_options => {:site => 'http://commons.wikimedia.org' }}
+ config.omniauth :mediawiki, "consumer_key", "consumer_secret",
+ {:client_options => {:site => 'https://commons.wikimedia.org' }}
You will obviously have to put in your key and secret, which you get when you register your app on your particula Wiki.
Now just follow the README at: https://github.com/intridea/omniauth
-## Info about the Medaiwiki OAuth extension
+## Info about the MediaWiki OAuth extension
In general see the pages around https://www.mediawiki.org/wiki/OAuth/For_Developers for more information
When registering for a new OAuth consumer registration you need to specify the callback url properly. e.g. for development:
@@ -46,13 +47,31 @@
:access_token_path => '/w/index.php?title=Special:OAuth/token',
:request_token_path => '/w/index.php?title=Special:OAuth/initiate',
This is a workaround as the paths should all be like the authorize path.
+Note also that new proposed registrations on mediawiki.org will work with your mediawki user that you registered the application with but have to be approved by an admin user for them to be useable by other users.
## Specifying Target Wiki
If you would like to use this plugin against a wiki you should pass this you can use the environment variable WIKI_AUTH_SITE to set the server to connect to. Alternatively you can pass the site as a client_option to the omniauth config:
- config.omniauth :mediawiki, "consumer_key", "consumer_secret", :client_options => {:site => 'http://commons.wikimedia.org' }
+ config.omniauth :mediawiki, "consumer_key", "consumer_secret",
+ :client_options => {:site => 'https://commons.wikimedia.org' }
if no site is specified the www.mediawiki.org wiki will be used.
+
+## How to call the MediaWiki API via Omniauth
+
+Within a Devise / Omniauth setup, in the callback method, you can directly get an OAuth::AccessToken via ```request.env["omniauth.auth"]["extra"]["access_token"]``` or you can get the token and secret from ```request.env["omniauth.auth"]["credentials"]["token"]``` and ```request.env["omniauth.auth"]["credentials"]["secret"]```
+
+Assuming these are stored in the user model, the following could be used to query the mediawiki API at a later date. In this example we are using the Wikimedia Commons API https://www.mediawiki.org/wiki/API:Main_page
+
+ @consumer = OAuth::Consumer.new "consumer_key", "consumer_secret",
+ {:site=>"https://commons.wikimedia.org"}
+ @access_token = OAuth::AccessToken.new(@consumer, user.auth_token, user.auth_secret)
+ uri = 'https://commons.wikimedia.org/w/api.php?action=query&meta=userinfo&uiprop=rights|editcount&format=json'
+ resp = @access_token.get(URI.encode(uri))
+ logger.debug resp.body.inspect
+ # {"query":{"userinfo":{"id":12345,"name":"WikiUser",
+ # "rights":["read","writeapi","purge","autoconfirmed","editsemiprotected","skipcaptcha"],
+ # "editcount":2323}}}