warden-openid 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +70 -3
- data/VERSION +1 -1
- data/examples/sinatra/.gitignore +1 -0
- data/examples/sinatra/Gemfile +6 -0
- data/examples/sinatra/Gemfile.lock +39 -0
- data/examples/sinatra/README +5 -0
- data/examples/sinatra/app.rb +84 -0
- data/examples/sinatra/config.ru +12 -0
- data/lib/warden/openid.rb +48 -5
- data/warden-openid.gemspec +69 -0
- metadata +23 -4
data/README.rdoc
CHANGED
@@ -1,9 +1,76 @@
|
|
1
|
-
=
|
1
|
+
= Warden OpenID Strategy
|
2
2
|
|
3
|
-
|
3
|
+
== Install
|
4
|
+
|
5
|
+
$ gem install warden-openid
|
6
|
+
|
7
|
+
== Usage
|
8
|
+
|
9
|
+
=== 1. Configure Warden uses OpenID strategy
|
10
|
+
|
11
|
+
require 'warden-openid'
|
12
|
+
|
13
|
+
use Rack::Session::Cookie
|
14
|
+
use Rack::OpenID
|
15
|
+
use Warden::Manager do |manager|
|
16
|
+
manager.default_strategies :openid
|
17
|
+
manager.failure_app = FailureApp
|
18
|
+
end
|
19
|
+
|
20
|
+
=== 2. Setup user finder
|
21
|
+
|
22
|
+
Warden::OpenID.configure do |config|
|
23
|
+
config.user_finder do |response|
|
24
|
+
User.find_by_identity_url(response.identity_url)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
_response_ is an instance of <tt>OpenID::Consumer::Response</tt>.
|
29
|
+
|
30
|
+
=== 3. Create route and view
|
31
|
+
|
32
|
+
Example by Sinatra and Haml:
|
33
|
+
|
34
|
+
post '/signin' do
|
35
|
+
authenticate!
|
36
|
+
end
|
37
|
+
|
38
|
+
%form(action='/signin' method='post')
|
39
|
+
%input(type='text' name='openid_identifier')
|
40
|
+
%input(type='submit' value='Sign in')
|
41
|
+
|
42
|
+
This strategy starts with _openid_identifier_ parameter.
|
43
|
+
|
44
|
+
You may need to customize <tt>/unauthenticated</tt> route. Please refer to examples directory for details.
|
45
|
+
|
46
|
+
== Fetch additional fields from server
|
47
|
+
|
48
|
+
Warden::OpenID.configure do |config|
|
49
|
+
config.required_fields = 'email'
|
50
|
+
config.optional_fields = %w(nickname fullname)
|
51
|
+
|
52
|
+
config.user_finder do |response|
|
53
|
+
fields = OpenID::SReg::Response.from_success_response(response)
|
54
|
+
p fields['email']
|
55
|
+
p fields['nickname']
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
== Caveats
|
60
|
+
|
61
|
+
If you use this with Rails, please don't use <tt>OpenID::Store::Memory</tt>. A problem occurs by class reloading in the development mode.
|
62
|
+
|
63
|
+
For example, <tt>OpenID::Store::Filesystem</tt> is used instead:
|
64
|
+
|
65
|
+
require 'openid/store/filesystem'
|
66
|
+
Rails.configuration.middleware.use Rack::OpenID, OpenID::Store::Filesystem.new(Rails.root + 'tmp/openid')
|
67
|
+
|
68
|
+
== Contributors
|
69
|
+
|
70
|
+
* Philip H. MacIver
|
4
71
|
|
5
72
|
== Note on Patches/Pull Requests
|
6
|
-
|
73
|
+
|
7
74
|
* Fork the project.
|
8
75
|
* Make your feature addition or bug fix.
|
9
76
|
* Add tests for it. This is important so I don't break it in a
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
@@ -0,0 +1 @@
|
|
1
|
+
.bundle/*
|
@@ -0,0 +1,39 @@
|
|
1
|
+
---
|
2
|
+
dependencies:
|
3
|
+
haml:
|
4
|
+
group:
|
5
|
+
- :default
|
6
|
+
version: ">= 0"
|
7
|
+
rack-flash:
|
8
|
+
group:
|
9
|
+
- :default
|
10
|
+
version: ">= 0"
|
11
|
+
warden-openid:
|
12
|
+
group:
|
13
|
+
- :default
|
14
|
+
version: ">= 0"
|
15
|
+
sinatra:
|
16
|
+
group:
|
17
|
+
- :default
|
18
|
+
version: ">= 0"
|
19
|
+
specs:
|
20
|
+
- haml:
|
21
|
+
version: 3.0.10
|
22
|
+
- rack:
|
23
|
+
version: 1.1.0
|
24
|
+
- rack-flash:
|
25
|
+
version: 0.1.1
|
26
|
+
- ruby-openid:
|
27
|
+
version: 2.1.7
|
28
|
+
- rack-openid:
|
29
|
+
version: 1.0.3
|
30
|
+
- sinatra:
|
31
|
+
version: "1.0"
|
32
|
+
- warden:
|
33
|
+
version: 0.10.7
|
34
|
+
- warden-openid:
|
35
|
+
version: 0.0.1
|
36
|
+
hash: a1205587e00609d6a930be402bdd2afbd252e0c0
|
37
|
+
sources:
|
38
|
+
- Rubygems:
|
39
|
+
uri: http://gemcutter.org
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
Bundler.setup
|
4
|
+
Bundler.require :default
|
5
|
+
|
6
|
+
users = {}
|
7
|
+
|
8
|
+
Warden::OpenID.configure do |config|
|
9
|
+
config.user_finder do |response|
|
10
|
+
users[response.identity_url]
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
helpers do
|
15
|
+
def warden
|
16
|
+
env['warden']
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
get '/' do
|
21
|
+
haml <<-'HAML'
|
22
|
+
%p#notice= flash[:notice]
|
23
|
+
%p#error= flash[:error]
|
24
|
+
|
25
|
+
- if warden.authenticated?
|
26
|
+
%p
|
27
|
+
Welcome #{warden.user}!
|
28
|
+
%a(href='/signout') Sign out
|
29
|
+
- else
|
30
|
+
%form(action='/signin' method='post')
|
31
|
+
%p
|
32
|
+
%label
|
33
|
+
OpenID:
|
34
|
+
%input(type='text' name='openid_identifier')
|
35
|
+
%input(type='submit' value='Sign in')
|
36
|
+
HAML
|
37
|
+
end
|
38
|
+
|
39
|
+
post '/signin' do
|
40
|
+
warden.authenticate!
|
41
|
+
flash[:notice] = 'You signed in'
|
42
|
+
redirect '/'
|
43
|
+
end
|
44
|
+
|
45
|
+
get '/signout' do
|
46
|
+
warden.logout(:default)
|
47
|
+
flash[:notice] = 'You signed out'
|
48
|
+
redirect '/'
|
49
|
+
end
|
50
|
+
|
51
|
+
post '/unauthenticated' do
|
52
|
+
if openid = env['warden.options'][:openid]
|
53
|
+
# OpenID authenticate success, but user is missing
|
54
|
+
# (Warden::OpenID.user_finder returns nil)
|
55
|
+
session[:identity_url] = openid[:response].identity_url
|
56
|
+
redirect '/register'
|
57
|
+
else
|
58
|
+
# OpenID authenticate failure
|
59
|
+
flash[:error] = warden.message
|
60
|
+
redirect '/'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
get '/register' do
|
65
|
+
haml <<-'HAML'
|
66
|
+
%form(action='/signup' method='post')
|
67
|
+
%p
|
68
|
+
%label
|
69
|
+
Name:
|
70
|
+
%input(type='text' name='name')
|
71
|
+
%input(type='submit' value='Sign up')
|
72
|
+
HAML
|
73
|
+
end
|
74
|
+
|
75
|
+
post '/signup' do
|
76
|
+
if (name = params[:name]).empty?
|
77
|
+
redirect '/register'
|
78
|
+
else
|
79
|
+
users[session.delete(:identity_url)] = name
|
80
|
+
warden.set_user name
|
81
|
+
flash[:notice] = 'You signed up'
|
82
|
+
redirect '/'
|
83
|
+
end
|
84
|
+
end
|
data/lib/warden/openid.rb
CHANGED
@@ -3,8 +3,51 @@ require 'rack/openid'
|
|
3
3
|
|
4
4
|
module Warden
|
5
5
|
module OpenID
|
6
|
-
|
7
|
-
|
6
|
+
CONFIG_EXAMPLE = <<-CODE
|
7
|
+
Warden::OpenID.configure do |config|
|
8
|
+
config.user_finder do |response|
|
9
|
+
# do something
|
10
|
+
end
|
11
|
+
end
|
12
|
+
CODE
|
13
|
+
|
14
|
+
class Config
|
15
|
+
attr_accessor :required_fields, :optional_fields, :policy_url
|
16
|
+
|
17
|
+
def user_finder(&block)
|
18
|
+
@user_finder = block
|
19
|
+
end
|
20
|
+
|
21
|
+
def find_user(response)
|
22
|
+
raise "Warden::OpenID::Config#user_finder has not been set yet.\n\n#{Warden::OpenID::CONFIG_EXAMPLE}" unless @user_finder
|
23
|
+
@user_finder.call(response)
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_params
|
27
|
+
{
|
28
|
+
:required => required_fields,
|
29
|
+
:optional => optional_fields,
|
30
|
+
:policy_url => policy_url
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class << self
|
36
|
+
def config
|
37
|
+
@@config ||= Config.new
|
38
|
+
end
|
39
|
+
|
40
|
+
def configure(&block)
|
41
|
+
block.call(config)
|
42
|
+
end
|
43
|
+
|
44
|
+
def user_finder(&block)
|
45
|
+
$stderr.puts "DEPRECATION WARNING: Warden::OpenID.user_finder is deprecated. Use Warden::OpenID::Config#user_finder instead.\n\n#{CONFIG_EXAMPLE}"
|
46
|
+
|
47
|
+
configure do |config|
|
48
|
+
config.user_finder(&block)
|
49
|
+
end
|
50
|
+
end
|
8
51
|
end
|
9
52
|
|
10
53
|
class Strategy < Warden::Strategies::Base
|
@@ -12,7 +55,7 @@ module Warden
|
|
12
55
|
if response = env[Rack::OpenID::RESPONSE]
|
13
56
|
case response.status
|
14
57
|
when :success
|
15
|
-
if user = Warden::OpenID.
|
58
|
+
if user = Warden::OpenID.config.find_user(response)
|
16
59
|
success!(user)
|
17
60
|
else
|
18
61
|
fail!('User not found')
|
@@ -22,10 +65,10 @@ module Warden
|
|
22
65
|
fail!(response.respond_to?(:message) ? response.message : "OpenID authentication failed: #{response.status}")
|
23
66
|
end
|
24
67
|
elsif identifier = params['openid_identifier']
|
25
|
-
if identifier.empty?
|
68
|
+
if identifier.nil? || identifier.empty?
|
26
69
|
fail!('OpenID identifier is required')
|
27
70
|
else
|
28
|
-
|
71
|
+
custom!([401, {'WWW-Authenticate' => Rack::OpenID.build_header(Warden::OpenID.config.to_params.merge(:identifier => identifier))}, ''])
|
29
72
|
end
|
30
73
|
end
|
31
74
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{warden-openid}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Keita Urashima"]
|
12
|
+
s.date = %q{2010-06-10}
|
13
|
+
s.description = %q{A warden strategy for authenticate with OpenID}
|
14
|
+
s.email = %q{ursm@ursm.jp}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"examples/sinatra/.gitignore",
|
27
|
+
"examples/sinatra/Gemfile",
|
28
|
+
"examples/sinatra/Gemfile.lock",
|
29
|
+
"examples/sinatra/README",
|
30
|
+
"examples/sinatra/app.rb",
|
31
|
+
"examples/sinatra/config.ru",
|
32
|
+
"lib/warden-openid.rb",
|
33
|
+
"lib/warden/openid.rb",
|
34
|
+
"spec/spec.opts",
|
35
|
+
"spec/spec_helper.rb",
|
36
|
+
"spec/warden-openid_spec.rb",
|
37
|
+
"warden-openid.gemspec"
|
38
|
+
]
|
39
|
+
s.homepage = %q{http://github.com/ursm/warden-openid}
|
40
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = %q{1.3.7}
|
43
|
+
s.summary = %q{A warden strategy for authenticate with OpenID}
|
44
|
+
s.test_files = [
|
45
|
+
"spec/spec_helper.rb",
|
46
|
+
"spec/warden-openid_spec.rb",
|
47
|
+
"examples/sinatra/app.rb"
|
48
|
+
]
|
49
|
+
|
50
|
+
if s.respond_to? :specification_version then
|
51
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
52
|
+
s.specification_version = 3
|
53
|
+
|
54
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
55
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
56
|
+
s.add_runtime_dependency(%q<warden>, [">= 0"])
|
57
|
+
s.add_runtime_dependency(%q<rack-openid>, [">= 0"])
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
60
|
+
s.add_dependency(%q<warden>, [">= 0"])
|
61
|
+
s.add_dependency(%q<rack-openid>, [">= 0"])
|
62
|
+
end
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
65
|
+
s.add_dependency(%q<warden>, [">= 0"])
|
66
|
+
s.add_dependency(%q<rack-openid>, [">= 0"])
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: warden-openid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
- 0
|
8
8
|
- 1
|
9
|
-
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Keita Urashima
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-06-10 00:00:00 +09:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: rspec
|
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: 13
|
27
30
|
segments:
|
28
31
|
- 1
|
29
32
|
- 2
|
@@ -35,9 +38,11 @@ dependencies:
|
|
35
38
|
name: warden
|
36
39
|
prerelease: false
|
37
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
38
42
|
requirements:
|
39
43
|
- - ">="
|
40
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 3
|
41
46
|
segments:
|
42
47
|
- 0
|
43
48
|
version: "0"
|
@@ -47,9 +52,11 @@ dependencies:
|
|
47
52
|
name: rack-openid
|
48
53
|
prerelease: false
|
49
54
|
requirement: &id003 !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
50
56
|
requirements:
|
51
57
|
- - ">="
|
52
58
|
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
53
60
|
segments:
|
54
61
|
- 0
|
55
62
|
version: "0"
|
@@ -71,11 +78,18 @@ files:
|
|
71
78
|
- README.rdoc
|
72
79
|
- Rakefile
|
73
80
|
- VERSION
|
81
|
+
- examples/sinatra/.gitignore
|
82
|
+
- examples/sinatra/Gemfile
|
83
|
+
- examples/sinatra/Gemfile.lock
|
84
|
+
- examples/sinatra/README
|
85
|
+
- examples/sinatra/app.rb
|
86
|
+
- examples/sinatra/config.ru
|
74
87
|
- lib/warden-openid.rb
|
75
88
|
- lib/warden/openid.rb
|
76
89
|
- spec/spec.opts
|
77
90
|
- spec/spec_helper.rb
|
78
91
|
- spec/warden-openid_spec.rb
|
92
|
+
- warden-openid.gemspec
|
79
93
|
has_rdoc: true
|
80
94
|
homepage: http://github.com/ursm/warden-openid
|
81
95
|
licenses: []
|
@@ -86,26 +100,31 @@ rdoc_options:
|
|
86
100
|
require_paths:
|
87
101
|
- lib
|
88
102
|
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
89
104
|
requirements:
|
90
105
|
- - ">="
|
91
106
|
- !ruby/object:Gem::Version
|
107
|
+
hash: 3
|
92
108
|
segments:
|
93
109
|
- 0
|
94
110
|
version: "0"
|
95
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
96
113
|
requirements:
|
97
114
|
- - ">="
|
98
115
|
- !ruby/object:Gem::Version
|
116
|
+
hash: 3
|
99
117
|
segments:
|
100
118
|
- 0
|
101
119
|
version: "0"
|
102
120
|
requirements: []
|
103
121
|
|
104
122
|
rubyforge_project:
|
105
|
-
rubygems_version: 1.3.
|
123
|
+
rubygems_version: 1.3.7
|
106
124
|
signing_key:
|
107
125
|
specification_version: 3
|
108
126
|
summary: A warden strategy for authenticate with OpenID
|
109
127
|
test_files:
|
110
128
|
- spec/spec_helper.rb
|
111
129
|
- spec/warden-openid_spec.rb
|
130
|
+
- examples/sinatra/app.rb
|