omniauth-mediawiki 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,41 @@
1
+ *.gem
2
+ *.rbc
3
+ *.sw[a-p]
4
+ *.tmproj
5
+ *.tmproject
6
+ *.un~
7
+ *~
8
+ .DS_Store
9
+ .Spotlight-V100
10
+ .Trashes
11
+ ._*
12
+ .bundle
13
+ bundle
14
+ .config
15
+ .directory
16
+ .elc
17
+ .emacs.desktop
18
+ .emacs.desktop.lock
19
+ .redcar
20
+ .yardoc
21
+ Desktop.ini
22
+ Gemfile.lock
23
+ Icon?
24
+ InstalledFiles
25
+ Session.vim
26
+ Thumbs.db
27
+ \#*\#
28
+ _yardoc
29
+ auto-save-list
30
+ coverage
31
+ doc
32
+ lib/bundler/man
33
+ pkg
34
+ pkg/*
35
+ rdoc
36
+ spec/reports
37
+ test/tmp
38
+ test/version_tmp
39
+ tmp
40
+ tmtags
41
+ tramp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
@@ -0,0 +1 @@
1
+ omniauth-mediawiki
@@ -0,0 +1 @@
1
+ 1.9.3-p547
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - 1.9.2
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - 2.1.0
6
+ notifications:
7
+ email:
8
+ - info@christophbuente.de
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,10 @@
1
+ The MIT License (MIT)
2
+
3
+ (Based on openstreetmap strategy by Copyright (c) 2011 Christoph Bünte)
4
+ Copyright (c) 2011 Tim Waters
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
7
+
8
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ # OmniAuth Mediawiki
2
+
3
+
4
+ This gem contains the MediaWiki strategy for OmniAuth.
5
+
6
+ MediaWiki uses the OAuth 1.0a extension, you can read about it here: https://www.mediawiki.org/wiki/Extension:OAuth
7
+
8
+ ## How To Use It
9
+
10
+ Usage is as per any other OmniAuth 1.0 strategy. So let's say you're using Rails, you need to add the strategy to your `Gemfile` along side omniauth:
11
+
12
+ gem 'omniauth'
13
+ gem 'omniauth-mediawiki'
14
+
15
+ Of course if one or both of these are unreleased, you may have to pull them in directly from github e.g.:
16
+
17
+ gem 'omniauth', :git => 'https://github.com/intridea/omniauth.git'
18
+ gem 'omniauth-mediawiki', :git => 'https://github.com/timwaters/omniauth-mediawiki.git'
19
+
20
+ Once these are in, you need to add the following to your `config/initializers/omniauth.rb`:
21
+
22
+ Rails.application.config.middleware.use OmniAuth::Builder do
23
+ provider :mediawiki, "consumer_key", "consumer_secret"
24
+ end
25
+
26
+ If you are using devise, this is how it looks like in your `config/initializers/devise.rb`:
27
+
28
+ config.omniauth :mediawiki, "consumer_key", "consumer_secret", {:client_options => {:site => 'http://commons.wikimedia.org' }}
29
+
30
+ 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
+ Now just follow the README at: https://github.com/intridea/omniauth
33
+
34
+ ## Info about the Medaiwiki OAuth extension
35
+
36
+ In general see the pages around https://www.mediawiki.org/wiki/OAuth/For_Developers for more information
37
+
38
+ When registering for a new OAuth consumer registration you need to specify the callback url properly. e.g. for development:
39
+
40
+ http://localhost:3000/u/auth/mediawiki/callback
41
+ http://localhost:3000/users/auth/mediawiki/callback
42
+
43
+ Internally the strategy has to use `/w/index.php?title=` paths like so:
44
+
45
+ :authorize_path => '/wiki/Special:Oauth/authorize',
46
+ :access_token_path => '/w/index.php?title=Special:OAuth/token',
47
+ :request_token_path => '/w/index.php?title=Special:OAuth/initiate',
48
+
49
+ This is a workaround as the paths should all be like the authorize path.
50
+
51
+
52
+ ## Specifying Target Wiki
53
+
54
+ 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
+
56
+ config.omniauth :mediawiki, "consumer_key", "consumer_secret", :client_options => {:site => 'http://commons.wikimedia.org' }
57
+
58
+ if no site is specified the www.mediawiki.org wiki will be used.
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc 'Default: run specs.'
5
+ task :default => :spec
6
+
7
+ desc "Run specs"
8
+ RSpec::Core::RakeTask.new
9
+
10
+ desc 'Run specs'
11
+ task :default => :spec
@@ -0,0 +1,2 @@
1
+ require "omniauth-mediawiki/version"
2
+ require 'omniauth/strategies/mediawiki'
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Mediawiki
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,89 @@
1
+ require 'omniauth-oauth'
2
+ require 'rexml/document'
3
+ require 'jwt'
4
+
5
+ module OmniAuth
6
+ module Strategies
7
+ class Mediawiki < OmniAuth::Strategies::OAuth
8
+ option :name, "mediawiki"
9
+
10
+ def self.site
11
+ if ENV['WIKI_AUTH_SITE']
12
+ ENV['WIKI_AUTH_SITE']
13
+ else
14
+ "https://www.mediawiki.org"
15
+ end
16
+ end
17
+
18
+
19
+ option :client_options, {
20
+ :site => site,
21
+ :authorize_path => '/wiki/Special:Oauth/authorize',
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"
25
+ }
26
+
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
+ # These are called after authentication has succeeded. If
52
+ # possible, you should try to set the UID without making
53
+ # additional calls (if the user id is returned with the token
54
+ # or as a URI parameter). This may not be possible with all
55
+ # providers.
56
+ uid{ raw_info["sub"] }
57
+
58
+ info do
59
+ {
60
+ :name => raw_info["username"],
61
+ :urls => {"server" => raw_info["iss"]}
62
+ }
63
+ end
64
+
65
+ extra do
66
+ {
67
+ 'raw_info' => raw_info
68
+ }
69
+ end
70
+
71
+
72
+ def raw_info
73
+ @raw_info ||= parse_info(access_token.get('/w/index.php?title=Special:OAuth/identify'))
74
+
75
+ @raw_info
76
+ end
77
+
78
+ private
79
+
80
+ def parse_info(jwt_data)
81
+ ident = jwt_data.body
82
+ payload, header = JWT.decode(ident, consumer.secret)
83
+
84
+ payload
85
+ end
86
+
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omniauth-mediawiki/version"
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = 'omniauth-mediawiki'
7
+ gem.version = OmniAuth::Mediawiki::VERSION
8
+ gem.authors = ["Tim Waters"]
9
+ gem.email = 'tim@geothings.net'
10
+ gem.homepage = 'https://github.com/timwaters/omniauth-mediawiki'
11
+ gem.description = %q{Mediawiki strategy for OmniAuth 1.0a}
12
+ gem.summary = %q{Mediawiki strategy for OmniAuth 1.0a}
13
+ gem.license = 'MIT'
14
+
15
+ gem.rubyforge_project = "omniauth-mediawiki"
16
+
17
+ gem.files = `git ls-files`.split("\n")
18
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
20
+ gem.require_paths = ['lib']
21
+
22
+ gem.add_runtime_dependency "omniauth-oauth", "~> 1.0"
23
+ gem.add_runtime_dependency "jwt", "~> 1.0"
24
+
25
+ gem.add_development_dependency 'rake', '~> 0.9'
26
+ gem.add_development_dependency 'rspec', '~> 2.7'
27
+ gem.add_development_dependency 'simplecov', '~> 0.5'
28
+ gem.add_development_dependency 'webmock', '~> 1.7'
29
+ gem.add_development_dependency 'coveralls'
30
+ gem.add_development_dependency 'rack-test'
31
+ gem.add_development_dependency 'sinatra'
32
+ end
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'OmniAuth::Strategies::Mediawiki Integration' do
4
+ pending 'write some tests yo'
5
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Mediawiki do
4
+ subject do
5
+ OmniAuth::Strategies::Mediawiki.new({})
6
+ end
7
+
8
+ context 'client options' do
9
+ it 'should have correct name' do
10
+ expect(subject.options.name).to eq('mediawiki')
11
+ end
12
+
13
+ it 'should have correct site' do
14
+ expect(subject.options.client_options.site).to eq('https://www.mediawiki.org')
15
+ end
16
+
17
+ it 'should have correct authorize url' do
18
+ expect(subject.options.client_options.authorize_path).to eq('/wiki/Special:Oauth/authorize')
19
+ end
20
+
21
+ it 'should have correct access token url' do
22
+ expect(subject.options.client_options.access_token_path).to eq('/w/index.php?title=Special:OAuth/token')
23
+ end
24
+
25
+ it 'should have correct request token url' do
26
+ expect(subject.options.client_options.request_token_path).to eq('/w/index.php?title=Special:OAuth/initiate')
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,15 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'rspec'
6
+ require 'rack/test'
7
+ require 'webmock/rspec'
8
+ require 'omniauth'
9
+ require 'omniauth-mediawiki'
10
+
11
+ RSpec.configure do |config|
12
+ config.include WebMock::API
13
+ config.include Rack::Test::Methods
14
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
15
+ end
metadata ADDED
@@ -0,0 +1,211 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-mediawiki
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Tim Waters
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-08-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth-oauth
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: jwt
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '0.9'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.9'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '2.7'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2.7'
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '0.5'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '0.5'
94
+ - !ruby/object:Gem::Dependency
95
+ name: webmock
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: '1.7'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: '1.7'
110
+ - !ruby/object:Gem::Dependency
111
+ name: coveralls
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rack-test
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: sinatra
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ description: Mediawiki strategy for OmniAuth 1.0a
159
+ email: tim@geothings.net
160
+ executables: []
161
+ extensions: []
162
+ extra_rdoc_files: []
163
+ files:
164
+ - .gitignore
165
+ - .rspec
166
+ - .ruby-gemset
167
+ - .ruby-version
168
+ - .travis.yml
169
+ - Gemfile
170
+ - LICENSE.md
171
+ - README.md
172
+ - Rakefile
173
+ - lib/omniauth-mediawiki.rb
174
+ - lib/omniauth-mediawiki/version.rb
175
+ - lib/omniauth/strategies/mediawiki.rb
176
+ - omniauth-mediawiki.gemspec
177
+ - spec/integration.spec
178
+ - spec/omniauth/strategies/mediawiki_spec.rb
179
+ - spec/spec_helper.rb
180
+ homepage: https://github.com/timwaters/omniauth-mediawiki
181
+ licenses:
182
+ - MIT
183
+ post_install_message:
184
+ rdoc_options: []
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ none: false
189
+ requirements:
190
+ - - ! '>='
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ segments:
194
+ - 0
195
+ hash: 4338702317791494363
196
+ required_rubygems_version: !ruby/object:Gem::Requirement
197
+ none: false
198
+ requirements:
199
+ - - ! '>='
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ segments:
203
+ - 0
204
+ hash: 4338702317791494363
205
+ requirements: []
206
+ rubyforge_project: omniauth-mediawiki
207
+ rubygems_version: 1.8.25
208
+ signing_key:
209
+ specification_version: 3
210
+ summary: Mediawiki strategy for OmniAuth 1.0a
211
+ test_files: []