toretore-simple_openid_authentication 0.1.2 → 0.1.3
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/app/views/logins/openid.html.erb +11 -0
- data/config/locales/simple_openid_authentication.yml +10 -0
- data/generators/simple_openid_authentication/USAGE +5 -0
- data/generators/simple_openid_authentication/simple_openid_authentication_generator.rb +38 -0
- data/lib/simple_openid_authentication.rb +6 -0
- data/lib/simple_openid_authentication/controller_methods.rb +67 -0
- data/lib/simple_openid_authentication/openid_authenticator.rb +20 -0
- data/rails/init.rb +1 -0
- data/rails/install.rb +1 -0
- data/rails/uninstall.rb +1 -0
- data/tasks/simple_openid_authentication_tasks.rake +4 -0
- metadata +21 -5
@@ -0,0 +1,11 @@
|
|
1
|
+
<h2><%= t('simple_openid_authentication.title') %></h2>
|
2
|
+
|
3
|
+
<% form_tag login_url(:authenticator => "openid") do -%>
|
4
|
+
<p class="input text">
|
5
|
+
<label for="openid_identifier"><%= User.human_attribute_name('openid_identifier') %></label>
|
6
|
+
<%= text_field_tag "openid_identifier" %>
|
7
|
+
</p>
|
8
|
+
<p class="submit button">
|
9
|
+
<%= submit_tag t('simple_openid_authentication.button') %>
|
10
|
+
</p>
|
11
|
+
<% end -%>
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class SimpleOpenidAuthenticationGenerator < Rails::Generator::NamedBase
|
2
|
+
def manifest
|
3
|
+
record do |m|
|
4
|
+
m.migration_template "migration:migration.rb", "db/migrate", :assigns => openid_auth_assigns,
|
5
|
+
:migration_file_name => "add_openid_authentication_fields_to_#{custom_file_name}" if options[:migration]
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def custom_file_name
|
12
|
+
custom_name = class_name.underscore.downcase
|
13
|
+
custom_name = custom_name.pluralize if ActiveRecord::Base.pluralize_table_names
|
14
|
+
custom_name
|
15
|
+
end
|
16
|
+
|
17
|
+
def openid_auth_assigns
|
18
|
+
returning({}) do |assigns|
|
19
|
+
assigns[:migration_action] = "add"
|
20
|
+
assigns[:class_name] = "add_openid_authentication_fields_to_#{custom_file_name}"
|
21
|
+
assigns[:table_name] = "users"
|
22
|
+
assigns[:attributes] = openid_auth_attributes
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def openid_auth_attributes
|
27
|
+
returning attributes.dup do |attributes|
|
28
|
+
{"openid_identifier" => "string"}.each do |name, type|
|
29
|
+
attributes << Rails::Generator::GeneratedAttribute.new(name, type) unless attributes.any?{|a| a.name == name }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_options!(opt)
|
35
|
+
opt.on('--migration', 'Create migration'){|v| options[:migration] = true }
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,6 @@
|
|
1
|
+
require "simple_authentication"
|
2
|
+
require "simple_openid_authentication/openid_authenticator"
|
3
|
+
require "simple_openid_authentication/controller_methods"
|
4
|
+
|
5
|
+
SimpleAuthentication::ControllerMethods::Logins.send(:include, SimpleOpenidAuthentication::ControllerMethods::Logins)
|
6
|
+
I18n.load_path.unshift(File.join(File.dirname(__FILE__), '..', 'config', 'locales', 'simple_openid_authentication.yml'))
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module SimpleOpenidAuthentication
|
2
|
+
|
3
|
+
|
4
|
+
module ControllerMethods
|
5
|
+
|
6
|
+
|
7
|
+
module Logins
|
8
|
+
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def openid_authentication
|
13
|
+
authenticate_with_open_id openid_authentication_url, openid_authentication_options do |result, identity_url, registration|
|
14
|
+
if result.successful?
|
15
|
+
authenticate_openid_user(identity_url, registration)
|
16
|
+
else
|
17
|
+
authentication_failed result.message
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def authenticate_openid_user(identity_url, registration)
|
23
|
+
user = User.find_or_initialize_by_openid_identifier(identity_url)
|
24
|
+
|
25
|
+
#Add or update attributes provided by the OpenID server
|
26
|
+
model_to_registration_mapping.each do |attr,reg_key|
|
27
|
+
user.send("#{attr}=", registration[reg_key])
|
28
|
+
end
|
29
|
+
|
30
|
+
if user.save
|
31
|
+
self.current_user = user
|
32
|
+
authentication_successful
|
33
|
+
else
|
34
|
+
authentication_failed I18n.t('simple_openid_authentication.could_not_save_user')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def openid_authentication_url
|
39
|
+
params[:openid_identifier]
|
40
|
+
end
|
41
|
+
|
42
|
+
def openid_authentication_options(opts={})
|
43
|
+
{
|
44
|
+
:return_to => login_url(:authenticator => "openid") #open_id_authentication will fake a POST
|
45
|
+
}.merge(openid_registration_options).merge(opts)
|
46
|
+
end
|
47
|
+
|
48
|
+
#Which attributes to request from the provider using the Simple Registration Extension
|
49
|
+
#They can be :optional or :required
|
50
|
+
def openid_registration_options
|
51
|
+
{:optional => [:fullname, :email]}
|
52
|
+
end
|
53
|
+
|
54
|
+
#Which attributes on the user object receives which SReg attributes
|
55
|
+
def model_to_registration_mapping
|
56
|
+
#{:model => 'server'}
|
57
|
+
{:name => 'fullname', :email => 'email'}
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module SimpleAuthentication
|
2
|
+
|
3
|
+
class OpenidAuthenticator < Authenticator
|
4
|
+
|
5
|
+
|
6
|
+
def authentication_possible?
|
7
|
+
params.include?(:openid_identifier) || params.include?(:open_id_complete)
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
def authenticate
|
12
|
+
controller.send :openid_authentication
|
13
|
+
|
14
|
+
:ok
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "simple_openid_authentication"
|
data/rails/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
data/rails/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: toretore-simple_openid_authentication
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tore Darell
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-03-
|
12
|
+
date: 2009-03-16 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,7 +20,7 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - "="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version: 0.1.
|
23
|
+
version: 0.1.3
|
24
24
|
version:
|
25
25
|
description: OpenID authentication for SimpleAuthentication
|
26
26
|
email: toredarell@gmail.com
|
@@ -30,8 +30,24 @@ extensions: []
|
|
30
30
|
|
31
31
|
extra_rdoc_files: []
|
32
32
|
|
33
|
-
files:
|
34
|
-
|
33
|
+
files:
|
34
|
+
- lib/simple_openid_authentication
|
35
|
+
- lib/simple_openid_authentication/openid_authenticator.rb
|
36
|
+
- lib/simple_openid_authentication/controller_methods.rb
|
37
|
+
- lib/simple_openid_authentication.rb
|
38
|
+
- rails/uninstall.rb
|
39
|
+
- rails/install.rb
|
40
|
+
- rails/init.rb
|
41
|
+
- config/locales
|
42
|
+
- config/locales/simple_openid_authentication.yml
|
43
|
+
- app/views
|
44
|
+
- app/views/logins
|
45
|
+
- app/views/logins/openid.html.erb
|
46
|
+
- generators/simple_openid_authentication
|
47
|
+
- generators/simple_openid_authentication/USAGE
|
48
|
+
- generators/simple_openid_authentication/templates
|
49
|
+
- generators/simple_openid_authentication/simple_openid_authentication_generator.rb
|
50
|
+
- tasks/simple_openid_authentication_tasks.rake
|
35
51
|
has_rdoc: false
|
36
52
|
homepage: http://github.com/toretore/simple_openid_authentication
|
37
53
|
post_install_message:
|