hobo_openid 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/CREDITS +8 -0
- data/LICENSE.txt +22 -0
- data/README.markdown +101 -0
- data/Rakefile +55 -0
- data/VERSION +1 -0
- data/lib/hobo_openid.rb +35 -0
- data/lib/openid_controller.rb +163 -0
- metadata +104 -0
data/.gitignore
ADDED
data/CREDITS
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
OpenID Authentication for Hobo
|
2
|
+
CREDITS
|
3
|
+
|
4
|
+
V1 by TheOtherShoe (Jesse Hallett), posted 10/22/2007 to hobocentral.net
|
5
|
+
available at http://sitr.us/openid_authentication_for_hobo.tar.gz
|
6
|
+
|
7
|
+
V2 by mdj42 (Matt Jones), rewritten 6/7/2008
|
8
|
+
contact: al2o3cr@gmail.com for questions / comments / bugs / etc.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2007 Jesse Hallett
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
OpenID Authentication for Hobo (VERSION 3)
|
2
|
+
==========================================
|
3
|
+
|
4
|
+
This plugin provides support for OpenID login. You can add OpenID login as
|
5
|
+
alternative login and registering method (and still allow login using
|
6
|
+
email + password).
|
7
|
+
|
8
|
+
Installing
|
9
|
+
===========
|
10
|
+
|
11
|
+
- Install Hobo gem
|
12
|
+
- Install the ruby-openid and ruby-yadis gems.
|
13
|
+
- Unpack the plugin in your vendor/plugins directory.
|
14
|
+
|
15
|
+
|
16
|
+
Setting up
|
17
|
+
==========
|
18
|
+
|
19
|
+
This plugin works basically the same way authenticated user support
|
20
|
+
works in Hobo. There are just a couple of extra things you will need
|
21
|
+
to set up. Here is the process in its entirety:
|
22
|
+
|
23
|
+
|
24
|
+
Modify user model
|
25
|
+
-------------------
|
26
|
+
|
27
|
+
The default hobo command now creates the User model - change User
|
28
|
+
as appropriate if you call it something else.
|
29
|
+
|
30
|
+
Open app/models/user.rb and add
|
31
|
+
|
32
|
+
openid :string
|
33
|
+
|
34
|
+
field.
|
35
|
+
|
36
|
+
Modify users controller
|
37
|
+
-------------------------
|
38
|
+
|
39
|
+
Open app/controllers/users_controller.rb and add follwing line to the controller class:
|
40
|
+
|
41
|
+
openid_login({ :openid_opts => { :model => User } })
|
42
|
+
|
43
|
+
|
44
|
+
Create OpenID login page
|
45
|
+
------------------------
|
46
|
+
|
47
|
+
Create app/views/users/openid_login.dryml with following content:
|
48
|
+
|
49
|
+
<login-page>
|
50
|
+
<form:>
|
51
|
+
<labelled-item-list>
|
52
|
+
<labelled-item>
|
53
|
+
<item-label>OpenID</item-label>
|
54
|
+
<item-value><input type="text" name="login" id="login" class="string"/></item-value>
|
55
|
+
</labelled-item>
|
56
|
+
|
57
|
+
<labelled-item if="&Hobo::User.default_user_model.column_names.include?('remember_token')">
|
58
|
+
<item-label class="field-label">Remember me:</item-label>
|
59
|
+
<item-value><input type="checkbox" name="remember_me" id="remember-me"/></item-value>
|
60
|
+
</labelled-item>
|
61
|
+
</labelled-item-list>
|
62
|
+
<set user="&Hobo::User.default_user_model"/>
|
63
|
+
<div class="actions">
|
64
|
+
<submit label='Log in'/>
|
65
|
+
</div>
|
66
|
+
</form:>
|
67
|
+
</login-page>
|
68
|
+
|
69
|
+
Add links to OpenID login page on login and signup pages
|
70
|
+
--------------------------------------------------------
|
71
|
+
|
72
|
+
Create app/views/users/signup.dryml with content
|
73
|
+
|
74
|
+
<signup-page>
|
75
|
+
<append-body:>
|
76
|
+
Or <a href="&openid_login_users_path">sign up using OpenID</a>.
|
77
|
+
</append-body:>
|
78
|
+
</signup-page>
|
79
|
+
|
80
|
+
and app/views/users/login.dryml with content
|
81
|
+
|
82
|
+
<login-page>
|
83
|
+
<append-body:>
|
84
|
+
Or <a href="&openid_login_users_path">log in using OpenID</a>.
|
85
|
+
</append-body:>
|
86
|
+
</login-page>
|
87
|
+
|
88
|
+
|
89
|
+
Create routes
|
90
|
+
-------------
|
91
|
+
|
92
|
+
Add this lines to config/routes.rb:
|
93
|
+
|
94
|
+
map.openid_login_users 'users/openid_login', :controller => 'users', :action => 'openid_login', :conditions => {:method => :get}
|
95
|
+
map.complete_openid_users 'users/complete_openid', :controller => 'users', :action => 'complete_openid', :conditions => {:method => :get}
|
96
|
+
|
97
|
+
|
98
|
+
Simple Registration
|
99
|
+
===================
|
100
|
+
|
101
|
+
Currently unsupported.
|
data/Rakefile
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "hobo_openid"
|
8
|
+
gem.summary = %Q{OpenID login for Hobo}
|
9
|
+
gem.description = %Q{Adds ability to login with OpenID to Hobo-based applications. See README to start using it.}
|
10
|
+
gem.email = "jbartosik@gmail.com"
|
11
|
+
gem.homepage = "http://github.com/ahenobarbi/hobo_openid"
|
12
|
+
gem.authors = ["Joachim Filip Ignacy Bartosik"]
|
13
|
+
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
|
14
|
+
#gem.add_dependency "hobo", ">=1.0.0"
|
15
|
+
gem.add_dependency "rails", ">=2.3.5"
|
16
|
+
gem.require_paths = ['lib']
|
17
|
+
end
|
18
|
+
Jeweler::GemcutterTasks.new
|
19
|
+
rescue LoadError
|
20
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'rake/testtask'
|
24
|
+
Rake::TestTask.new(:test) do |test|
|
25
|
+
test.libs << 'lib' << 'test'
|
26
|
+
test.pattern = 'test/**/test_*.rb'
|
27
|
+
test.verbose = true
|
28
|
+
end
|
29
|
+
|
30
|
+
begin
|
31
|
+
require 'rcov/rcovtask'
|
32
|
+
Rcov::RcovTask.new do |test|
|
33
|
+
test.libs << 'test'
|
34
|
+
test.pattern = 'test/**/test_*.rb'
|
35
|
+
test.verbose = true
|
36
|
+
end
|
37
|
+
rescue LoadError
|
38
|
+
task :rcov do
|
39
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task :test => :check_dependencies
|
44
|
+
|
45
|
+
task :default => :test
|
46
|
+
|
47
|
+
require 'rake/rdoctask'
|
48
|
+
Rake::RDocTask.new do |rdoc|
|
49
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
50
|
+
|
51
|
+
rdoc.rdoc_dir = 'rdoc'
|
52
|
+
rdoc.title = "hobo_openid #{version}"
|
53
|
+
rdoc.rdoc_files.include('README*')
|
54
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
55
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.4.0
|
data/lib/hobo_openid.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'hobo'
|
2
|
+
require 'openid'
|
3
|
+
require 'openid_controller'
|
4
|
+
|
5
|
+
class ActionController::Base
|
6
|
+
|
7
|
+
# Recognized options
|
8
|
+
# :login_action - default :openid_login
|
9
|
+
# :complete_action - default :complete_openid
|
10
|
+
# :openid_opts - forwarded to hobo_openid_login, hobo_openid_complete
|
11
|
+
# :openid_opts recognizes
|
12
|
+
# :model - class of your user model (required)
|
13
|
+
# :login - field of params where users provide openIDs (default :login)
|
14
|
+
# :return_to - page to return after OpenID auth. -> should point to action executing hobo_openid_complete
|
15
|
+
# :openid_field - field of your user model that stores openID
|
16
|
+
# :mappings - simple registration mappings (currently unsupported)
|
17
|
+
# :redirect_to - where to redirect after success
|
18
|
+
# :*_notice - failure, cancellation, setup_needed, new_user_failure
|
19
|
+
def self.openid_login(options = {})
|
20
|
+
options.reverse_merge!(:login_action => :openid_login,
|
21
|
+
:complete_action => :complete_openid,
|
22
|
+
:openid_opts => Hash.new)
|
23
|
+
|
24
|
+
include Hobo::OpenidController
|
25
|
+
|
26
|
+
define_method(options[:complete_action]) do
|
27
|
+
hobo_openid_complete(options[:openid_opts])
|
28
|
+
end
|
29
|
+
|
30
|
+
define_method(options[:login_action]) do
|
31
|
+
hobo_openid_login(request, options[:openid_opts])
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
require 'openid'
|
2
|
+
require 'openid/extensions/sreg'
|
3
|
+
require 'openid/store/memory'
|
4
|
+
module Hobo
|
5
|
+
module OpenidController
|
6
|
+
# Login action for controller. Parameters:
|
7
|
+
# Recognized options are:
|
8
|
+
# :model - class of your user model (default User)
|
9
|
+
# :login - field of params where users provide openIDs (default :login)
|
10
|
+
# :return_to - page to return
|
11
|
+
def hobo_openid_login(request, options = {})
|
12
|
+
options.reverse_merge!(:success_notice => "You have logged in",
|
13
|
+
:failure_notice => "Verification failed",
|
14
|
+
:cancellation_notice => "Verification cancelled",
|
15
|
+
:setup_needed_notice => "OpenID server reports setup is needed",
|
16
|
+
:new_user_failure_notice => "Could not create a new user account",
|
17
|
+
:redirect_to => { :controller => "front", :action => "index" },
|
18
|
+
:model => User,
|
19
|
+
:openid_field => :openid,
|
20
|
+
:mappings => [])
|
21
|
+
options.reverse_merge!(:return_to => url_for(:action => :complete_openid),
|
22
|
+
:model => User, :login => :login)
|
23
|
+
|
24
|
+
return unless request.post?
|
25
|
+
|
26
|
+
openid = params[options[:login]]
|
27
|
+
|
28
|
+
begin
|
29
|
+
oidreq = openid_consumer.begin openid
|
30
|
+
rescue => e
|
31
|
+
flash[:error] = "Discovery failed: #{e}"
|
32
|
+
redirect_to homepage(request) and return
|
33
|
+
end
|
34
|
+
|
35
|
+
redirect_to oidreq.redirect_url(homepage(request), options[:return_to])
|
36
|
+
end
|
37
|
+
|
38
|
+
# Complete user login. Recognized options:
|
39
|
+
# :model - class of your user model
|
40
|
+
# :openid_field - field of your user model that stores openID
|
41
|
+
# :mappings - simple registration mappings (currently unsupported)
|
42
|
+
# :redirect_to - where to redirect after success
|
43
|
+
# :*_notice - failure, cancellation, setup_needed, new_user_failure
|
44
|
+
def hobo_openid_complete(options={})
|
45
|
+
options.reverse_merge!(:success_notice => "You have logged in",
|
46
|
+
:failure_notice => "Verification failed",
|
47
|
+
:cancellation_notice => "Verification cancelled",
|
48
|
+
:setup_needed_notice => "OpenID server reports setup is needed",
|
49
|
+
:new_user_failure_notice => "Could not create a new user account",
|
50
|
+
:redirect_to => { :controller => "front", :action => "index"},
|
51
|
+
:model => User,
|
52
|
+
:openid_field => :openid,
|
53
|
+
:mappings => [])
|
54
|
+
|
55
|
+
user = nil
|
56
|
+
current_url = url_for(:action => 'complete_openid', :only_path => false)
|
57
|
+
|
58
|
+
# un-munge params array
|
59
|
+
parameters = params.reject{|k,v|request.path_parameters[k]}
|
60
|
+
response = openid_consumer.complete parameters, current_url
|
61
|
+
|
62
|
+
case response.status
|
63
|
+
when OpenID::Consumer::SUCCESS
|
64
|
+
openid = response.identity_url
|
65
|
+
user = model.first :conditions => { options[:openid_field] => openid }
|
66
|
+
|
67
|
+
if user #user exists
|
68
|
+
hobo_openid_complete_user_exists(user, options)
|
69
|
+
else
|
70
|
+
hobo_openid_complete_new_user(response, openid, options)
|
71
|
+
end
|
72
|
+
|
73
|
+
when OpenID::Consumer::FAILURE
|
74
|
+
flash[:notice] = options[:failure_notice]
|
75
|
+
|
76
|
+
when OpenID::Consumer::CANCEL
|
77
|
+
flash[:notice] = options[:cancellation_notice]
|
78
|
+
|
79
|
+
when OpenID::Consumer::SETUP_NEEDED
|
80
|
+
flash[:notice] = options[:setup_needed_notice]
|
81
|
+
|
82
|
+
else
|
83
|
+
flash[:notice] = "Unknown response from OpenID server."
|
84
|
+
end
|
85
|
+
|
86
|
+
redirect_to :action => :openid_login unless performed?
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
def openid_logout(options={})
|
91
|
+
options = options.reverse_merge(:notice => "You have been logged out.",
|
92
|
+
:redirect_to => base_url)
|
93
|
+
|
94
|
+
current_user.forget_me if logged_in?
|
95
|
+
cookies.delete :auth_token
|
96
|
+
reset_session
|
97
|
+
flash[:notice] = options[:notice]
|
98
|
+
redirect_back_or_default(options[:redirect_to])
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
# Get the OpenID::Consumer object.
|
103
|
+
def openid_consumer
|
104
|
+
@@openid_consumer ||= OpenID::Consumer.new(session, OpenID::Store::Memory.new)
|
105
|
+
end
|
106
|
+
|
107
|
+
# Helper function for Openid::Controller#complete.
|
108
|
+
# handles existing users that successfully authorized.
|
109
|
+
# user is user to be logged in. Recognized option :success_notice.
|
110
|
+
# If you provide block taking user as argument it will be used to determine
|
111
|
+
# if user can login.
|
112
|
+
def hobo_openid_complete_user_exists(user, options = {})
|
113
|
+
# If supplied, a block can be used to test if this user is
|
114
|
+
# allowed to log in (e.g. the account may be disabled)
|
115
|
+
return if block_given? && !yield(user)
|
116
|
+
|
117
|
+
# Change current_user
|
118
|
+
self.current_user = user
|
119
|
+
|
120
|
+
if params[:remember_me] == "1"
|
121
|
+
current_user.remember_me
|
122
|
+
create_auth_cookie
|
123
|
+
end
|
124
|
+
|
125
|
+
flash[:notice] ||= options[:success_notice]
|
126
|
+
|
127
|
+
redirect_back_or_default(options[:redirect_to] || homepage(request)) unless performed?
|
128
|
+
end
|
129
|
+
|
130
|
+
# Helper function for Openid::Controller#complete
|
131
|
+
# handles new users that successfully authorized.
|
132
|
+
# user - user to be logged in.
|
133
|
+
# respose - response of openID provider
|
134
|
+
# Recognized options are (if they are missing function may fail):
|
135
|
+
# :model, :openid_field, :mappings
|
136
|
+
def hobo_openid_complete_new_user(response, openid, options = {})
|
137
|
+
# Generate parameters for new user record
|
138
|
+
user_attrs = {options[:openid_field] => openid}
|
139
|
+
sreg = OpenID::SReg::Response.from_success_response(response)
|
140
|
+
|
141
|
+
unless sreg.empty?
|
142
|
+
options[:mappings].each do |set,mappings|
|
143
|
+
mappings.each do |key,col|
|
144
|
+
user_attrs[col] = sreg[key.to_s]
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
user = options[:model].new(user_attrs)
|
150
|
+
logger.info user_attrs
|
151
|
+
|
152
|
+
flash[:notice] = options[:new_user_failure_notice] unless user.save false
|
153
|
+
|
154
|
+
self.current_user = user
|
155
|
+
redirect_to(:action => "edit", :id => user.id)
|
156
|
+
end
|
157
|
+
|
158
|
+
# If I call it home_page it'll break cucumbers
|
159
|
+
def homepage(request)
|
160
|
+
"#{request.protocol}#{request.host}:#{request.port}"
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hobo_openid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 15
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Joachim Filip Ignacy Bartosik
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-04 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: thoughtbot-shoulda
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rails
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 9
|
44
|
+
segments:
|
45
|
+
- 2
|
46
|
+
- 3
|
47
|
+
- 5
|
48
|
+
version: 2.3.5
|
49
|
+
type: :runtime
|
50
|
+
version_requirements: *id002
|
51
|
+
description: Adds ability to login with OpenID to Hobo-based applications. See README to start using it.
|
52
|
+
email: jbartosik@gmail.com
|
53
|
+
executables: []
|
54
|
+
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files:
|
58
|
+
- LICENSE.txt
|
59
|
+
- README.markdown
|
60
|
+
files:
|
61
|
+
- .gitignore
|
62
|
+
- CREDITS
|
63
|
+
- LICENSE.txt
|
64
|
+
- README.markdown
|
65
|
+
- Rakefile
|
66
|
+
- VERSION
|
67
|
+
- lib/hobo_openid.rb
|
68
|
+
- lib/openid_controller.rb
|
69
|
+
has_rdoc: true
|
70
|
+
homepage: http://github.com/ahenobarbi/hobo_openid
|
71
|
+
licenses: []
|
72
|
+
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options:
|
75
|
+
- --charset=UTF-8
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
hash: 3
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
hash: 3
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
requirements: []
|
97
|
+
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.3.7
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: OpenID login for Hobo
|
103
|
+
test_files: []
|
104
|
+
|