omniauth-tropo 1.0.0 → 1.0.1
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/.gitignore +1 -0
- data/Gemfile +2 -0
- data/README.md +6 -0
- data/lib/omniauth-tropo/version.rb +1 -1
- data/lib/omniauth/strategies/tropo.rb +37 -11
- data/spec/omniauth/strategies/tropo_spec.rb +62 -17
- data/spec/spec_helper.rb +4 -1
- metadata +4 -4
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -16,6 +16,12 @@ Add :tropo provider to omniauth builder (RAILS_ROOT/config/initializers/omniauth
|
|
16
16
|
# provider ...
|
17
17
|
end
|
18
18
|
|
19
|
+
If you want to pull roles from the ProvisioningAPI ( Premise only ) you can do so by adding :role_options hash in the builder:
|
20
|
+
|
21
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
22
|
+
provider :tropo, "http://yourserver.com:8080/rest", :role_options=>{:admin_username=>'admin',:admin_password=>'admin'}
|
23
|
+
end
|
24
|
+
|
19
25
|
### Example:
|
20
26
|
|
21
27
|
cd examples
|
@@ -1,12 +1,18 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
%w(omniauth-http-basic multi_json faraday).each{|lib| require lib}
|
2
|
+
|
3
3
|
module OmniAuth
|
4
4
|
module Strategies
|
5
5
|
class Tropo < OmniAuth::Strategies::HttpBasic
|
6
6
|
|
7
7
|
option :title, "Tropo Login"
|
8
8
|
|
9
|
-
|
9
|
+
option :role_options, {
|
10
|
+
:path => 'roles',
|
11
|
+
:admin_username => nil,
|
12
|
+
:admin_password => nil
|
13
|
+
}
|
14
|
+
|
15
|
+
uid { get_value(:id) }
|
10
16
|
|
11
17
|
credentials { {:username => username, :password => password}}
|
12
18
|
|
@@ -26,23 +32,43 @@ module OmniAuth
|
|
26
32
|
:job_title => get_value('jobTitle'),
|
27
33
|
:email => get_value('email'),
|
28
34
|
:address => get_value('address'),
|
29
|
-
:address2 => get_value('address2')
|
35
|
+
:address2 => get_value('address2'),
|
36
|
+
:roles => roles_enabled ? fetch_roles : nil
|
30
37
|
}
|
31
38
|
end
|
32
39
|
|
33
40
|
protected
|
34
41
|
|
35
|
-
|
36
|
-
|
37
|
-
|
42
|
+
def api_uri
|
43
|
+
"#{options.endpoint}/users/#{username}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def json_response
|
47
|
+
@json_response ||= MultiJson.load(authentication_response.body, :symbolize_keys => true)
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_value(key)
|
51
|
+
json_response[key.to_sym]
|
52
|
+
end
|
38
53
|
|
39
|
-
|
40
|
-
|
54
|
+
def roles_enabled
|
55
|
+
if options.role_options.admin_username && options.role_options.admin_username
|
56
|
+
true
|
57
|
+
else
|
58
|
+
false
|
41
59
|
end
|
60
|
+
end
|
42
61
|
|
43
|
-
|
44
|
-
|
62
|
+
def fetch_roles
|
63
|
+
conn = Faraday.new(:url => options.endpoint) do |builder|
|
64
|
+
builder.request :url_encoded
|
65
|
+
builder.response :logger
|
66
|
+
builder.adapter :net_http
|
45
67
|
end
|
68
|
+
conn.basic_auth(options.role_options.admin_username,options.role_options.admin_password)
|
69
|
+
response = conn.get "/users/#{request['username']}/#{options.role_options.path}"
|
70
|
+
MultiJson.load(response.body).collect{|x| x["roleName"]} if response.status == 200
|
71
|
+
end
|
46
72
|
end
|
47
73
|
end
|
48
74
|
end
|
@@ -23,31 +23,76 @@ RESPONSE_JSON = <<-EOF
|
|
23
23
|
"status": "active"
|
24
24
|
}
|
25
25
|
EOF
|
26
|
-
|
27
26
|
describe OmniAuth::Strategies::Tropo do
|
28
27
|
def app; lambda {|env| [200, {}, ["Hello HttpBasic!"]]}; end
|
29
28
|
|
30
29
|
let(:fresh_strategy) { Class.new OmniAuth::Strategies::Tropo }
|
31
|
-
let(:instance) { subject.new(app, "http://www.example.com
|
30
|
+
let(:instance) { subject.new(app, "http://www.example.com") }
|
32
31
|
subject { fresh_strategy }
|
33
32
|
|
34
33
|
it 'should be initialized with API endpoint' do
|
35
|
-
instance.options.endpoint.should == "http://www.example.com
|
34
|
+
instance.options.endpoint.should == "http://www.example.com"
|
36
35
|
end
|
36
|
+
describe "request" do
|
37
|
+
describe "role_options-defaults" do
|
38
|
+
it 'should use default options for role features' do
|
39
|
+
instance.options.role_options.admin_username.should == nil
|
40
|
+
instance.options.role_options.admin_password.should == nil
|
41
|
+
instance.options.role_options.path.should == "roles"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "role_options-overrides" do
|
46
|
+
let(:instance) { subject.new(app, "http://www.example.com", :role_options=>{:admin_username=> 'blah',:admin_password=>'blah',:path=>'blah'}) }
|
47
|
+
it 'should take options for roles features' do
|
48
|
+
instance.options.role_options.admin_username.should == "blah"
|
49
|
+
instance.options.role_options.admin_password.should == "blah"
|
50
|
+
instance.options.role_options.path.should == "blah"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should return roles when role_options is provided" do
|
54
|
+
json = MultiJson.load(RESPONSE_JSON, :symbolize_keys => true)
|
37
55
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
instance.extra[:address2].should == '#1000'
|
56
|
+
FakeWeb.register_uri(:get,
|
57
|
+
"http://blah:blah@www.example.com/users/jdyer/roles",
|
58
|
+
:body=>'',
|
59
|
+
:content_type=>'application/json',
|
60
|
+
:status => ["200","OK"]
|
61
|
+
)
|
62
|
+
|
63
|
+
instance.stub!(:request).and_return({'username' => 'jdyer', 'password' => '1234'})
|
64
|
+
instance.stub!(:json_response).and_return(json)
|
65
|
+
instance.stub!(:fetch_roles).and_return(["VOXEO_EMPLOYEE", "TROPO_PRODUCTION_CUSTOMER"])
|
66
|
+
instance.extra[:roles].should include('VOXEO_EMPLOYEE')
|
67
|
+
end
|
68
|
+
end
|
52
69
|
end
|
70
|
+
|
71
|
+
describe "response" do
|
72
|
+
let(:instance) { subject.new(app, "http://www.example.com")}
|
73
|
+
it 'should set an expected auth hash' do
|
74
|
+
json = MultiJson.load(RESPONSE_JSON, :symbolize_keys => true)
|
75
|
+
instance.stub!(:request).and_return({'username' => 'jdyer', 'password' => '1234'})
|
76
|
+
instance.stub!(:json_response).and_return(json)
|
77
|
+
instance.uid.should == '12345'
|
78
|
+
instance.credentials[:username].should == 'jdyer'
|
79
|
+
instance.info[:name].should == 'John Dyer'
|
80
|
+
instance.extra[:job_title].should == 'System Engineer'
|
81
|
+
instance.extra[:state].should == 'FL'
|
82
|
+
instance.extra[:zip_code].should == '32801'
|
83
|
+
instance.extra[:number].should == '1234567890'
|
84
|
+
instance.extra[:email].should == 'user@test.com'
|
85
|
+
instance.extra[:address].should == '189 South Orange Avenue'
|
86
|
+
instance.extra[:address2].should == '#1000'
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should return empty roles by default" do
|
90
|
+
json = MultiJson.load(RESPONSE_JSON, :symbolize_keys => true)
|
91
|
+
instance.stub!(:request).and_return({'username' => 'jdyer', 'password' => '1234'})
|
92
|
+
instance.stub!(:json_response).and_return(json)
|
93
|
+
instance.extra[:roles].should == nil
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
53
98
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -4,13 +4,16 @@ $:.unshift File.expand_path('../../lib', __FILE__)
|
|
4
4
|
require 'simplecov'
|
5
5
|
SimpleCov.start
|
6
6
|
require 'rspec'
|
7
|
+
require 'faraday'
|
7
8
|
require 'rack/test'
|
8
9
|
require 'webmock/rspec'
|
9
10
|
require 'omniauth'
|
11
|
+
require 'fakeweb'
|
10
12
|
require 'omniauth-tropo'
|
11
13
|
|
14
|
+
FakeWeb.allow_net_connect = false
|
15
|
+
|
12
16
|
RSpec.configure do |config|
|
13
|
-
config.include WebMock::API
|
14
17
|
config.include Rack::Test::Methods
|
15
18
|
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
16
19
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-tropo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: omniauth
|
@@ -175,7 +175,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
175
175
|
version: '0'
|
176
176
|
segments:
|
177
177
|
- 0
|
178
|
-
hash:
|
178
|
+
hash: 4379067423480031072
|
179
179
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
180
180
|
none: false
|
181
181
|
requirements:
|
@@ -184,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
184
|
version: '0'
|
185
185
|
segments:
|
186
186
|
- 0
|
187
|
-
hash:
|
187
|
+
hash: 4379067423480031072
|
188
188
|
requirements: []
|
189
189
|
rubyforge_project:
|
190
190
|
rubygems_version: 1.8.24
|