rack-openid 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/rack/openid.rb +3 -4
- data/lib/rack/openid/simple_auth.rb +67 -0
- metadata +17 -7
data/lib/rack/openid.rb
CHANGED
@@ -65,9 +65,9 @@ module Rack #:nodoc:
|
|
65
65
|
|
66
66
|
HTTP_METHODS = %w(GET HEAD PUT POST DELETE OPTIONS)
|
67
67
|
|
68
|
-
RESPONSE = "rack.openid.response"
|
69
|
-
AUTHENTICATE_HEADER = "WWW-Authenticate"
|
70
|
-
AUTHENTICATE_REGEXP = /^OpenID
|
68
|
+
RESPONSE = "rack.openid.response"
|
69
|
+
AUTHENTICATE_HEADER = "WWW-Authenticate"
|
70
|
+
AUTHENTICATE_REGEXP = /^OpenID/
|
71
71
|
|
72
72
|
URL_FIELD_SELECTOR = lambda { |field| field.to_s =~ %r{^https?://} }
|
73
73
|
|
@@ -84,7 +84,6 @@ module Rack #:nodoc:
|
|
84
84
|
def initialize(app, store = nil)
|
85
85
|
@app = app
|
86
86
|
@store = store || default_store
|
87
|
-
freeze
|
88
87
|
end
|
89
88
|
|
90
89
|
# Standard Rack +call+ dispatch that accepts an +env+ and
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'rack/openid'
|
2
|
+
|
3
|
+
module Rack #:nodoc:
|
4
|
+
class OpenID
|
5
|
+
# A simple OpenID middleware that restricts access to
|
6
|
+
# a single identifier.
|
7
|
+
#
|
8
|
+
# use Rack::OpenID::SimpleAuth, "http://example.org"
|
9
|
+
#
|
10
|
+
# SimpleAuth will automatically insert the required Rack::OpenID
|
11
|
+
# middleware, so <tt>use Rack::OpenID</tt> is unnecessary.
|
12
|
+
class SimpleAuth
|
13
|
+
def self.new(*args)
|
14
|
+
Rack::OpenID.new(super)
|
15
|
+
end
|
16
|
+
|
17
|
+
attr_reader :app, :identifier
|
18
|
+
|
19
|
+
def initialize(app, identifier)
|
20
|
+
@app = app
|
21
|
+
@identifier = identifier
|
22
|
+
end
|
23
|
+
|
24
|
+
def call(env)
|
25
|
+
if session_authenticated?(env)
|
26
|
+
app.call(env)
|
27
|
+
elsif successful_response?(env)
|
28
|
+
authenticate_session(env)
|
29
|
+
app.call(env)
|
30
|
+
else
|
31
|
+
authentication_request
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def session(env)
|
37
|
+
env['rack.session'] || raise_session_error
|
38
|
+
end
|
39
|
+
|
40
|
+
def raise_session_error
|
41
|
+
raise RuntimeError, 'Rack::OpenID::SimpleAuth requires a session'
|
42
|
+
end
|
43
|
+
|
44
|
+
def session_authenticated?(env)
|
45
|
+
session(env)['authenticated'] == true
|
46
|
+
end
|
47
|
+
|
48
|
+
def authenticate_session(env)
|
49
|
+
session(env)['authenticated'] = true
|
50
|
+
end
|
51
|
+
|
52
|
+
def successful_response?(env)
|
53
|
+
if resp = env[OpenID::RESPONSE]
|
54
|
+
resp.status == :success && resp.display_identifier == identifier
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def authentication_request
|
59
|
+
[401, { OpenID::AUTHENTICATE_HEADER => www_authenticate_header }, []]
|
60
|
+
end
|
61
|
+
|
62
|
+
def www_authenticate_header
|
63
|
+
OpenID.build_header(:identifier => identifier)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-openid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 1
|
8
|
+
- 1
|
7
9
|
- 0
|
8
|
-
|
9
|
-
version: 1.0.3
|
10
|
+
version: 1.1.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Joshua Peek
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-07-24 00:00:00 -05:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: rack
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
27
30
|
segments:
|
28
31
|
- 0
|
29
32
|
- 4
|
@@ -34,14 +37,16 @@ dependencies:
|
|
34
37
|
name: ruby-openid
|
35
38
|
prerelease: false
|
36
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
37
41
|
requirements:
|
38
42
|
- - ">="
|
39
43
|
- !ruby/object:Gem::Version
|
44
|
+
hash: 9
|
40
45
|
segments:
|
41
46
|
- 2
|
42
|
-
-
|
43
|
-
-
|
44
|
-
version: 2.
|
47
|
+
- 0
|
48
|
+
- 3
|
49
|
+
version: 2.0.3
|
45
50
|
type: :runtime
|
46
51
|
version_requirements: *id002
|
47
52
|
description: Provides a more HTTPish API around the ruby-openid library
|
@@ -55,6 +60,7 @@ extra_rdoc_files:
|
|
55
60
|
- README.rdoc
|
56
61
|
files:
|
57
62
|
- lib/rack/openid.rb
|
63
|
+
- lib/rack/openid/simple_auth.rb
|
58
64
|
has_rdoc: true
|
59
65
|
homepage: http://github.com/josh/rack-openid
|
60
66
|
licenses: []
|
@@ -65,23 +71,27 @@ rdoc_options: []
|
|
65
71
|
require_paths:
|
66
72
|
- lib
|
67
73
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
68
75
|
requirements:
|
69
76
|
- - ">="
|
70
77
|
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
71
79
|
segments:
|
72
80
|
- 0
|
73
81
|
version: "0"
|
74
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
75
84
|
requirements:
|
76
85
|
- - ">="
|
77
86
|
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
78
88
|
segments:
|
79
89
|
- 0
|
80
90
|
version: "0"
|
81
91
|
requirements: []
|
82
92
|
|
83
93
|
rubyforge_project:
|
84
|
-
rubygems_version: 1.3.
|
94
|
+
rubygems_version: 1.3.7
|
85
95
|
signing_key:
|
86
96
|
specification_version: 3
|
87
97
|
summary: Provides a more HTTPish API around the ruby-openid library
|