open_id_authentication 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5cce1e8f0cba4a96a9e4956b3b5fb382d3213c8b
4
+ data.tar.gz: fb3ce670dd73d0f373f595a438b1e7b0d0f72fc8
5
+ SHA512:
6
+ metadata.gz: 842187004fe9a43cfed5ba12e244a44a96ba2b90d5656ba8061395c1dae5e900c7b283ead17448984365c8b0e07f4f268cd96ad8f98da07a3335bf28cb082995
7
+ data.tar.gz: 7ee055e647c265ab54e173c459dd9fd0b168f441cf610eae45127b9ab7e29ea491f95728912e998e3c926ea31e62c73700ca17f8f1c0719518fb6b642817920f
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+ gemspec
3
+
4
+ gem 'bump'
5
+ gem 'rake'
6
+ gem 'rspec', '~>2'
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ open_id_authentication (1.2.0)
5
+ rack-openid (~> 1.3)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ bump (0.4.2)
11
+ diff-lcs (1.2.4)
12
+ rack (1.5.2)
13
+ rack-openid (1.3.1)
14
+ rack (>= 1.1.0)
15
+ ruby-openid (>= 2.1.8)
16
+ rake (10.1.0)
17
+ rspec (2.14.1)
18
+ rspec-core (~> 2.14.0)
19
+ rspec-expectations (~> 2.14.0)
20
+ rspec-mocks (~> 2.14.0)
21
+ rspec-core (2.14.5)
22
+ rspec-expectations (2.14.2)
23
+ diff-lcs (>= 1.1.3, < 2.0)
24
+ rspec-mocks (2.14.3)
25
+ ruby-openid (2.3.0)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ bump
32
+ open_id_authentication!
33
+ rake
34
+ rspec (~> 2)
data/README.md CHANGED
@@ -1,9 +1,7 @@
1
1
  OpenIdAuthentication
2
2
  ====================
3
3
 
4
- Provides a thin wrapper around the excellent ruby-openid gem from JanRan. Be sure to install that first:
5
-
6
- gem install ruby-openid
4
+ Provides a thin wrapper around the excellent ruby-openid gem from JanRan.
7
5
 
8
6
  To understand what OpenID is about and how it works, it helps to read the documentation for lib/openid/consumer.rb
9
7
  from that gem.
@@ -219,24 +217,22 @@ Some OpenID providers also support the OpenID AX (attribute exchange) protocol f
219
217
  Accessing AX data is very similar to the Simple Registration process, described above -- just add the URI identifier for the AX field to your :optional or :required parameters. For example:
220
218
 
221
219
  authenticate_with_open_id(identity_url,
222
- :required => [ :email, 'http://schema.openid.net/birthDate' ]) do
220
+ :required => [ :email, 'http://schema.openid.net/birthDate' ]) do
223
221
  |result, identity_url, registration, ax|
224
222
 
225
223
  This would provide the sreg data for :email via registration, and the AX data for http://schema.openid.net/birthDate via ax.
226
224
 
227
- Contributing
228
- ------------
225
+ TODO
226
+ ----
227
+ - tests
229
228
 
