omniauth-rightsignature 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.rubocop.yml +60 -0
- data/.travis.yml +26 -0
- data/.yardopts +4 -0
- data/Gemfile +33 -0
- data/Gemfile.rack-1.3.x +25 -0
- data/Guardfile +10 -0
- data/LICENSE.md +19 -0
- data/README.md +167 -0
- data/Rakefile +17 -0
- data/lib/omniauth/auth_hash.rb +54 -0
- data/lib/omniauth/builder.rb +62 -0
- data/lib/omniauth/failure_endpoint.rb +44 -0
- data/lib/omniauth/form.css +81 -0
- data/lib/omniauth/form.rb +111 -0
- data/lib/omniauth/rightsignature/version.rb +5 -0
- data/lib/omniauth/strategies/rightsignature.rb +44 -0
- data/lib/omniauth/strategy.rb +501 -0
- data/lib/omniauth/test.rb +8 -0
- data/lib/omniauth/version.rb +3 -0
- data/lib/omniauth-rightsignature.rb +1 -0
- data/lib/omniauth.rb +170 -0
- data/omniauth-rightsignature.gemspec +24 -0
- data/spec/helper.rb +55 -0
- data/spec/omniauth/auth_hash_spec.rb +109 -0
- data/spec/omniauth/builder_spec.rb +50 -0
- data/spec/omniauth/failure_endpoint_spec.rb +58 -0
- data/spec/omniauth/form_spec.rb +23 -0
- data/spec/omniauth/strategies/developer_spec.rb +73 -0
- data/spec/omniauth/strategy_spec.rb +765 -0
- data/spec/omniauth_spec.rb +145 -0
- metadata +35 -3
@@ -0,0 +1,8 @@
|
|
1
|
+
module OmniAuth
|
2
|
+
# Support for testing OmniAuth strategies.
|
3
|
+
module Test
|
4
|
+
autoload :PhonySession, 'omniauth/test/phony_session'
|
5
|
+
autoload :StrategyMacros, 'omniauth/test/strategy_macros'
|
6
|
+
autoload :StrategyTestCase, 'omniauth/test/strategy_test_case'
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'omniauth/rightsignature'
|
data/lib/omniauth.rb
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
require 'rack'
|
2
|
+
require 'singleton'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
module OmniAuth
|
6
|
+
class Error < StandardError; end
|
7
|
+
|
8
|
+
module Strategies
|
9
|
+
autoload :Developer, 'omniauth/strategies/developer'
|
10
|
+
end
|
11
|
+
|
12
|
+
autoload :Builder, 'omniauth/builder'
|
13
|
+
autoload :Strategy, 'omniauth/strategy'
|
14
|
+
autoload :Test, 'omniauth/test'
|
15
|
+
autoload :Form, 'omniauth/form'
|
16
|
+
autoload :AuthHash, 'omniauth/auth_hash'
|
17
|
+
autoload :FailureEndpoint, 'omniauth/failure_endpoint'
|
18
|
+
|
19
|
+
def self.strategies
|
20
|
+
@strategies ||= []
|
21
|
+
end
|
22
|
+
|
23
|
+
class Configuration
|
24
|
+
include Singleton
|
25
|
+
|
26
|
+
def self.default_logger
|
27
|
+
logger = Logger.new(STDOUT)
|
28
|
+
logger.progname = 'omniauth'
|
29
|
+
logger
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.defaults
|
33
|
+
@defaults ||= {
|
34
|
+
:camelizations => {},
|
35
|
+
:path_prefix => '/auth',
|
36
|
+
:on_failure => OmniAuth::FailureEndpoint,
|
37
|
+
:failure_raise_out_environments => ['development'],
|
38
|
+
:before_request_phase => nil,
|
39
|
+
:before_callback_phase => nil,
|
40
|
+
:before_options_phase => nil,
|
41
|
+
:form_css => Form::DEFAULT_CSS,
|
42
|
+
:test_mode => false,
|
43
|
+
:logger => default_logger,
|
44
|
+
:allowed_request_methods => [:get, :post],
|
45
|
+
:mock_auth => {:default => AuthHash.new('provider' => 'default', 'uid' => '1234', 'info' => {'name' => 'Example User'})},
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
49
|
+
def initialize
|
50
|
+
self.class.defaults.each_pair { |k, v| send("#{k}=", v) }
|
51
|
+
end
|
52
|
+
|
53
|
+
def on_failure(&block)
|
54
|
+
if block_given?
|
55
|
+
@on_failure = block
|
56
|
+
else
|
57
|
+
@on_failure
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def before_callback_phase(&block)
|
62
|
+
if block_given?
|
63
|
+
@before_callback_phase = block
|
64
|
+
else
|
65
|
+
@before_callback_phase
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def before_options_phase(&block)
|
70
|
+
if block_given?
|
71
|
+
@before_options_phase = block
|
72
|
+
else
|
73
|
+
@before_options_phase
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def before_request_phase(&block)
|
78
|
+
if block_given?
|
79
|
+
@before_request_phase = block
|
80
|
+
else
|
81
|
+
@before_request_phase
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def add_mock(provider, mock = {})
|
86
|
+
# Stringify keys recursively one level.
|
87
|
+
mock.keys.each do |key|
|
88
|
+
mock[key.to_s] = mock.delete(key)
|
89
|
+
end
|
90
|
+
mock.each_pair do |_key, val|
|
91
|
+
if val.is_a? Hash
|
92
|
+
val.keys.each do |subkey|
|
93
|
+
val[subkey.to_s] = val.delete(subkey)
|
94
|
+
end
|
95
|
+
else
|
96
|
+
next
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# Merge with the default mock and ensure provider is correct.
|
101
|
+
mock = mock_auth[:default].dup.merge(mock)
|
102
|
+
mock['provider'] = provider.to_s
|
103
|
+
|
104
|
+
# Add it to the mocks.
|
105
|
+
mock_auth[provider.to_sym] = mock
|
106
|
+
end
|
107
|
+
|
108
|
+
# This is a convenience method to be used by strategy authors
|
109
|
+
# so that they can add special cases to the camelization utility
|
110
|
+
# method that allows OmniAuth::Builder to work.
|
111
|
+
#
|
112
|
+
# @param name [String] The underscored name, e.g. `oauth`
|
113
|
+
# @param camelized [String] The properly camelized name, e.g. 'OAuth'
|
114
|
+
def add_camelization(name, camelized)
|
115
|
+
camelizations[name.to_s] = camelized.to_s
|
116
|
+
end
|
117
|
+
|
118
|
+
attr_writer :on_failure, :before_callback_phase, :before_options_phase, :before_request_phase
|
119
|
+
attr_accessor :failure_raise_out_environments, :path_prefix, :allowed_request_methods, :form_css, :test_mode, :mock_auth, :full_host, :camelizations, :logger
|
120
|
+
end
|
121
|
+
|
122
|
+
def self.config
|
123
|
+
Configuration.instance
|
124
|
+
end
|
125
|
+
|
126
|
+
def self.configure
|
127
|
+
yield config
|
128
|
+
end
|
129
|
+
|
130
|
+
def self.logger
|
131
|
+
config.logger
|
132
|
+
end
|
133
|
+
|
134
|
+
def self.mock_auth_for(provider)
|
135
|
+
config.mock_auth[provider.to_sym] || config.mock_auth[:default]
|
136
|
+
end
|
137
|
+
|
138
|
+
module Utils
|
139
|
+
module_function
|
140
|
+
|
141
|
+
def form_css
|
142
|
+
"<style type='text/css'>#{OmniAuth.config.form_css}</style>"
|
143
|
+
end
|
144
|
+
|
145
|
+
def deep_merge(hash, other_hash)
|
146
|
+
target = hash.dup
|
147
|
+
|
148
|
+
other_hash.keys.each do |key|
|
149
|
+
if other_hash[key].is_a?(::Hash) && hash[key].is_a?(::Hash)
|
150
|
+
target[key] = deep_merge(target[key], other_hash[key])
|
151
|
+
next
|
152
|
+
end
|
153
|
+
|
154
|
+
target[key] = other_hash[key]
|
155
|
+
end
|
156
|
+
|
157
|
+
target
|
158
|
+
end
|
159
|
+
|
160
|
+
def camelize(word, first_letter_in_uppercase = true)
|
161
|
+
return OmniAuth.config.camelizations[word.to_s] if OmniAuth.config.camelizations[word.to_s]
|
162
|
+
|
163
|
+
if first_letter_in_uppercase
|
164
|
+
word.to_s.gsub(/\/(.?)/) { '::' + Regexp.last_match[1].upcase }.gsub(/(^|_)(.)/) { Regexp.last_match[2].upcase }
|
165
|
+
else
|
166
|
+
word.first + camelize(word)[1..-1]
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.expand_path('../lib/omniauth/rightsignature/version', __FILE__)
|
3
|
+
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = 'omniauth-rightsignature'
|
7
|
+
gem.version = OmniAuth::Rightsignature::VERSION
|
8
|
+
gem.homepage = 'https://github.com/DeepikaaSubramaniam21/omniauth-rightsignature/'
|
9
|
+
gem.author = "Deepikaa Subramaniam"
|
10
|
+
gem.email = 'deepikaa.subramaniam@citrix.com'
|
11
|
+
gem.description = 'RightSignature strategy for OmniAuth 1.0'
|
12
|
+
gem.summary = gem.description
|
13
|
+
gem.add_dependency "omniauth-oauth", "~> 1.0"
|
14
|
+
gem.add_development_dependency 'rake', '~> 0.9'
|
15
|
+
gem.add_development_dependency 'rdiscount', '~> 1.6'
|
16
|
+
gem.add_development_dependency 'rspec', '~> 2.7'
|
17
|
+
gem.add_development_dependency 'simplecov', '~> 0.5'
|
18
|
+
gem.add_development_dependency 'yard', '~> 0.7'
|
19
|
+
gem.add_development_dependency 'webmock', '~> 1.7'
|
20
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
|
21
|
+
gem.files = `git ls-files`.split("\n")
|
22
|
+
#gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
gem.require_paths = ['lib']
|
24
|
+
end
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
if RUBY_VERSION >= '1.9'
|
2
|
+
require 'simplecov'
|
3
|
+
require 'coveralls'
|
4
|
+
|
5
|
+
SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter]
|
6
|
+
|
7
|
+
SimpleCov.start do
|
8
|
+
add_filter '/spec'
|
9
|
+
minimum_coverage(93.05)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
require 'rspec'
|
14
|
+
require 'rack/test'
|
15
|
+
require 'omniauth'
|
16
|
+
require 'omniauth/test'
|
17
|
+
|
18
|
+
OmniAuth.config.logger = Logger.new('/dev/null')
|
19
|
+
|
20
|
+
RSpec.configure do |config|
|
21
|
+
config.include Rack::Test::Methods
|
22
|
+
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
23
|
+
config.expect_with :rspec do |c|
|
24
|
+
c.syntax = :expect
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class ExampleStrategy
|
29
|
+
include OmniAuth::Strategy
|
30
|
+
attr_reader :last_env
|
31
|
+
option :name, 'test'
|
32
|
+
|
33
|
+
def call(env)
|
34
|
+
self.call!(env)
|
35
|
+
end
|
36
|
+
|
37
|
+
def initialize(*args, &block)
|
38
|
+
super
|
39
|
+
@fail = nil
|
40
|
+
end
|
41
|
+
|
42
|
+
def request_phase
|
43
|
+
@fail = fail!(options[:failure]) if options[:failure]
|
44
|
+
@last_env = env
|
45
|
+
return @fail if @fail
|
46
|
+
fail('Request Phase')
|
47
|
+
end
|
48
|
+
|
49
|
+
def callback_phase
|
50
|
+
@fail = fail!(options[:failure]) if options[:failure]
|
51
|
+
@last_env = env
|
52
|
+
return @fail if @fail
|
53
|
+
fail('Callback Phase')
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe OmniAuth::AuthHash do
|
4
|
+
subject { OmniAuth::AuthHash.new }
|
5
|
+
it 'converts a supplied info key into an InfoHash object' do
|
6
|
+
subject.info = {:first_name => 'Awesome'}
|
7
|
+
expect(subject.info).to be_kind_of(OmniAuth::AuthHash::InfoHash)
|
8
|
+
expect(subject.info.first_name).to eq('Awesome')
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#valid?' do
|
12
|
+
subject { OmniAuth::AuthHash.new(:uid => '123', :provider => 'example', :info => {:name => 'Steven'}) }
|
13
|
+
|
14
|
+
it 'is valid with the right parameters' do
|
15
|
+
expect(subject).to be_valid
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'requires a uid' do
|
19
|
+
subject.uid = nil
|
20
|
+
expect(subject).not_to be_valid
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'requires a provider' do
|
24
|
+
subject.provider = nil
|
25
|
+
expect(subject).not_to be_valid
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'requires a name in the user info hash' do
|
29
|
+
subject.info.name = nil
|
30
|
+
expect(subject).not_to be_valid
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#name' do
|
35
|
+
subject do
|
36
|
+
OmniAuth::AuthHash.new(:info => {
|
37
|
+
:name => 'Phillip J. Fry',
|
38
|
+
:first_name => 'Phillip',
|
39
|
+
:last_name => 'Fry',
|
40
|
+
:nickname => 'meatbag',
|
41
|
+
:email => 'fry@planetexpress.com',
|
42
|
+
})
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'defaults to the name key' do
|
46
|
+
expect(subject.info.name).to eq('Phillip J. Fry')
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'falls back to go to first_name last_name concatenation' do
|
50
|
+
subject.info.name = nil
|
51
|
+
expect(subject.info.name).to eq('Phillip Fry')
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'displays only a first or last name if only that is available' do
|
55
|
+
subject.info.name = nil
|
56
|
+
subject.info.first_name = nil
|
57
|
+
expect(subject.info.name).to eq('Fry')
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'displays the nickname if no name, first, or last is available' do
|
61
|
+
subject.info.name = nil
|
62
|
+
%w(first_name last_name).each { |k| subject.info[k] = nil }
|
63
|
+
expect(subject.info.name).to eq('meatbag')
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'displays the email if no name, first, last, or nick is available' do
|
67
|
+
subject.info.name = nil
|
68
|
+
%w(first_name last_name nickname).each { |k| subject.info[k] = nil }
|
69
|
+
expect(subject.info.name).to eq('fry@planetexpress.com')
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#to_hash' do
|
74
|
+
subject { OmniAuth::AuthHash.new(:uid => '123', :provider => 'test', :name => 'Example User') }
|
75
|
+
let(:hash) { subject.to_hash }
|
76
|
+
|
77
|
+
it 'is a plain old hash' do
|
78
|
+
expect(hash.class).to eq(::Hash)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'has string keys' do
|
82
|
+
expect(hash.keys).to be_include('uid')
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'converts an info hash as well' do
|
86
|
+
subject.info = {:first_name => 'Example', :last_name => 'User'}
|
87
|
+
expect(subject.info.class).to eq(OmniAuth::AuthHash::InfoHash)
|
88
|
+
expect(subject.to_hash['info'].class).to eq(::Hash)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'supplies the calculated name in the converted hash' do
|
92
|
+
subject.info = {:first_name => 'Examplar', :last_name => 'User'}
|
93
|
+
expect(hash['info']['name']).to eq('Examplar User')
|
94
|
+
end
|
95
|
+
|
96
|
+
it "does not pollute the URL hash with 'name' etc" do
|
97
|
+
subject.info = {'urls' => {'Homepage' => 'http://homepage.com'}}
|
98
|
+
expect(subject.to_hash['info']['urls']).to eq('Homepage' => 'http://homepage.com')
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe OmniAuth::AuthHash::InfoHash do
|
103
|
+
describe '#valid?' do
|
104
|
+
it 'is valid if there is a name' do
|
105
|
+
expect(OmniAuth::AuthHash::InfoHash.new(:name => 'Awesome')).to be_valid
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe OmniAuth::Builder do
|
4
|
+
describe '#provider' do
|
5
|
+
it 'translates a symbol to a constant' do
|
6
|
+
expect(OmniAuth::Strategies).to 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 'accepts a class' do
|
13
|
+
class ExampleClass; end
|
14
|
+
|
15
|
+
expect do
|
16
|
+
OmniAuth::Builder.new(nil) do
|
17
|
+
provider ::ExampleClass
|
18
|
+
end
|
19
|
+
end.not_to raise_error
|
20
|
+
end
|
21
|
+
|
22
|
+
it "raises a helpful LoadError message if it can't find the class" do
|
23
|
+
expect do
|
24
|
+
OmniAuth::Builder.new(nil) do
|
25
|
+
provider :lorax
|
26
|
+
end
|
27
|
+
end.to raise_error(LoadError, 'Could not find matching strategy for :lorax. You may need to install an additional gem (such as omniauth-lorax).')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#options' do
|
32
|
+
it 'merges provided options in' do
|
33
|
+
k = Class.new
|
34
|
+
b = OmniAuth::Builder.new(nil)
|
35
|
+
expect(b).to receive(:use).with(k, :foo => 'bar', :baz => 'tik')
|
36
|
+
|
37
|
+
b.options :foo => 'bar'
|
38
|
+
b.provider k, :baz => 'tik'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'adds an argument if no options are provided' do
|
42
|
+
k = Class.new
|
43
|
+
b = OmniAuth::Builder.new(nil)
|
44
|
+
expect(b).to receive(:use).with(k, :foo => 'bar')
|
45
|
+
|
46
|
+
b.options :foo => 'bar'
|
47
|
+
b.provider k
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe OmniAuth::FailureEndpoint do
|
4
|
+
subject { OmniAuth::FailureEndpoint }
|
5
|
+
|
6
|
+
context 'raise-out environment' do
|
7
|
+
before do
|
8
|
+
@rack_env = ENV['RACK_ENV']
|
9
|
+
ENV['RACK_ENV'] = 'test'
|
10
|
+
|
11
|
+
@default = OmniAuth.config.failure_raise_out_environments
|
12
|
+
OmniAuth.config.failure_raise_out_environments = ['test']
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'raises out the error' do
|
16
|
+
expect do
|
17
|
+
subject.call('omniauth.error' => StandardError.new('Blah'))
|
18
|
+
end.to raise_error(StandardError, 'Blah')
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'raises out an OmniAuth::Error if no omniauth.error is set' do
|
22
|
+
expect { subject.call('omniauth.error.type' => 'example') }.to raise_error(OmniAuth::Error, 'example')
|
23
|
+
end
|
24
|
+
|
25
|
+
after do
|
26
|
+
ENV['RACK_ENV'] = @rack_env
|
27
|
+
OmniAuth.config.failure_raise_out_environments = @default
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'non-raise-out environment' do
|
32
|
+
let(:env) do
|
33
|
+
{'omniauth.error.type' => 'invalid_request', 'omniauth.error.strategy' => ExampleStrategy.new({})}
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'is a redirect' do
|
37
|
+
status, _, _ = *subject.call(env)
|
38
|
+
expect(status).to eq(302)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'includes the SCRIPT_NAME' do
|
42
|
+
_, head, _ = *subject.call(env.merge('SCRIPT_NAME' => '/random'))
|
43
|
+
expect(head['Location']).to eq('/random/auth/failure?message=invalid_request&strategy=test')
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'respects the configured path prefix' do
|
47
|
+
allow(OmniAuth.config).to receive(:path_prefix).and_return('/boo')
|
48
|
+
_, head, _ = *subject.call(env)
|
49
|
+
expect(head['Location']).to eq('/boo/failure?message=invalid_request&strategy=test')
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'includes the origin (escaped) if one is provided' do
|
53
|
+
env.merge! 'omniauth.origin' => '/origin-example'
|
54
|
+
_, head, _ = *subject.call(env)
|
55
|
+
expect(head['Location']).to be_include('&origin=%2Forigin-example')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|