omniauth-mediawiki 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ 0.0.3
2
+ Added email to raw_info
3
+ Simplify mediawiki authentication code
4
+
5
+ 0.0.2
6
+ Initial Version
7
+
8
+
data/README.md CHANGED
@@ -25,13 +25,14 @@ Once these are in, you need to add the following to your `config/initializers/om
25
25
 
26
26
  If you are using devise, this is how it looks like in your `config/initializers/devise.rb`:
27
27
 
28
- config.omniauth :mediawiki, "consumer_key", "consumer_secret", {:client_options => {:site => 'http://commons.wikimedia.org' }}
28
+ config.omniauth :mediawiki, "consumer_key", "consumer_secret",
29
+ {:client_options => {:site => 'https://commons.wikimedia.org' }}
29
30
 
30
31
  You will obviously have to put in your key and secret, which you get when you register your app on your particula Wiki.
31
32
 
32
33
  Now just follow the README at: https://github.com/intridea/omniauth
33
34
 
34
- ## Info about the Medaiwiki OAuth extension
35
+ ## Info about the MediaWiki OAuth extension
35
36
 
36
37
  In general see the pages around https://www.mediawiki.org/wiki/OAuth/For_Developers for more information
37
38
 
@@ -48,11 +49,29 @@ Internally the strategy has to use `/w/index.php?title=` paths like so:
48
49
 
49
50
  This is a workaround as the paths should all be like the authorize path.
50
51
 
52
+ 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.
51
53
 
52
54
  ## Specifying Target Wiki
53
55
 
54
56
  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:
55
57
 
56
- config.omniauth :mediawiki, "consumer_key", "consumer_secret", :client_options => {:site => 'http://commons.wikimedia.org' }
58
+ config.omniauth :mediawiki, "consumer_key", "consumer_secret",
59
+ :client_options => {:site => 'https://commons.wikimedia.org' }
57
60
 
58
61
  if no site is specified the www.mediawiki.org wiki will be used.
62
+
63
+ ## How to call the MediaWiki API via Omniauth
64
+
65
+ 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"]```
66
+
67
+ 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
68
+
69
+ @consumer = OAuth::Consumer.new "consumer_key", "consumer_secret",
70
+ {:site=>"https://commons.wikimedia.org"}
71
+ @access_token = OAuth::AccessToken.new(@consumer, user.auth_token, user.auth_secret)
72
+ uri = 'https://commons.wikimedia.org/w/api.php?action=query&meta=userinfo&uiprop=rights|editcount&format=json'
73
+ resp = @access_token.get(URI.encode(uri))
74
+ logger.debug resp.body.inspect
75
+ # {"query":{"userinfo":{"id":12345,"name":"WikiUser",
76
+ # "rights":["read","writeapi","purge","autoconfirmed","editsemiprotected","skipcaptcha"],
77
+ # "editcount":2323}}}
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module Mediawiki
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -20,34 +20,9 @@ module OmniAuth
20
20
  :site => site,
21
21
  :authorize_path => '/wiki/Special:Oauth/authorize',
22
22
  :access_token_path => '/w/index.php?title=Special:OAuth/token',
23
- :request_token_path => '/w/index.php?title=Special:OAuth/initiate',
24
- :oauth_callback=> "oob"
23
+ :request_token_path => '/w/index.php?title=Special:OAuth/initiate'
25
24
  }
26
25
 
27
- def request_phase
28
- request_token = consumer.get_request_token(:oauth_callback => callback_url)
29
- session['oauth'] ||= {}
30
- session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
31
- r = Rack::Response.new
32
-
33
- if request_token.callback_confirmed?
34
- r.redirect(request_token.authorize_url(
35
- :oauth_consumer_key => consumer.key
36
- ))
37
- else
38
- r.redirect(request_token.authorize_url(
39
- :oauth_callback => callback_url,
40
- :oauth_consumer_key => consumer.key
41
- ))
42
- end
43
-
44
- r.finish
45
- end
46
-
47
- def callback_url
48
- 'oob'
49
- end
50
-
51
26
  # These are called after authentication has succeeded. If
52
27
  # possible, you should try to set the UID without making
53
28
  # additional calls (if the user id is returned with the token
@@ -58,6 +33,7 @@ module OmniAuth
58
33
  info do
59
34
  {
60
35
  :name => raw_info["username"],
36
+ :email => raw_info["email"],
61
37
  :urls => {"server" => raw_info["iss"]}
62
38
  }
63
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-mediawiki
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-08-23 00:00:00.000000000 Z
12
+ date: 2016-06-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: omniauth-oauth
@@ -165,6 +165,7 @@ files:
165
165
  - .rspec
166
166
  - .ruby-gemset
167
167
  - .ruby-version
168
+ - Changelog
168
169
  - Gemfile
169
170
  - LICENSE.md
170
171
  - README.md
@@ -189,18 +190,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
189
190
  - - ! '>='
190
191
  - !ruby/object:Gem::Version
191
192
  version: '0'
192
- segments:
193
- - 0
194
- hash: -4372388317667068380
195
193
  required_rubygems_version: !ruby/object:Gem::Requirement
196
194
  none: false
197
195
  requirements:
198
196
  - - ! '>='
199
197
  - !ruby/object:Gem::Version
200
198
  version: '0'
201
- segments:
202
- - 0
203
- hash: -4372388317667068380
204
199
  requirements: []
205
200
  rubyforge_project: omniauth-mediawiki
206
201
  rubygems_version: 1.8.25