230
- Please see the [contribution guidelines](http://github.com/Velir/open_id_authentication/blob/master/CONTRIBUTION_GUIDELINES.md).
231
229
 
232
230
  Credits
233
231
  -------
234
232
 
235
233
  open_id_authentication was written by David Heinemeier Hansson with a number of other [contributors](https://github.com/Velir/open_id_authentication/contributors).
236
234
 
237
- open_id_authentication maintenance is funded by [Velir](http://velir.com).
238
-
239
235
 
240
236
  License
241
237
  -------
242
- Copyright (c) 2007-2011 David Heinemeier Hansson, released under the MIT license
238
+ Copyright (c) 2007-2011 David Heinemeier Hansson, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/setup'
2
+ require 'bundler/gem_tasks'
3
+ require 'bump/tasks'
4
+
5
+ task :default do
6
+ sh "rspec spec/"
7
+ end
@@ -1,146 +1,19 @@
1
- require 'uri'
2
- require 'openid'
3
- require 'rack/openid'
1
+ require "open_id_authentication/version"
2
+ require "open_id_authentication/middleware"
3
+ require "open_id_authentication/controller_methods"
4
+ require "open_id_authentication/railtie" if defined?(::Rails::Railtie)
4
5
 
5
6
  module OpenIdAuthentication
6
- def self.new(app)
7
- store = OpenIdAuthentication.store
8
- if store.nil?
9
- Rails.logger.warn "OpenIdAuthentication.store is nil. Using in-memory store."
10
- end
11
-
12
- ::Rack::OpenID.new(app, OpenIdAuthentication.store)
7
+ # deprecated middleware creation
8
+ def self.new(*args)
9
+ raise "Use OpenIdAuthentication::Middleware"
13
10
  end
14
11
 
15
12
  def self.store
16
- @@store
17
- end
18
-
19
- def self.store=(*store_option)
20
- store, *parameters = *([ store_option ].flatten)
21
-
22
- @@store = case store
23
- when :memory
24
- require 'openid/store/memory'
25
- OpenID::Store::Memory.new
26
- when :file
27
- require 'openid/store/filesystem'
28
- OpenID::Store::Filesystem.new(Rails.root.join('tmp/openids'))
29
- when :memcache
30
- require 'memcache'
31
- require 'openid/store/memcache'
32
- OpenID::Store::Memcache.new(MemCache.new(parameters))
33
- else
34
- store
35
- end
36
- end
37
-
38
- self.store = nil
39
-
40
- if Rails.version >= '3'
41
- class Railtie < ::Rails::Railtie
42
- config.app_middleware.use OpenIdAuthentication
43
-
44
- config.after_initialize do
45
- OpenID::Util.logger = Rails.logger
46
- end
47
-
48
- ActiveSupport.on_load :action_controller do
49
- ActionController::Base.send :include, ControllerMethods
50
- #ActionController::Base.extend ControllerMethods
51
- end
52
- end
53
- end
54
-
55
- class Result
56
- ERROR_MESSAGES = {
57
- :missing => "Sorry, the OpenID server couldn't be found",
58
- :invalid => "Sorry, but this does not appear to be a valid OpenID",
59
- :canceled => "OpenID verification was canceled",
60
- :failed => "OpenID verification failed",
61
- :setup_needed => "OpenID verification needs setup"
62
- }
63
-
64
- def self.[](code)
65
- new(code)
66
- end
67
-
68
- def initialize(code)
69
- @code = code
70
- end
71
-
72
- def status
73
- @code
74
- end
75
-
76
- ERROR_MESSAGES.keys.each { |state| define_method("#{state}?") { @code == state } }
77
-
78
- def successful?
79
- @code == :successful
80
- end
81
-
82
- def unsuccessful?
83
- ERROR_MESSAGES.keys.include?(@code)
84
- end
85
-
86
- def message
87
- ERROR_MESSAGES[@code]
88
- end
13
+ Middleware.store
89
14
  end
90
15
 
91
- module ControllerMethods
92
- protected
93
- # The parameter name of "openid_identifier" is used rather than
94
- # the Rails convention "open_id_identifier" because that's what
95
- # the specification dictates in order to get browser auto-complete
96
- # working across sites
97
- def using_open_id?(identifier = nil) #:doc:
98
- identifier ||= open_id_identifier
99
- !identifier.blank? || request.env[Rack::OpenID::RESPONSE]
100
- end
101
-
102
- def authenticate_with_open_id(identifier = nil, options = {}, &block) #:doc:
103
- identifier ||= open_id_identifier
104
-
105
- if request.env[Rack::OpenID::RESPONSE]
106
- complete_open_id_authentication(&block)
107
- else
108
- begin_open_id_authentication(identifier, options, &block)
109
- end
110
- end
111
-
112
- private
113
- def open_id_identifier
114
- params[:openid_identifier] || params[:openid_url]
115
- end
116
-
117
- def begin_open_id_authentication(identifier, options = {})
118
- options[:identifier] = identifier
119
- value = Rack::OpenID.build_header(options)
120
- response.headers[Rack::OpenID::AUTHENTICATE_HEADER] = value
121
- head :unauthorized
122
- end
123
-
124
- def complete_open_id_authentication
125
- response = request.env[Rack::OpenID::RESPONSE]
126
- identifier = response.display_identifier
127
-
128
- case response.status
129
- when OpenID::Consumer::SUCCESS
130
- yield Result[:successful], identifier,
131
- OpenID::SReg::Response.from_success_response(response),
132
- OpenID::AX::FetchResponse.from_success_response(response)
133
- when :missing
134
- yield Result[:missing], identifier, nil
135
- when :invalid
136
- yield Result[:invalid], identifier, nil
137
- when OpenID::Consumer::CANCEL
138
- yield Result[:canceled], identifier, nil
139
- when OpenID::Consumer::FAILURE
140
- yield Result[:failed], identifier, nil
141
- when OpenID::Consumer::SETUP_NEEDED
142
- yield Result[:setup_needed], response.setup_url, nil
143
- end
144
- end
16
+ def self.store=(*args)
17
+ Middleware.store = *args
145
18
  end
146
19
  end
@@ -0,0 +1,61 @@
1
+ require "open_id_authentication/result"
2
+
3
+ module OpenIdAuthentication
4
+ module ControllerMethods
5
+ protected
6
+
7
+ # The parameter name of "openid_identifier" is used rather than
8
+ # the Rails convention "open_id_identifier" because that's what
9
+ # the specification dictates in order to get browser auto-complete
10
+ # working across sites
11
+ def using_open_id?(identifier = nil) #:doc:
12
+ identifier ||= open_id_identifier
13
+ !identifier.blank? || request.env[Rack::OpenID::RESPONSE]
14
+ end
15
+
16
+ def authenticate_with_open_id(identifier = nil, options = {}, &block) #:doc:
17
+ identifier ||= open_id_identifier
18
+
19
+ if request.env[Rack::OpenID::RESPONSE]
20
+ complete_open_id_authentication(&block)
21
+ else
22
+ begin_open_id_authentication(identifier, options, &block)
23
+ end
24
+ end
25
+
26
+ private
27
+
28
+ def open_id_identifier
29
+ params[:openid_identifier] || params[:openid_url]
30
+ end
31
+
32
+ def begin_open_id_authentication(identifier, options = {})
33
+ options[:identifier] = identifier
34
+ value = Rack::OpenID.build_header(options)
35
+ response.headers[Rack::OpenID::AUTHENTICATE_HEADER] = value
36
+ head :unauthorized
37
+ end
38
+
39
+ def complete_open_id_authentication
40
+ response = request.env[Rack::OpenID::RESPONSE]
41
+ identifier = response.display_identifier
42
+
43
+ case response.status
44
+ when OpenID::Consumer::SUCCESS
45
+ yield Result[:successful], identifier,
46
+ OpenID::SReg::Response.from_success_response(response),
47
+ OpenID::AX::FetchResponse.from_success_response(response)
48
+ when :missing
49
+ yield Result[:missing], identifier, nil
50
+ when :invalid
51
+ yield Result[:invalid], identifier, nil
52
+ when OpenID::Consumer::CANCEL
53
+ yield Result[:canceled], identifier, nil
54
+ when OpenID::Consumer::FAILURE
55
+ yield Result[:failed], identifier, nil
56
+ when OpenID::Consumer::SETUP_NEEDED
57
+ yield Result[:setup_needed], response.setup_url, nil
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,41 @@
1
+ require 'uri'
2
+ require 'openid'
3
+ require 'rack/openid'
4
+
5
+ module OpenIdAuthentication
6
+ class Middleware
7
+ # middleware creation
8
+ def self.new(app)
9
+ if store.nil?
10
+ Rails.logger.warn "OpenIdAuthentication.store is nil. Using in-memory store."
11
+ end
12
+
13
+ ::Rack::OpenID.new(app, store)
14
+ end
15
+
16
+ def self.store
17
+ @@store
18
+ end
19
+
20
+ def self.store=(*store_option)
21
+ store, *args = *([ store_option ].flatten)
22
+
23
+ @@store = case store
24
+ when :memory
25
+ require 'openid/store/memory'
26
+ OpenID::Store::Memory.new
27
+ when :file
28
+ require 'openid/store/filesystem'
29
+ OpenID::Store::Filesystem.new(Rails.root.join('tmp/openids'))
30
+ when :memcache
31
+ require 'memcache'
32
+ require 'openid/store/memcache'
33
+ OpenID::Store::Memcache.new(MemCache.new(args))
34
+ else
35
+ store
36
+ end
37
+ end
38
+
39
+ self.store = nil
40
+ end
41
+ end
@@ -0,0 +1,13 @@
1
+ module OpenIdAuthentication
2
+ class Railtie < ::Rails::Railtie
3
+ config.app_middleware.use OpenIdAuthentication::Middleware
4
+
5
+ config.after_initialize do
6
+ OpenID::Util.logger = Rails.logger
7
+ end
8
+
9
+ ActiveSupport.on_load :action_controller do
10
+ ActionController::Base.send :include, ControllerMethods
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,37 @@
1
+ module OpenIdAuthentication
2
+ class Result
3
+ ERROR_MESSAGES = {
4
+ :missing => "Sorry, the OpenID server couldn't be found",
5
+ :invalid => "Sorry, but this does not appear to be a valid OpenID",
6
+ :canceled => "OpenID verification was canceled",
7
+ :failed => "OpenID verification failed",
8
+ :setup_needed => "OpenID verification needs setup"
9
+ }
10
+
11
+ def self.[](code)
12
+ new(code)
13
+ end
14
+
15
+ def initialize(code)
16
+ @code = code
17
+ end
18
+
19
+ def status
20
+ @code
21
+ end
22
+
23
+ ERROR_MESSAGES.keys.each { |state| define_method("#{state}?") { @code == state } }
24
+
25
+ def successful?
26
+ @code == :successful
27
+ end
28
+
29
+ def unsuccessful?
30
+ ERROR_MESSAGES.keys.include?(@code)
31
+ end
32
+
33
+ def message
34
+ ERROR_MESSAGES[@code]
35
+ end
36
+ end
37
+ end
@@ -1,4 +1,4 @@
1
1
  module OpenIdAuthentication
2
- VERSION = "1.1.0"
2
+ VERSION = "1.2.0"
3
3
  end
4
4
 
@@ -0,0 +1,18 @@
1
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
2
+ name = "open_id_authentication"
3
+ require "#{name}/version"
4
+
5
+ Gem::Specification.new name, OpenIdAuthentication::VERSION do |s|
6
+ s.summary = "open_id_authentication provides a thin wrapper around the excellent rack-openid gem."
7
+ s.authors = ["Patrick Robertson", "Michael Grosser"]
8
+ s.email = "michael@grosser.it"
9
+ s.homepage = "https://github.com/grosser/#{name}"
10
+ s.files = `git ls-files`.split("\n")
11
+ s.license = "MIT"
12
+ key = File.expand_path("~/.ssh/gem-private_key.pem")
13
+ if File.exist?(key)
14
+ s.signing_key = key
15
+ s.cert_chain = ["gem-public_cert.pem"]
16
+ end
17
+ s.add_runtime_dependency "rack-openid", "~> 1.3"
18
+ end
@@ -0,0 +1,17 @@
1
+ require 'spec_helper'
2
+
3
+ describe OpenIdAuthentication do
4
+ before do
5
+ OpenIdAuthentication.store = :memory
6
+ end
7
+
8
+ it "has a version" do
9
+ OpenIdAuthentication::VERSION.should =~ /^\d+\.\d+\.\d+$/
10
+ end
11
+
12
+ describe ".new" do
13
+ it "creates a Rack::OpenID" do
14
+ OpenIdAuthentication::Middleware.new({}).class.should == Rack::OpenID
15
+ end
16
+ end
17
+ end
@@ -0,0 +1 @@
1
+ require 'open_id_authentication'
metadata CHANGED
@@ -1,87 +1,73 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: open_id_authentication
3
- version: !ruby/object:Gem::Version
4
- hash: 19
5
- prerelease: false
6
- segments:
7
- - 1
8
- - 1
9
- - 0
10
- version: 1.1.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Patrick Robertson
8
+ - Michael Grosser
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-09-18 00:00:00 -04:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2013-09-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rack-openid
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
27
18
  - - ~>
28
- - !ruby/object:Gem::Version
29
- hash: 9
30
- segments:
31
- - 1
32
- - 3
33
- version: "1.3"
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
34
21
  type: :runtime
35
- version_requirements: *id001
36
- description: |-
37
- open_id_authentication provides a thin wrapper around the excellent rack-openid
38
- gem.
39
- email: patrick.robertson@velir.com
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.3'
28
+ description:
29
+ email: michael@grosser.it
40
30
  executables: []
41
-
42
31
  extensions: []
43
-
44
32
  extra_rdoc_files: []
45
-
46
- files:
47
- - CHANGELOG
48
- - CONTRIBUTION_GUIDELINES.md
33
+ files:
34
+ - .gitignore
35
+ - Gemfile
36
+ - Gemfile.lock
49
37
  - README.md
50
- - lib/open_id_authentication/version.rb
38
+ - Rakefile
51
39
  - lib/open_id_authentication.rb
52
- has_rdoc: true
53
- homepage: https://github.com/Velir/open_id_authentication
54
- licenses: []
55
-
40
+ - lib/open_id_authentication/controller_methods.rb
41
+ - lib/open_id_authentication/middleware.rb
42
+ - lib/open_id_authentication/railtie.rb
43
+ - lib/open_id_authentication/result.rb
44
+ - lib/open_id_authentication/version.rb
45
+ - open_id_authentication.gemspec
46
+ - spec/open_id_authentication_spec.rb
47
+ - spec/spec_helper.rb
48
+ homepage: https://github.com/grosser/open_id_authentication
49
+ licenses:
50
+ - MIT
51
+ metadata: {}
56
52
  post_install_message:
57
53
  rdoc_options: []
58
-
59
- require_paths:
54
+ require_paths:
60
55
  - lib
61
- required_ruby_version: !ruby/object:Gem::Requirement
62
- none: false
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- hash: 3
67
- segments:
68
- - 0
69
- version: "0"
70
- required_rubygems_version: !ruby/object:Gem::Requirement
71
- none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 3
76
- segments:
77
- - 0
78
- version: "0"
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
79
66
  requirements: []
80
-
81
67
  rubyforge_project:
82
- rubygems_version: 1.3.7
68
+ rubygems_version: 2.0.6
83
69
  signing_key:
84
- specification_version: 3
85
- summary: open_id_authentication provides a thin wrapper around the excellent rack-openid gem.
70
+ specification_version: 4
71
+ summary: open_id_authentication provides a thin wrapper around the excellent rack-openid
72
+ gem.
86
73
  test_files: []
87
-
data/CHANGELOG DELETED
@@ -1,37 +0,0 @@
1
- * Dump heavy lifting off to rack-openid gem. OpenIdAuthentication is just a simple controller concern.
2
-
3
- * Fake HTTP method from OpenID server since they only support a GET. Eliminates the need to set an extra route to match the server's reply. [Josh Peek]
4
-
5
- * OpenID 2.0 recommends that forms should use the field name "openid_identifier" rather than "openid_url" [Josh Peek]
6
-
7
- * Return open_id_response.display_identifier to the application instead of .endpoints.claimed_id. [nbibler]
8
-
9
- * Add Timeout protection [Rick]
10
-
11
- * An invalid identity url passed through authenticate_with_open_id will no longer raise an InvalidOpenId exception. Instead it will return Result[:missing] to the completion block.
12
-
13
- * Allow a return_to option to be used instead of the requested url [Josh Peek]
14
-
15
- * Updated plugin to use Ruby OpenID 2.x.x [Josh Peek]
16
-
17
- * Tied plugin to ruby-openid 1.1.4 gem until we can make it compatible with 2.x [DHH]
18
-
19
- * Use URI instead of regexps to normalize the URL and gain free, better matching #8136 [dkubb]
20
-
21
- * Allow -'s in #normalize_url [Rick]
22
-
23
- * remove instance of mattr_accessor, it was breaking tests since they don't load ActiveSupport. Fix Timeout test [Rick]
24
-
25
- * Throw a InvalidOpenId exception instead of just a RuntimeError when the URL can't be normalized [DHH]
26
-
27
- * Just use the path for the return URL, so extra query parameters don't interfere [DHH]
28
-
29
- * Added a new default database-backed store after experiencing trouble with the filestore on NFS. The file store is still available as an option [DHH]
30
-
31
- * Added normalize_url and applied it to all operations going through the plugin [DHH]
32
-
33
- * Removed open_id? as the idea of using the same input box for both OpenID and username has died -- use using_open_id? instead (which checks for the presence of params[:openid_url] by default) [DHH]
34
-
35
- * Added OpenIdAuthentication::Result to make it easier to deal with default situations where you don't care to do something particular for each error state [DHH]
36
-
37
- * Stop relying on root_url being defined, we can just grab the current url instead [DHH]
@@ -1,8 +0,0 @@
1
- Contributing to open_id_authentication:
2
-
3
- 1. Fork the [official repository](http://github.com/Velir/open_id_authentication/tree/master).
4
- 2. Make your changes in a topic branch.
5
- 3. Send a pull request.
6
-
7
- Notes:
8
- * Please don't update the Gem version.