devise_openid_authenticatable 1.0.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ pkg/*
data/README.md ADDED
@@ -0,0 +1,102 @@
1
+ devise_openid_authenticatable
2
+ ==========================
3
+
4
+ Written by Nat Budin
5
+
6
+ devise_openid_authenticatable is [OpenID](http://openid.net) authentication support for
7
+ [Devise](http://github.com/plataformatec/devise) applications. It is very thin and uses
8
+ [Rack::OpenID](http://github.com/josh/rack-openid) for most of the actual work.
9
+
10
+ Requirements
11
+ ------------
12
+
13
+ - Devise 1.0.6 or later (including 1.1 versions)
14
+ - rack-openid
15
+
16
+ Installation
17
+ ------------
18
+
19
+ gem install --pre devise_openid_authenticatable
20
+
21
+ and add devise_openid_authenticatable to your Gemfile or config/environment.rb as a gem
22
+ dependency.
23
+
24
+ Example
25
+ -------
26
+
27
+ I've modified the devise_example application to work with this gem. You can find the results
28
+ [here](http://github.com/nbudin/devise_openid_example).
29
+
30
+ Setup
31
+ -----
32
+
33
+ Once devise\_openid\_authenticatable is installed, add the following to your user model:
34
+
35
+ devise :openid_authenticatable
36
+
37
+ You can also add other modules such as token_authenticatable, trackable, etc. Database_authenticatable
38
+ should work fine alongside openid_authenticatable.
39
+
40
+ You'll also need to set up the database schema for this:
41
+
42
+ create_table :users do |t|
43
+ t.openid_authenticatable
44
+ end
45
+
46
+ and, optionally, indexes:
47
+
48
+ add_index :users, :identity_url, :unique => true
49
+
50
+ In addition, you'll need to modify sessions/new.html.erb (or the appropriate scoped view if you're
51
+ using those). You need to add a field for identity_url, and remove username and password if you
52
+ aren't using database_authenticatable:
53
+
54
+ <% form_for resource_name, resource, :url => session_path(resource_name) do |f| -%>
55
+ <p><%= f.label :identity_url %></p>
56
+ <p><%= f.text_field :identity_url %></p>
57
+
58
+ <% if devise_mapping.rememberable? -%>
59
+ <p><%= f.check_box :remember_me %> <%= f.label :remember_me %></p>
60
+ <% end -%>
61
+
62
+ <p><%= f.submit "Sign in" %></p>
63
+ <% end -%>
64
+
65
+ Finally, you'll need to add the following in your Rails configuration:
66
+
67
+ config.middleware.use Rack::OpenID
68
+
69
+ which is the Rack middleware that actually does most of the heavy lifting here.
70
+
71
+ Automatically creating users
72
+ ----------------------------
73
+
74
+ If you want to have users automatically created when a new OpenID identity URL is
75
+ successfully used to sign in, you can implement a method called "create_from_identity_url"
76
+ to your user model class:
77
+
78
+ class User < ActiveRecord::Base
79
+ devise :openid_authenticatable
80
+
81
+ def self.create_from_identity_url(identity_url)
82
+ User.create(:identity_url => identity_url)
83
+ end
84
+ end
85
+
86
+ Ideally I'd like to add support for using sreg attributes here as well, to populate other
87
+ fields in the user table.
88
+
89
+ See also
90
+ --------
91
+
92
+ * [OpenID](http://openid.net)
93
+ * [Rack::OpenID](http://github.com/josh/rack-openid)
94
+ * [Devise](http://github.com/plataformatec/devise)
95
+ * [Warden](http://github.com/hassox/warden)
96
+
97
+ TODO
98
+ ----
99
+
100
+ * Add sreg attributes support
101
+ * Write test suite
102
+ * Test on non-ActiveRecord ORMs
data/Rakefile ADDED
@@ -0,0 +1,41 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the devise_openid_authenticatable plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the devise_openid_authenticatable plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'devise_openid_authenticatable'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
24
+
25
+
26
+ begin
27
+ require 'jeweler'
28
+ Jeweler::Tasks.new do |gemspec|
29
+ gemspec.name = "devise_openid_authenticatable"
30
+ gemspec.summary = "OpenID authentication module for Devise"
31
+ gemspec.description = "OpenID authentication module for Devise using Rack::OpenID"
32
+ gemspec.email = "natbudin@gmail.com"
33
+ gemspec.homepage = "http://github.com/nbudin/devise_cas_authenticatable"
34
+ gemspec.authors = ["Nat Budin"]
35
+ gemspec.add_runtime_dependency "devise", ">= 1.0.6"
36
+ gemspec.add_runtime_dependency "rack-openid", "~> 1.0.3"
37
+ end
38
+ Jeweler::GemcutterTasks.new
39
+ rescue LoadError
40
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
41
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0.alpha1
@@ -0,0 +1,53 @@
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{devise_openid_authenticatable}
8
+ s.version = "1.0.0.alpha1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Nat Budin"]
12
+ s.date = %q{2010-05-21}
13
+ s.description = %q{OpenID authentication module for Devise using Rack::OpenID}
14
+ s.email = %q{natbudin@gmail.com}
15
+ s.extra_rdoc_files = [
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "README.md",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "devise_openid_authenticatable.gemspec",
24
+ "lib/devise_openid_authenticatable.rb",
25
+ "lib/devise_openid_authenticatable/model.rb",
26
+ "lib/devise_openid_authenticatable/routes.rb",
27
+ "lib/devise_openid_authenticatable/schema.rb",
28
+ "lib/devise_openid_authenticatable/strategy.rb",
29
+ "rails/init.rb"
30
+ ]
31
+ s.homepage = %q{http://github.com/nbudin/devise_cas_authenticatable}
32
+ s.rdoc_options = ["--charset=UTF-8"]
33
+ s.require_paths = ["lib"]
34
+ s.rubygems_version = %q{1.3.7}
35
+ s.summary = %q{OpenID authentication module for Devise}
36
+
37
+ if s.respond_to? :specification_version then
38
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
39
+ s.specification_version = 3
40
+
41
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
+ s.add_runtime_dependency(%q<devise>, [">= 1.0.6"])
43
+ s.add_runtime_dependency(%q<rack-openid>, ["~> 1.0.3"])
44
+ else
45
+ s.add_dependency(%q<devise>, [">= 1.0.6"])
46
+ s.add_dependency(%q<rack-openid>, ["~> 1.0.3"])
47
+ end
48
+ else
49
+ s.add_dependency(%q<devise>, [">= 1.0.6"])
50
+ s.add_dependency(%q<rack-openid>, ["~> 1.0.3"])
51
+ end
52
+ end
53
+
@@ -0,0 +1,9 @@
1
+ module Devise
2
+ module Models
3
+ module OpenidAuthenticatable
4
+ def find_by_identity_url(identity_url)
5
+ find(:first, :conditions => {:identity_url => identity_url})
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ if ActionController::Routing.name =~ /ActionDispatch/
2
+ # We're on Rails 3
3
+ ActionDispatch::Routing::Mapper.class_eval do
4
+ protected
5
+
6
+ alias_method :devise_openid, :devise_session
7
+ end
8
+ else
9
+ # We're on Rails 2
10
+
11
+ ActionController::Routing::RouteSet::Mapper.class_eval do
12
+ protected
13
+
14
+ alias_method :openid_authenticatable, :database_authenticatable
15
+ end
16
+ end
@@ -0,0 +1,5 @@
1
+ Devise::Schema.class_eval do
2
+ def openid_authenticatable
3
+ apply_schema :identity_url, String
4
+ end
5
+ end
@@ -0,0 +1,43 @@
1
+ require 'devise/strategies/base'
2
+ require 'rack/openid'
3
+
4
+ module Devise
5
+ module Strategies
6
+ class OpenidAuthenticatable < Base
7
+ def valid?
8
+ env[Rack::OpenID::RESPONSE] || (mapping.to.respond_to?(:find_by_identity_url) &&
9
+ params[scope] && !params[scope]["identity_url"].blank?)
10
+ end
11
+
12
+ def authenticate!
13
+ RAILS_DEFAULT_LOGGER.info("Authenticating with OpenID for mapping #{mapping.to}")
14
+ if resp = env[Rack::OpenID::RESPONSE]
15
+ RAILS_DEFAULT_LOGGER.info "Attempting OpenID auth: #{env["rack.openid.response"].inspect}"
16
+ case resp.status
17
+ when :success
18
+ u = mapping.to.find_by_identity_url(resp.identity_url)
19
+ if u
20
+ success!(u)
21
+ elsif mapping.to.respond_to?(:create_from_identity_url)
22
+ success!(mapping.to.create_from_identity_url(resp.identity_url))
23
+ else
24
+ fail!("This OpenID URL is not associated with any registered user")
25
+ end
26
+ when :cancel
27
+ fail!("OpenID auth cancelled")
28
+ when :failure
29
+ fail!("OpenID auth failed")
30
+ end
31
+ else
32
+ header_data = Rack::OpenID.build_header(:identifier => params[scope]["identity_url"])
33
+ RAILS_DEFAULT_LOGGER.info header_data
34
+ custom!([401, {
35
+ Rack::OpenID::AUTHENTICATE_HEADER => header_data
36
+ }, "Sign in with OpenID"])
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ Warden::Strategies.add(:openid_authenticatable, Devise::Strategies::OpenidAuthenticatable)
@@ -0,0 +1,11 @@
1
+ require 'devise'
2
+
3
+ require 'devise_openid_authenticatable/schema'
4
+ require 'devise_openid_authenticatable/strategy'
5
+ require 'devise_openid_authenticatable/routes'
6
+
7
+ Devise.add_module(:openid_authenticatable,
8
+ :strategy => true,
9
+ :model => 'devise_openid_authenticatable/model',
10
+ :controller => :sessions,
11
+ :route => :openid)
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ require "devise_openid_authenticatable"
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devise_openid_authenticatable
3
+ version: !ruby/object:Gem::Version
4
+ hash: -1710980573
5
+ prerelease: true
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ - alpha1
11
+ version: 1.0.0.alpha1
12
+ platform: ruby
13
+ authors:
14
+ - Nat Budin
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-05-21 00:00:00 -04:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: devise
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ hash: 27
31
+ segments:
32
+ - 1
33
+ - 0
34
+ - 6
35
+ version: 1.0.6
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ - !ruby/object:Gem::Dependency
39
+ name: rack-openid
40
+ prerelease: false
41
+ requirement: &id002 !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ hash: 17
47
+ segments:
48
+ - 1
49
+ - 0
50
+ - 3
51
+ version: 1.0.3
52
+ type: :runtime
53
+ version_requirements: *id002
54
+ description: OpenID authentication module for Devise using Rack::OpenID
55
+ email: natbudin@gmail.com
56
+ executables: []
57
+
58
+ extensions: []
59
+
60
+ extra_rdoc_files:
61
+ - README.md
62
+ files:
63
+ - .gitignore
64
+ - README.md
65
+ - Rakefile
66
+ - VERSION
67
+ - devise_openid_authenticatable.gemspec
68
+ - lib/devise_openid_authenticatable.rb
69
+ - lib/devise_openid_authenticatable/model.rb
70
+ - lib/devise_openid_authenticatable/routes.rb
71
+ - lib/devise_openid_authenticatable/schema.rb
72
+ - lib/devise_openid_authenticatable/strategy.rb
73
+ - rails/init.rb
74
+ has_rdoc: true
75
+ homepage: http://github.com/nbudin/devise_cas_authenticatable
76
+ licenses: []
77
+
78
+ post_install_message:
79
+ rdoc_options:
80
+ - --charset=UTF-8
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ hash: 3
89
+ segments:
90
+ - 0
91
+ version: "0"
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ">"
96
+ - !ruby/object:Gem::Version
97
+ hash: 25
98
+ segments:
99
+ - 1
100
+ - 3
101
+ - 1
102
+ version: 1.3.1
103
+ requirements: []
104
+
105
+ rubyforge_project:
106
+ rubygems_version: 1.3.7
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: OpenID authentication module for Devise
110
+ test_files: []
111
+