devise_openid_authenticatable 1.0.0.alpha5 → 1.0.0.alpha6
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +9 -0
- data/README.md +5 -3
- data/Rakefile +5 -11
- data/VERSION +1 -1
- data/devise_openid_authenticatable.gemspec +49 -3
- data/lib/devise_openid_authenticatable/strategy.rb +72 -52
- data/lib/devise_openid_authenticatable.rb +2 -2
- data/spec/model_spec.rb +10 -0
- data/spec/scenario/app/controllers/application_controller.rb +4 -0
- data/spec/scenario/app/controllers/home_controller.rb +5 -0
- data/spec/scenario/app/controllers/sessions_controller.rb +4 -0
- data/spec/scenario/app/models/user.rb +18 -0
- data/spec/scenario/app/views/sessions/new.html.erb +10 -0
- data/spec/scenario/config/application.rb +18 -0
- data/spec/scenario/config/boot.rb +15 -0
- data/spec/scenario/config/database.yml +5 -0
- data/spec/scenario/config/environment.rb +5 -0
- data/spec/scenario/config/environments/development.rb +19 -0
- data/spec/scenario/config/environments/test.rb +33 -0
- data/spec/scenario/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/scenario/config/initializers/inflections.rb +2 -0
- data/spec/scenario/config/initializers/secret_token.rb +2 -0
- data/spec/scenario/config/routes.rb +4 -0
- data/spec/scenario/config.ru +0 -0
- data/spec/scenario/db/migrate/20100401102949_create_tables.rb +13 -0
- data/spec/scenario/db/schema.rb +38 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/strategy_spec.rb +163 -0
- data/spec/support/migrations.rb +4 -0
- data/spec/support/patches.rb +4 -0
- metadata +53 -5
data/.gitignore
CHANGED
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -62,11 +62,13 @@ aren't using database_authenticatable:
|
|
62
62
|
<p><%= f.submit "Sign in" %></p>
|
63
63
|
<% end -%>
|
64
64
|
|
65
|
-
Finally, you'll need to
|
65
|
+
Finally, you'll need to wire up Rack::OpenID in your Rails configuration. If you're using Devise 1.0, you can do:
|
66
|
+
|
67
|
+
config.middleware.use "Rack::OpenID"
|
68
|
+
|
69
|
+
If you're using Devise 1.1 or a later version, you'll need to do this instead, to ensure that Rack::OpenID sits above Warden in the Rack middleware stack:
|
66
70
|
|
67
71
|
config.middleware.insert_before(Warden::Manager, Rack::OpenID)
|
68
|
-
|
69
|
-
which is the Rack middleware that actually does most of the heavy lifting here.
|
70
72
|
|
71
73
|
Automatically creating users
|
72
74
|
----------------------------
|
data/Rakefile
CHANGED
@@ -1,17 +1,12 @@
|
|
1
1
|
require 'rake'
|
2
|
-
require 'rake/testtask'
|
3
2
|
require 'rake/rdoctask'
|
3
|
+
require 'rspec/mocks/version'
|
4
|
+
require 'rspec/core/rake_task'
|
4
5
|
|
5
|
-
|
6
|
-
task :default => :test
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
7
|
|
8
|
-
desc '
|
9
|
-
|
10
|
-
t.libs << 'lib'
|
11
|
-
t.libs << 'test'
|
12
|
-
t.pattern = 'test/**/*_test.rb'
|
13
|
-
t.verbose = true
|
14
|
-
end
|
8
|
+
desc 'Default: run specs.'
|
9
|
+
task :default => :spec
|
15
10
|
|
16
11
|
desc 'Generate documentation for the devise_openid_authenticatable plugin.'
|
17
12
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
@@ -22,7 +17,6 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
22
17
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
18
|
end
|
24
19
|
|
25
|
-
|
26
20
|
begin
|
27
21
|
require 'jeweler'
|
28
22
|
Jeweler::Tasks.new do |gemspec|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.0.
|
1
|
+
1.0.0.alpha6
|
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{devise_openid_authenticatable}
|
8
|
-
s.version = "1.0.0.
|
8
|
+
s.version = "1.0.0.alpha6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Nat Budin"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-19}
|
13
13
|
s.description = %q{OpenID authentication module for Devise using Rack::OpenID}
|
14
14
|
s.email = %q{natbudin@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.files = [
|
19
19
|
".gitignore",
|
20
20
|
"CHANGELOG.rdoc",
|
21
|
+
"Gemfile",
|
21
22
|
"README.md",
|
22
23
|
"Rakefile",
|
23
24
|
"VERSION",
|
@@ -27,13 +28,58 @@ Gem::Specification.new do |s|
|
|
27
28
|
"lib/devise_openid_authenticatable/routes.rb",
|
28
29
|
"lib/devise_openid_authenticatable/schema.rb",
|
29
30
|
"lib/devise_openid_authenticatable/strategy.rb",
|
30
|
-
"rails/init.rb"
|
31
|
+
"rails/init.rb",
|
32
|
+
"spec/model_spec.rb",
|
33
|
+
"spec/scenario/app/controllers/application_controller.rb",
|
34
|
+
"spec/scenario/app/controllers/home_controller.rb",
|
35
|
+
"spec/scenario/app/controllers/sessions_controller.rb",
|
36
|
+
"spec/scenario/app/models/user.rb",
|
37
|
+
"spec/scenario/app/views/sessions/new.html.erb",
|
38
|
+
"spec/scenario/config.ru",
|
39
|
+
"spec/scenario/config/application.rb",
|
40
|
+
"spec/scenario/config/boot.rb",
|
41
|
+
"spec/scenario/config/database.yml",
|
42
|
+
"spec/scenario/config/environment.rb",
|
43
|
+
"spec/scenario/config/environments/development.rb",
|
44
|
+
"spec/scenario/config/environments/test.rb",
|
45
|
+
"spec/scenario/config/initializers/backtrace_silencers.rb",
|
46
|
+
"spec/scenario/config/initializers/inflections.rb",
|
47
|
+
"spec/scenario/config/initializers/secret_token.rb",
|
48
|
+
"spec/scenario/config/routes.rb",
|
49
|
+
"spec/scenario/db/migrate/20100401102949_create_tables.rb",
|
50
|
+
"spec/scenario/db/schema.rb",
|
51
|
+
"spec/spec_helper.rb",
|
52
|
+
"spec/strategy_spec.rb",
|
53
|
+
"spec/support/migrations.rb",
|
54
|
+
"spec/support/patches.rb"
|
31
55
|
]
|
32
56
|
s.homepage = %q{http://github.com/nbudin/devise_openid_authenticatable}
|
33
57
|
s.rdoc_options = ["--charset=UTF-8"]
|
34
58
|
s.require_paths = ["lib"]
|
35
59
|
s.rubygems_version = %q{1.3.7}
|
36
60
|
s.summary = %q{OpenID authentication module for Devise}
|
61
|
+
s.test_files = [
|
62
|
+
"spec/model_spec.rb",
|
63
|
+
"spec/scenario/app/controllers/application_controller.rb",
|
64
|
+
"spec/scenario/app/controllers/home_controller.rb",
|
65
|
+
"spec/scenario/app/controllers/sessions_controller.rb",
|
66
|
+
"spec/scenario/app/models/user.rb",
|
67
|
+
"spec/scenario/config/application.rb",
|
68
|
+
"spec/scenario/config/boot.rb",
|
69
|
+
"spec/scenario/config/environment.rb",
|
70
|
+
"spec/scenario/config/environments/development.rb",
|
71
|
+
"spec/scenario/config/environments/test.rb",
|
72
|
+
"spec/scenario/config/initializers/backtrace_silencers.rb",
|
73
|
+
"spec/scenario/config/initializers/inflections.rb",
|
74
|
+
"spec/scenario/config/initializers/secret_token.rb",
|
75
|
+
"spec/scenario/config/routes.rb",
|
76
|
+
"spec/scenario/db/migrate/20100401102949_create_tables.rb",
|
77
|
+
"spec/scenario/db/schema.rb",
|
78
|
+
"spec/spec_helper.rb",
|
79
|
+
"spec/strategy_spec.rb",
|
80
|
+
"spec/support/migrations.rb",
|
81
|
+
"spec/support/patches.rb"
|
82
|
+
]
|
37
83
|
|
38
84
|
if s.respond_to? :specification_version then
|
39
85
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
@@ -4,76 +4,96 @@ require 'rack/openid'
|
|
4
4
|
module Devise
|
5
5
|
module Strategies
|
6
6
|
class OpenidAuthenticatable < Base
|
7
|
+
|
7
8
|
def valid?
|
8
|
-
|
9
|
-
params[scope] && !params[scope]["identity_url"].blank?)
|
9
|
+
valid_mapping? && ( provider_response? || identity_param? )
|
10
10
|
end
|
11
11
|
|
12
12
|
def authenticate!
|
13
13
|
logger.debug("Authenticating with OpenID for mapping #{mapping.to}")
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
|
15
|
+
if provider_response
|
16
|
+
handle_response!
|
17
|
+
else # Delegate authentication to Rack::OpenID by throwing a 401
|
18
|
+
opts = { :identifier => params[scope]["identity_url"] }
|
19
|
+
opts[:optional] = mapping.to.openid_optional_fields if mapping.to.respond_to?(:openid_optional_fields)
|
20
|
+
opts[:required] = mapping.to.openid_required_fields if mapping.to.respond_to?(:openid_required_fields)
|
21
|
+
custom! [401, { Rack::OpenID::AUTHENTICATE_HEADER => Rack::OpenID.build_header(opts) }, "Sign in with OpenID"]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
# Handles incoming provider response
|
28
|
+
def handle_response!
|
29
|
+
logger.debug "Attempting OpenID auth: #{provider_response.inspect}"
|
30
|
+
|
31
|
+
case provider_response.status
|
17
32
|
when :success
|
18
|
-
|
19
|
-
if
|
20
|
-
|
33
|
+
resource = mapping.to.find_by_identity_url(provider_response.identity_url)
|
34
|
+
if resource.nil? && mapping.to.respond_to?(:create_from_identity_url)
|
35
|
+
resource = mapping.to.create_from_identity_url(provider_response.identity_url)
|
21
36
|
end
|
22
|
-
|
23
|
-
if
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
if openid_fields
|
28
|
-
u.openid_fields = openid_fields
|
29
|
-
u.save
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
success!(u)
|
37
|
+
|
38
|
+
if resource
|
39
|
+
update_resource!(resource)
|
40
|
+
success!(resource)
|
34
41
|
else
|
35
|
-
fail!
|
42
|
+
fail! "This OpenID URL is not associated with any registered user"
|
36
43
|
end
|
44
|
+
|
37
45
|
when :cancel
|
38
|
-
fail!
|
46
|
+
fail! "OpenID authentication cancelled"
|
39
47
|
when :failure
|
40
|
-
fail!
|
48
|
+
fail! "OpenID authentication failed"
|
41
49
|
end
|
42
|
-
else
|
43
|
-
header_params = { :identifier => params[scope]["identity_url"] }
|
44
|
-
header_params[:optional] = mapping.to.openid_optional_fields if mapping.to.respond_to?(:openid_optional_fields)
|
45
|
-
header_params[:required] = mapping.to.openid_required_fields if mapping.to.respond_to?(:openid_required_fields)
|
46
|
-
header_data = Rack::OpenID.build_header(header_params)
|
47
|
-
logger.debug header_data
|
48
|
-
custom!([401, {
|
49
|
-
Rack::OpenID::AUTHENTICATE_HEADER => header_data
|
50
|
-
}, "Sign in with OpenID"])
|
51
50
|
end
|
52
|
-
|
53
|
-
|
51
|
+
|
54
52
|
private
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
53
|
+
|
54
|
+
def provider_response?
|
55
|
+
!!provider_response
|
56
|
+
end
|
57
|
+
|
58
|
+
def provider_response
|
59
|
+
env[Rack::OpenID::RESPONSE]
|
60
|
+
end
|
61
|
+
|
62
|
+
def valid_mapping?
|
63
|
+
mapping.to.respond_to?(:find_by_identity_url)
|
64
|
+
end
|
65
|
+
|
66
|
+
def identity_param?
|
67
|
+
params[scope].try(:[], 'identity_url').present?
|
68
|
+
end
|
69
|
+
|
70
|
+
def update_resource!(resource)
|
71
|
+
return unless resource.respond_to?(:openid_fields=)
|
72
|
+
|
73
|
+
fields = nil
|
74
|
+
if axr = OpenID::AX::FetchResponse.from_success_response(provider_response)
|
75
|
+
fields = axr.data
|
76
|
+
else
|
77
|
+
provider_response.message.namespaces.each do |uri, ns_alias|
|
78
|
+
if ns_alias.to_s == "sreg"
|
79
|
+
fields = provider_response.extension_response(uri, true)
|
80
|
+
break
|
81
|
+
end
|
65
82
|
end
|
66
83
|
end
|
84
|
+
|
85
|
+
if fields
|
86
|
+
resource.openid_fields = fields
|
87
|
+
resource.save
|
88
|
+
end
|
67
89
|
end
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
@logger ||= ((Rails && Rails.logger) || RAILS_DEFAULT_LOGGER)
|
74
|
-
end
|
90
|
+
|
91
|
+
def logger
|
92
|
+
@logger ||= ((Rails && Rails.logger) || RAILS_DEFAULT_LOGGER)
|
93
|
+
end
|
94
|
+
|
75
95
|
end
|
76
96
|
end
|
77
97
|
end
|
78
98
|
|
79
|
-
Warden::Strategies.add
|
99
|
+
Warden::Strategies.add :openid_authenticatable, Devise::Strategies::OpenidAuthenticatable
|
@@ -4,8 +4,8 @@ require 'devise_openid_authenticatable/schema'
|
|
4
4
|
require 'devise_openid_authenticatable/strategy'
|
5
5
|
require 'devise_openid_authenticatable/routes'
|
6
6
|
|
7
|
-
Devise.add_module
|
7
|
+
Devise.add_module :openid_authenticatable,
|
8
8
|
:strategy => true,
|
9
9
|
:model => 'devise_openid_authenticatable/model',
|
10
10
|
:controller => :sessions,
|
11
|
-
:route => :openid
|
11
|
+
:route => :openid
|
data/spec/model_spec.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Devise::Models::OpenidAuthenticatable do
|
4
|
+
|
5
|
+
it 'should respond to find_by_identity_url' do
|
6
|
+
User.included_modules.should include(Devise::Models::OpenidAuthenticatable)
|
7
|
+
User.should respond_to(:find_by_identity_url)
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class User < ActiveRecord::Base
|
2
|
+
devise :openid_authenticatable
|
3
|
+
|
4
|
+
def self.create_from_identity_url(identity_url)
|
5
|
+
create do |user|
|
6
|
+
user.identity_url = identity_url
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.openid_required_fields
|
11
|
+
["http://axschema.org/contact/email"]
|
12
|
+
end
|
13
|
+
|
14
|
+
def openid_fields=(fields)
|
15
|
+
self.email = fields["http://axschema.org/contact/email"].first
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<h2>Sign in</h2>
|
2
|
+
|
3
|
+
<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>
|
4
|
+
<p><%= f.label :identity_url %><br />
|
5
|
+
<%= f.text_field :identity_url %></p>
|
6
|
+
|
7
|
+
<p><%= f.submit "Sign in" %></p>
|
8
|
+
<% end %>
|
9
|
+
|
10
|
+
<%= render :partial => "devise/shared/links" %>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require "rails/all"
|
4
|
+
Bundler.require :default, Rails.env
|
5
|
+
|
6
|
+
require "devise"
|
7
|
+
require "devise_openid_authenticatable"
|
8
|
+
|
9
|
+
Devise.setup do |config|
|
10
|
+
require "devise/orm/active_record"
|
11
|
+
end
|
12
|
+
|
13
|
+
module Scenario
|
14
|
+
class Application < Rails::Application
|
15
|
+
config.active_support.deprecation = :stderr
|
16
|
+
config.middleware.insert_before(Warden::Manager, Rack::OpenID)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
# Set up gems listed in the Gemfile.
|
4
|
+
gemfile = File.expand_path('../../../../Gemfile', __FILE__)
|
5
|
+
begin
|
6
|
+
ENV['BUNDLE_GEMFILE'] = gemfile
|
7
|
+
require 'bundler'
|
8
|
+
Bundler.setup
|
9
|
+
rescue Bundler::GemNotFound => e
|
10
|
+
STDERR.puts e.message
|
11
|
+
STDERR.puts "Try running `bundle install`."
|
12
|
+
exit!
|
13
|
+
end if File.exist?(gemfile)
|
14
|
+
|
15
|
+
$:.unshift File.expand_path('../../../../lib', __FILE__)
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Scenario::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
3
|
+
|
4
|
+
# In the development environment your application's code is reloaded on
|
5
|
+
# every request. This slows down response time but is perfect for development
|
6
|
+
# since you don't have to restart the webserver when you make code changes.
|
7
|
+
config.cache_classes = false
|
8
|
+
|
9
|
+
# Log error messages when you accidentally call methods on nil.
|
10
|
+
config.whiny_nils = true
|
11
|
+
|
12
|
+
# Show full error reports and disable caching
|
13
|
+
config.consider_all_requests_local = true
|
14
|
+
config.action_view.debug_rjs = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Don't care if the mailer can't send
|
18
|
+
config.action_mailer.raise_delivery_errors = false
|
19
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
Scenario::Application.configure do
|
2
|
+
# Settings specified here will take precedence over those in config/environment.rb
|
3
|
+
|
4
|
+
# The test environment is used exclusively to run your application's
|
5
|
+
# test suite. You never need to work with it otherwise. Remember that
|
6
|
+
# your test database is "scratch space" for the test suite and is wiped
|
7
|
+
# and recreated between test runs. Don't rely on the data there!
|
8
|
+
config.cache_classes = true
|
9
|
+
|
10
|
+
# Log error messages when you accidentally call methods on nil.
|
11
|
+
config.whiny_nils = true
|
12
|
+
|
13
|
+
# Show full error reports and disable caching
|
14
|
+
config.consider_all_requests_local = true
|
15
|
+
config.action_controller.perform_caching = false
|
16
|
+
|
17
|
+
# Disable request forgery protection in test environment
|
18
|
+
config.action_controller.allow_forgery_protection = false
|
19
|
+
|
20
|
+
# Tell Action Mailer not to deliver emails to the real world.
|
21
|
+
# The :test delivery method accumulates sent emails in the
|
22
|
+
# ActionMailer::Base.deliveries array.
|
23
|
+
config.action_mailer.delivery_method = :test
|
24
|
+
|
25
|
+
# Use SQL instead of Active Record's schema dumper when creating the test database.
|
26
|
+
# This is necessary if your schema can't be completely dumped by the schema dumper,
|
27
|
+
# like if you have constraints or database-specific column types
|
28
|
+
# config.active_record.schema_format = :sql
|
29
|
+
|
30
|
+
config.action_dispatch.show_exceptions = false
|
31
|
+
|
32
|
+
config.active_support.deprecation = :stderr
|
33
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
|
4
|
+
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
|
5
|
+
|
6
|
+
# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.
|
7
|
+
Rails.backtrace_cleaner.remove_silencers!
|
File without changes
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# This file is auto-generated from the current state of the database. Instead of editing this file,
|
2
|
+
# please use the migrations feature of Active Record to incrementally modify your database, and
|
3
|
+
# then regenerate this schema definition.
|
4
|
+
#
|
5
|
+
# Note that this schema.rb definition is the authoritative source for your database schema. If you need
|
6
|
+
# to create the application database on another system, you should be using db:schema:load, not running
|
7
|
+
# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
8
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
9
|
+
#
|
10
|
+
# It's strongly recommended to check this file into your version control system.
|
11
|
+
|
12
|
+
ActiveRecord::Schema.define(:version => 20100401102949) do
|
13
|
+
|
14
|
+
create_table "users", :force => true do |t|
|
15
|
+
t.string "email", :default => "", :null => false
|
16
|
+
t.string "encrypted_password", :default => "", :null => false
|
17
|
+
t.string "password_salt", :default => "", :null => false
|
18
|
+
t.string "username"
|
19
|
+
t.string "confirmation_token"
|
20
|
+
t.datetime "confirmed_at"
|
21
|
+
t.datetime "confirmation_sent_at"
|
22
|
+
t.string "reset_password_token"
|
23
|
+
t.string "remember_token"
|
24
|
+
t.datetime "remember_created_at"
|
25
|
+
t.integer "sign_in_count", :default => 0
|
26
|
+
t.datetime "current_sign_in_at"
|
27
|
+
t.datetime "last_sign_in_at"
|
28
|
+
t.string "current_sign_in_ip"
|
29
|
+
t.string "last_sign_in_ip"
|
30
|
+
t.integer "failed_attempts", :default => 0
|
31
|
+
t.string "unlock_token"
|
32
|
+
t.datetime "locked_at"
|
33
|
+
t.string "authentication_token"
|
34
|
+
t.datetime "created_at"
|
35
|
+
t.datetime "updated_at"
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
ENV["RAILS_ENV"] = "test"
|
2
|
+
$:.unshift File.dirname(__FILE__)
|
3
|
+
$:.unshift File.expand_path('../../lib', __FILE__)
|
4
|
+
|
5
|
+
require "scenario/config/environment"
|
6
|
+
require "rails/test_help"
|
7
|
+
require 'rspec/rails'
|
8
|
+
|
9
|
+
Webrat.configure do |config|
|
10
|
+
config.mode = :rails
|
11
|
+
config.open_error_files = false
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
@@ -0,0 +1,163 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Devise::Strategies::OpenidAuthenticatable do
|
4
|
+
include Rspec::Rails::RequestExampleGroup
|
5
|
+
|
6
|
+
def openid_params
|
7
|
+
{
|
8
|
+
"openid.identity"=>identity,
|
9
|
+
"openid.sig"=>"OWYQspA5zZhoqRFhfSMFX/hLkok=",
|
10
|
+
"openid.return_to"=>"http://www.example.com/users/sign_in?_method=post",
|
11
|
+
"openid.op_endpoint"=>"http://openid.example.org",
|
12
|
+
"openid.mode"=>"id_res",
|
13
|
+
"openid.response_nonce"=>"2010-01-11T00:00:00Zeru5O3ETpTNX0A",
|
14
|
+
"openid.ns"=>"http://specs.openid.net/auth/2.0",
|
15
|
+
"openid.ns.ext1"=>"http://openid.net/srv/ax/1.0",
|
16
|
+
"openid.ext1.value.ext0"=>"dimitrij@example.com",
|
17
|
+
"openid.ext1.type.ext0"=>"http://axschema.org/contact/email",
|
18
|
+
"openid.assoc_handle"=>"AOQobUeSdDcZUnQEYna4AZeTREaJiCDoii26u_x7wdrRrU5TqkGaqq9N",
|
19
|
+
"openid.claimed_id"=>identity,
|
20
|
+
"openid.signed"=>"op_endpoint,claimed_id,identity,return_to,response_nonce,assoc_handle,ns.ext1,ext1.mode,ext1.type.ext0,ext1.value.ext0"
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def stub_completion
|
25
|
+
ax_info = mock('AXInfo', :data => { "http://axschema.org/contact/email" => ["dimitrij@example.com"] })
|
26
|
+
OpenID::AX::FetchResponse.stubs(:from_success_response).returns(ax_info)
|
27
|
+
|
28
|
+
endpoint = mock('EndPoint', :claimed_id => identity)
|
29
|
+
success = OpenID::Consumer::SuccessResponse.new(endpoint, OpenID::Message.new, "ANY")
|
30
|
+
OpenID::Consumer.any_instance.stubs(:complete_id_res).returns(success)
|
31
|
+
end
|
32
|
+
|
33
|
+
def identity
|
34
|
+
@identity || 'http://openid.example.org/myid'
|
35
|
+
end
|
36
|
+
|
37
|
+
before do
|
38
|
+
User.create! do |u|
|
39
|
+
u.identity_url = "http://openid.example.org/myid"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
after do
|
44
|
+
User.delete_all
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "GET /protected/resource" do
|
48
|
+
before { get '/' }
|
49
|
+
|
50
|
+
it 'should redirect to sign-in' do
|
51
|
+
response.should be_redirect
|
52
|
+
response.should redirect_to('/users/sign_in')
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "GET /users/sign_in" do
|
57
|
+
before { get '/users/sign_in' }
|
58
|
+
|
59
|
+
it 'should render the page' do
|
60
|
+
response.should be_success
|
61
|
+
response.should render_template("sessions/new")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe "POST /users/sign_in (without a identity URL param)" do
|
66
|
+
before { post '/users/sign_in' }
|
67
|
+
|
68
|
+
it 'should render the sign-in form' do
|
69
|
+
response.should be_success
|
70
|
+
response.should render_template("sessions/new")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "POST /users/sign_in (with an empty identity URL param)" do
|
75
|
+
before { post '/users/sign_in', 'user' => { 'identity_url' => '' } }
|
76
|
+
|
77
|
+
it 'should render the sign-in form' do
|
78
|
+
response.should be_success
|
79
|
+
response.should render_template("sessions/new")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "POST /users/sign_in (with a valid identity URL param)" do
|
84
|
+
before do
|
85
|
+
Rack::OpenID.any_instance.stubs(:begin_authentication).returns([302, {'location' => 'http://openid.example.org/auth'}, ''])
|
86
|
+
post '/users/sign_in', 'user' => { 'identity_url' => 'http://openid.example.org/myid' }
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should forward request to provider' do
|
90
|
+
response.should be_redirect
|
91
|
+
response.should redirect_to('http://openid.example.org/auth')
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "POST /users/sign_in (from OpenID provider, with failure)" do
|
96
|
+
|
97
|
+
before do
|
98
|
+
post '/users/sign_in', "openid.mode"=>"failure", "openid.ns"=>"http://specs.openid.net/auth/2.0", "_method"=>"post"
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'should fail authentication with failure' do
|
102
|
+
response.should be_success
|
103
|
+
response.should render_template("sessions/new")
|
104
|
+
flash[:alert].should match(/failed/i)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "POST /users/sign_in (from OpenID provider, when cancelled failure)" do
|
109
|
+
|
110
|
+
before do
|
111
|
+
post '/users/sign_in', "openid.mode"=>"cancel", "openid.ns"=>"http://specs.openid.net/auth/2.0", "_method"=>"post"
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should fail authentication with failure' do
|
115
|
+
response.should be_success
|
116
|
+
response.should render_template("sessions/new")
|
117
|
+
flash[:alert].should match(/cancelled/i)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "POST /users/sign_in (from OpenID provider, success, user already present)" do
|
122
|
+
|
123
|
+
before do
|
124
|
+
stub_completion
|
125
|
+
post '/users/sign_in', openid_params.merge("_method"=>"post")
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'should accept authentication with success' do
|
129
|
+
response.should be_redirect
|
130
|
+
response.should redirect_to('http://www.example.com/')
|
131
|
+
flash[:notice].should match(/success/i)
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'should update user-records with retrieved information' do
|
135
|
+
User.should have(1).record
|
136
|
+
User.first.email.should == 'dimitrij@example.com'
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "POST /users/sign_in (from OpenID provider, success, new user)" do
|
141
|
+
|
142
|
+
before do
|
143
|
+
@identity = 'http://openid.example.org/newid'
|
144
|
+
stub_completion
|
145
|
+
post '/users/sign_in', openid_params.merge("_method"=>"post")
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'should accept authentication with success' do
|
149
|
+
response.should be_redirect
|
150
|
+
response.should redirect_to('http://www.example.com/')
|
151
|
+
flash[:notice].should match(/success/i)
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should auto-create user-records (if supported)' do
|
155
|
+
User.should have(2).records
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'should update new user-records with retrieved information' do
|
159
|
+
User.order(:id).last.email.should == 'dimitrij@example.com'
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: devise_openid_authenticatable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: -1710980388
|
4
5
|
prerelease: true
|
5
6
|
segments:
|
6
7
|
- 1
|
7
8
|
- 0
|
8
9
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.0.
|
10
|
+
- alpha6
|
11
|
+
version: 1.0.0.alpha6
|
11
12
|
platform: ruby
|
12
13
|
authors:
|
13
14
|
- Nat Budin
|
@@ -15,7 +16,7 @@ autorequire:
|
|
15
16
|
bindir: bin
|
16
17
|
cert_chain: []
|
17
18
|
|
18
|
-
date: 2010-08-
|
19
|
+
date: 2010-08-19 00:00:00 -04:00
|
19
20
|
default_executable:
|
20
21
|
dependencies:
|
21
22
|
- !ruby/object:Gem::Dependency
|
@@ -26,6 +27,7 @@ dependencies:
|
|
26
27
|
requirements:
|
27
28
|
- - ">="
|
28
29
|
- !ruby/object:Gem::Version
|
30
|
+
hash: 27
|
29
31
|
segments:
|
30
32
|
- 1
|
31
33
|
- 0
|
@@ -41,6 +43,7 @@ dependencies:
|
|
41
43
|
requirements:
|
42
44
|
- - ">="
|
43
45
|
- !ruby/object:Gem::Version
|
46
|
+
hash: 17
|
44
47
|
segments:
|
45
48
|
- 1
|
46
49
|
- 0
|
@@ -59,6 +62,7 @@ extra_rdoc_files:
|
|
59
62
|
files:
|
60
63
|
- .gitignore
|
61
64
|
- CHANGELOG.rdoc
|
65
|
+
- Gemfile
|
62
66
|
- README.md
|
63
67
|
- Rakefile
|
64
68
|
- VERSION
|
@@ -69,6 +73,29 @@ files:
|
|
69
73
|
- lib/devise_openid_authenticatable/schema.rb
|
70
74
|
- lib/devise_openid_authenticatable/strategy.rb
|
71
75
|
- rails/init.rb
|
76
|
+
- spec/model_spec.rb
|
77
|
+
- spec/scenario/app/controllers/application_controller.rb
|
78
|
+
- spec/scenario/app/controllers/home_controller.rb
|
79
|
+
- spec/scenario/app/controllers/sessions_controller.rb
|
80
|
+
- spec/scenario/app/models/user.rb
|
81
|
+
- spec/scenario/app/views/sessions/new.html.erb
|
82
|
+
- spec/scenario/config.ru
|
83
|
+
- spec/scenario/config/application.rb
|
84
|
+
- spec/scenario/config/boot.rb
|
85
|
+
- spec/scenario/config/database.yml
|
86
|
+
- spec/scenario/config/environment.rb
|
87
|
+
- spec/scenario/config/environments/development.rb
|
88
|
+
- spec/scenario/config/environments/test.rb
|
89
|
+
- spec/scenario/config/initializers/backtrace_silencers.rb
|
90
|
+
- spec/scenario/config/initializers/inflections.rb
|
91
|
+
- spec/scenario/config/initializers/secret_token.rb
|
92
|
+
- spec/scenario/config/routes.rb
|
93
|
+
- spec/scenario/db/migrate/20100401102949_create_tables.rb
|
94
|
+
- spec/scenario/db/schema.rb
|
95
|
+
- spec/spec_helper.rb
|
96
|
+
- spec/strategy_spec.rb
|
97
|
+
- spec/support/migrations.rb
|
98
|
+
- spec/support/patches.rb
|
72
99
|
has_rdoc: true
|
73
100
|
homepage: http://github.com/nbudin/devise_openid_authenticatable
|
74
101
|
licenses: []
|
@@ -83,6 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
110
|
requirements:
|
84
111
|
- - ">="
|
85
112
|
- !ruby/object:Gem::Version
|
113
|
+
hash: 3
|
86
114
|
segments:
|
87
115
|
- 0
|
88
116
|
version: "0"
|
@@ -91,6 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
119
|
requirements:
|
92
120
|
- - ">"
|
93
121
|
- !ruby/object:Gem::Version
|
122
|
+
hash: 25
|
94
123
|
segments:
|
95
124
|
- 1
|
96
125
|
- 3
|
@@ -103,5 +132,24 @@ rubygems_version: 1.3.7
|
|
103
132
|
signing_key:
|
104
133
|
specification_version: 3
|
105
134
|
summary: OpenID authentication module for Devise
|
106
|
-
test_files:
|
107
|
-
|
135
|
+
test_files:
|
136
|
+
- spec/model_spec.rb
|
137
|
+
- spec/scenario/app/controllers/application_controller.rb
|
138
|
+
- spec/scenario/app/controllers/home_controller.rb
|
139
|
+
- spec/scenario/app/controllers/sessions_controller.rb
|
140
|
+
- spec/scenario/app/models/user.rb
|
141
|
+
- spec/scenario/config/application.rb
|
142
|
+
- spec/scenario/config/boot.rb
|
143
|
+
- spec/scenario/config/environment.rb
|
144
|
+
- spec/scenario/config/environments/development.rb
|
145
|
+
- spec/scenario/config/environments/test.rb
|
146
|
+
- spec/scenario/config/initializers/backtrace_silencers.rb
|
147
|
+
- spec/scenario/config/initializers/inflections.rb
|
148
|
+
- spec/scenario/config/initializers/secret_token.rb
|
149
|
+
- spec/scenario/config/routes.rb
|
150
|
+
- spec/scenario/db/migrate/20100401102949_create_tables.rb
|
151
|
+
- spec/scenario/db/schema.rb
|
152
|
+
- spec/spec_helper.rb
|
153
|
+
- spec/strategy_spec.rb
|
154
|
+
- spec/support/migrations.rb
|
155
|
+
- spec/support/patches.rb
|