omniauth 0.3.0.rc3 → 1.0.0.pr1
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/.gemtest +0 -0
- data/.gitignore +56 -0
- data/.rspec +2 -0
- data/.travis.yml +7 -0
- data/.yardopts +4 -0
- data/Gemfile +11 -0
- data/Guardfile +10 -0
- data/{LICENSE.md → LICENSE} +1 -1
- data/README.md +130 -152
- data/Rakefile +6 -0
- data/lib/omniauth/auth_hash.rb +47 -0
- data/lib/omniauth/builder.rb +33 -0
- data/lib/omniauth/form.rb +191 -0
- data/lib/omniauth/strategy.rb +429 -0
- data/lib/omniauth/test/phony_session.rb +8 -0
- data/lib/omniauth/test/strategy_macros.rb +34 -0
- data/lib/omniauth/test/strategy_test_case.rb +49 -0
- data/lib/omniauth/test.rb +12 -0
- data/lib/omniauth/version.rb +1 -17
- data/lib/omniauth.rb +135 -6
- data/omniauth.gemspec +28 -0
- data/spec/omniauth/auth_hash_spec.rb +103 -0
- data/spec/omniauth/builder_spec.rb +20 -0
- data/spec/omniauth/strategy_spec.rb +601 -0
- data/spec/omniauth_spec.rb +82 -0
- data/spec/spec_helper.rb +12 -0
- metadata +138 -143
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module OmniAuth
|
|
2
|
+
|
|
3
|
+
# Support for testing OmniAuth strategies.
|
|
4
|
+
module Test
|
|
5
|
+
|
|
6
|
+
autoload :PhonySession, 'omniauth/test/phony_session'
|
|
7
|
+
autoload :StrategyMacros, 'omniauth/test/strategy_macros'
|
|
8
|
+
autoload :StrategyTestCase, 'omniauth/test/strategy_test_case'
|
|
9
|
+
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
end
|
data/lib/omniauth/version.rb
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
1
|
module OmniAuth
|
|
2
|
-
|
|
3
|
-
unless defined?(::OmniAuth::Version::MAJOR)
|
|
4
|
-
MAJOR = 0
|
|
5
|
-
end
|
|
6
|
-
unless defined?(::OmniAuth::Version::MINOR)
|
|
7
|
-
MINOR = 3
|
|
8
|
-
end
|
|
9
|
-
unless defined?(::OmniAuth::Version::PATCH)
|
|
10
|
-
PATCH = 0
|
|
11
|
-
end
|
|
12
|
-
unless defined?(::OmniAuth::Version::PRE)
|
|
13
|
-
PRE = "rc3"
|
|
14
|
-
end
|
|
15
|
-
unless defined?(::OmniAuth::Version::STRING)
|
|
16
|
-
STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.')
|
|
17
|
-
end
|
|
18
|
-
end
|
|
2
|
+
VERSION = "1.0.0.pr1"
|
|
19
3
|
end
|
data/lib/omniauth.rb
CHANGED
|
@@ -1,6 +1,135 @@
|
|
|
1
|
-
require '
|
|
2
|
-
require '
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
require 'rack'
|
|
2
|
+
require 'singleton'
|
|
3
|
+
|
|
4
|
+
module OmniAuth
|
|
5
|
+
module Strategies; end
|
|
6
|
+
|
|
7
|
+
autoload :Builder, 'omniauth/builder'
|
|
8
|
+
autoload :Strategy, 'omniauth/strategy'
|
|
9
|
+
autoload :Test, 'omniauth/test'
|
|
10
|
+
autoload :Form, 'omniauth/form'
|
|
11
|
+
autoload :AuthHash, 'omniauth/auth_hash'
|
|
12
|
+
|
|
13
|
+
def self.strategies
|
|
14
|
+
@@strategies ||= []
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class Configuration
|
|
18
|
+
include Singleton
|
|
19
|
+
|
|
20
|
+
@@defaults = {
|
|
21
|
+
:camelizations => {},
|
|
22
|
+
:path_prefix => '/auth',
|
|
23
|
+
:on_failure => Proc.new do |env|
|
|
24
|
+
message_key = env['omniauth.error.type']
|
|
25
|
+
new_path = "#{OmniAuth.config.path_prefix}/failure?message=#{message_key}"
|
|
26
|
+
[302, {'Location' => new_path, 'Content-Type'=> 'text/html'}, []]
|
|
27
|
+
end,
|
|
28
|
+
:form_css => Form::DEFAULT_CSS,
|
|
29
|
+
:test_mode => false,
|
|
30
|
+
:allowed_request_methods => [:get, :post],
|
|
31
|
+
:mock_auth => {
|
|
32
|
+
:default => {
|
|
33
|
+
'provider' => 'default',
|
|
34
|
+
'uid' => '1234',
|
|
35
|
+
'name' => 'Bob Example'
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
def self.defaults
|
|
41
|
+
@@defaults
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def initialize
|
|
45
|
+
@@defaults.each_pair{|k,v| self.send("#{k}=",v)}
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def on_failure(&block)
|
|
49
|
+
if block_given?
|
|
50
|
+
@on_failure = block
|
|
51
|
+
else
|
|
52
|
+
@on_failure
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def add_mock(provider, mock={})
|
|
57
|
+
# Stringify keys recursively one level.
|
|
58
|
+
mock.keys.each do |key|
|
|
59
|
+
mock[key.to_s] = mock.delete(key)
|
|
60
|
+
end
|
|
61
|
+
mock.each_pair do |key, val|
|
|
62
|
+
if val.is_a? Hash
|
|
63
|
+
val.keys.each do |subkey|
|
|
64
|
+
val[subkey.to_s] = val.delete(subkey)
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# Merge with the default mock and ensure provider is correct.
|
|
70
|
+
mock = self.mock_auth[:default].dup.merge(mock)
|
|
71
|
+
mock["provider"] = provider.to_s
|
|
72
|
+
|
|
73
|
+
# Add it to the mocks.
|
|
74
|
+
self.mock_auth[provider.to_sym] = mock
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# This is a convenience method to be used by strategy authors
|
|
78
|
+
# so that they can add special cases to the camelization utility
|
|
79
|
+
# method that allows OmniAuth::Builder to work.
|
|
80
|
+
#
|
|
81
|
+
# @param name [String] The underscored name, e.g. `oauth`
|
|
82
|
+
# @param camelized [String] The properly camelized name, e.g. 'OAuth'
|
|
83
|
+
def add_camelization(name, camelized)
|
|
84
|
+
self.camelizations[name.to_s] = camelized.to_s
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
attr_writer :on_failure
|
|
88
|
+
attr_accessor :path_prefix, :allowed_request_methods, :form_css, :test_mode, :mock_auth, :full_host, :camelizations
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def self.config
|
|
92
|
+
Configuration.instance
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def self.configure
|
|
96
|
+
yield config
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def self.mock_auth_for(provider)
|
|
100
|
+
config.mock_auth[provider.to_sym] || config.mock_auth[:default]
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
module Utils
|
|
104
|
+
module_function
|
|
105
|
+
|
|
106
|
+
def form_css
|
|
107
|
+
"<style type='text/css'>#{OmniAuth.config.form_css}</style>"
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def deep_merge(hash, other_hash)
|
|
111
|
+
target = hash.dup
|
|
112
|
+
|
|
113
|
+
other_hash.keys.each do |key|
|
|
114
|
+
if other_hash[key].is_a? ::Hash and hash[key].is_a? ::Hash
|
|
115
|
+
target[key] = deep_merge(target[key],other_hash[key])
|
|
116
|
+
next
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
target[key] = other_hash[key]
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
target
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
def camelize(word, first_letter_in_uppercase = true)
|
|
126
|
+
return OmniAuth.config.camelizations[word.to_s] if OmniAuth.config.camelizations[word.to_s]
|
|
127
|
+
|
|
128
|
+
if first_letter_in_uppercase
|
|
129
|
+
word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
|
|
130
|
+
else
|
|
131
|
+
word.first + camelize(word)[1..-1]
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
data/omniauth.gemspec
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# encoding: utf-8
|
|
2
|
+
require File.expand_path('../lib/omniauth/version', __FILE__)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |gem|
|
|
5
|
+
gem.name = 'omniauth'
|
|
6
|
+
gem.description = %q{A generalized Rack framework for multiple-provider authentication.}
|
|
7
|
+
gem.authors = ['Michael Bleigh', 'Erik Michaels-Ober']
|
|
8
|
+
gem.email = ['michael@intridea.com', 'sferik@gmail.com']
|
|
9
|
+
|
|
10
|
+
gem.add_runtime_dependency 'rack'
|
|
11
|
+
gem.add_runtime_dependency 'hashie'
|
|
12
|
+
|
|
13
|
+
gem.add_development_dependency 'maruku', '~> 0.6'
|
|
14
|
+
gem.add_development_dependency 'simplecov', '~> 0.4'
|
|
15
|
+
gem.add_development_dependency 'rack-test', '~> 0.5'
|
|
16
|
+
gem.add_development_dependency 'rake', '~> 0.8'
|
|
17
|
+
gem.add_development_dependency 'rdiscount', '~> 1.6'
|
|
18
|
+
gem.add_development_dependency 'rspec', '~> 2.5'
|
|
19
|
+
gem.add_development_dependency 'yard', '~> 0.7'
|
|
20
|
+
|
|
21
|
+
gem.version = OmniAuth::VERSION
|
|
22
|
+
gem.files = `git ls-files`.split("\n")
|
|
23
|
+
gem.homepage = 'http://github.com/intridea/omniauth'
|
|
24
|
+
gem.require_paths = ['lib']
|
|
25
|
+
gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if gem.respond_to? :required_rubygems_version=
|
|
26
|
+
gem.summary = gem.description
|
|
27
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
28
|
+
end
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe OmniAuth::AuthHash do
|
|
4
|
+
subject{ OmniAuth::AuthHash.new }
|
|
5
|
+
it 'should convert a supplied info key into an InfoHash object' do
|
|
6
|
+
subject.info = {:first_name => 'Awesome'}
|
|
7
|
+
subject.info.should be_kind_of(OmniAuth::AuthHash::InfoHash)
|
|
8
|
+
subject.info.first_name.should == 'Awesome'
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
describe '#valid?' do
|
|
12
|
+
subject{ OmniAuth::AuthHash.new(:uid => '123', :provider => 'example', :info => {:name => 'Steven'}) }
|
|
13
|
+
|
|
14
|
+
it 'should be valid with the right parameters' do
|
|
15
|
+
subject.should be_valid
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'should require a uid' do
|
|
19
|
+
subject.uid = nil
|
|
20
|
+
subject.should_not be_valid
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'should require a provider' do
|
|
24
|
+
subject.provider = nil
|
|
25
|
+
subject.should_not be_valid
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it 'should require a name in the user info hash' do
|
|
29
|
+
subject.info.name = nil
|
|
30
|
+
subject.should_not be_valid?
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
describe '#name' do
|
|
35
|
+
subject{ OmniAuth::AuthHash.new(
|
|
36
|
+
:info => {
|
|
37
|
+
:name => 'Phillip J. Fry',
|
|
38
|
+
:first_name => 'Phillip',
|
|
39
|
+
:last_name => 'Fry',
|
|
40
|
+
:nickname => 'meatbag',
|
|
41
|
+
:email => 'fry@planetexpress.com'
|
|
42
|
+
})}
|
|
43
|
+
|
|
44
|
+
it 'should default to the name key' do
|
|
45
|
+
subject.info.name.should == 'Phillip J. Fry'
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it 'should fall back to go to first_name last_name concatenation' do
|
|
49
|
+
subject.info.name = nil
|
|
50
|
+
subject.info.name.should == 'Phillip Fry'
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'should display only a first or last name if only that is available' do
|
|
54
|
+
subject.info.name = nil
|
|
55
|
+
subject.info.first_name = nil
|
|
56
|
+
subject.info.name.should == 'Fry'
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it 'should display the nickname if no name, first, or last is available' do
|
|
60
|
+
subject.info.name = nil
|
|
61
|
+
%w(first_name last_name).each{|k| subject.info[k] = nil}
|
|
62
|
+
subject.info.name.should == 'meatbag'
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it 'should display the email if no name, first, last, or nick is available' do
|
|
66
|
+
subject.info.name = nil
|
|
67
|
+
%w(first_name last_name nickname).each{|k| subject.info[k] = nil}
|
|
68
|
+
subject.info.name.should == 'fry@planetexpress.com'
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
describe '#to_hash' do
|
|
73
|
+
subject{ OmniAuth::AuthHash.new(:uid => '123', :provider => 'test', :name => 'Bob Example')}
|
|
74
|
+
let(:hash){ subject.to_hash }
|
|
75
|
+
|
|
76
|
+
it 'should be a plain old hash' do
|
|
77
|
+
hash.class.should == ::Hash
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
it 'should have string keys' do
|
|
81
|
+
hash.keys.should be_include('uid')
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it 'should convert an info hash as well' do
|
|
85
|
+
subject.info = {:first_name => 'Bob', :last_name => 'Example'}
|
|
86
|
+
subject.info.class.should == OmniAuth::AuthHash::InfoHash
|
|
87
|
+
subject.to_hash['info'].class.should == ::Hash
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it 'should supply the calculated name in the converted hash' do
|
|
91
|
+
subject.info = {:first_name => 'Bob', :last_name => 'Examplar'}
|
|
92
|
+
hash['info']['name'].should == 'Bob Examplar'
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
describe OmniAuth::AuthHash::InfoHash do
|
|
97
|
+
describe '#valid?' do
|
|
98
|
+
it 'should be valid if there is a name' do
|
|
99
|
+
OmniAuth::AuthHash::InfoHash.new(:name => 'Awesome').should be_valid
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require File.expand_path('../../spec_helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
describe OmniAuth::Builder do
|
|
4
|
+
describe '#provider' do
|
|
5
|
+
it 'should translate a symbol to a constant' do
|
|
6
|
+
OmniAuth::Strategies.should_receive(:const_get).with('MyStrategy').and_return(Class.new)
|
|
7
|
+
OmniAuth::Builder.new(nil) do
|
|
8
|
+
provider :my_strategy
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it 'should also just accept a class' do
|
|
13
|
+
class ::ExampleClass; end
|
|
14
|
+
|
|
15
|
+
lambda{ OmniAuth::Builder.new(nil) do
|
|
16
|
+
provider ::ExampleClass
|
|
17
|
+
end }.should_not raise_error
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|