omniauth-tropo 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format=nested
3
+ --backtrace
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development, :test do
6
+ gem 'guard'
7
+ gem 'rake'
8
+ gem 'guard-rspec'
9
+ gem 'guard-bundler'
10
+ gem 'growl'
11
+ gem 'rb-fsevent'
12
+ end
data/Guardfile ADDED
@@ -0,0 +1,11 @@
1
+ guard 'rspec', :version => 2 do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { "spec" }
5
+ end
6
+
7
+
8
+ guard 'bundler' do
9
+ watch('Gemfile')
10
+ watch(/^.+\.gemspec/)
11
+ end
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2011-2012 John Dyer <johntdyer@gmail.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # OmniAuth::Tropo
2
+
3
+ OmniAuth stratgie to get user profile from Tropo's RestAPI.
4
+
5
+ ## Usage
6
+
7
+ Install manually, or just use Bundler:
8
+
9
+ gem 'omniauth-tropo'
10
+
11
+ Add :tropo provider to omniauth builder (RAILS_ROOT/config/initializers/omniauth.rb):
12
+
13
+ # configuration for Tropo Provisioning API
14
+ Rails.application.config.middleware.use OmniAuth::Builder do
15
+ provider :tropo, "http://api.tropo.com"
16
+ # provider ...
17
+ end
18
+
19
+ ### Example:
20
+
21
+ cd examples
22
+ rackup config.ru
23
+ http://localhost:9292
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ desc 'Default: run specs'
7
+ task :default => :spec
8
+
9
+ desc 'Run specs'
10
+ RSpec::Core::RakeTask.new
11
+
12
+ Bundler::GemHelper.install_tasks
13
+
data/example/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source :rubygems
2
+
3
+ gem 'sinatra'
4
+ gem 'multi_json'
5
+ gem 'omniauth-tropo', :path => '../'
data/example/config.ru ADDED
@@ -0,0 +1,27 @@
1
+ require 'bundler/setup'
2
+ require 'sinatra/base'
3
+ require 'omniauth-tropo'
4
+
5
+ class App < Sinatra::Base
6
+ get '/' do
7
+ redirect '/auth/tropo'
8
+ end
9
+
10
+ post '/auth/:provider/callback' do
11
+ content_type 'application/json'
12
+ MultiJson.encode(request.env)
13
+ end
14
+
15
+ get '/auth/failure' do
16
+ content_type 'application/json'
17
+ MultiJson.encode(request.env)
18
+ end
19
+ end
20
+
21
+ use Rack::Session::Cookie
22
+
23
+ use OmniAuth::Builder do
24
+ provider :tropo, "http://api.tropo.com"
25
+ end
26
+
27
+ run App.new
@@ -0,0 +1,48 @@
1
+ require 'omniauth-http-basic'
2
+ require 'multi_json'
3
+ module OmniAuth
4
+ module Strategies
5
+ class Tropo < OmniAuth::Strategies::HttpBasic
6
+
7
+ option :title, "Tropo Login"
8
+
9
+ uid { get_value('id') }
10
+
11
+ credentials { {:username => username, :password => password}}
12
+
13
+ info do
14
+ {
15
+ :name => "#{get_value('firstName')} #{get_value('lastName')}",
16
+ :username => request['username']
17
+ }
18
+ end
19
+
20
+ extra do
21
+ {
22
+ :number => get_value('phoneNumber'),
23
+ :state => get_value('state'),
24
+ :zip_code => get_value('postalCode'),
25
+ :join_date => get_value('joinDate'),
26
+ :job_title => get_value('jobTitle'),
27
+ :email => get_value('email'),
28
+ :address => get_value('address'),
29
+ :address2 => get_value('address2')
30
+ }
31
+ end
32
+
33
+ protected
34
+
35
+ def api_uri
36
+ "#{options.endpoint}/users/#{username}"
37
+ end
38
+
39
+ def json_response
40
+ @json_response ||= MultiJson.load(authentication_response.body, :symbolize_keys => true)
41
+ end
42
+
43
+ def get_value(key)
44
+ json_response[key.to_sym]
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Tropo
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require 'omniauth-tropo/version'
2
+ require 'omniauth/strategies/tropo'
@@ -0,0 +1,26 @@
1
+ # encoding: utf-8
2
+ require File.expand_path('../lib/omniauth-tropo/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.add_dependency 'omniauth', '~> 1.0'
6
+ gem.add_dependency 'omniauth-http-basic', '~> 1.0'
7
+
8
+ gem.add_development_dependency 'rspec', '~> 2.7'
9
+ gem.add_development_dependency 'rack-test'
10
+ gem.add_development_dependency 'multi_json'
11
+ gem.add_development_dependency 'simplecov'
12
+ gem.add_development_dependency 'webmock'
13
+ gem.add_development_dependency 'yard'
14
+
15
+ gem.authors = ['John Dyer']
16
+ gem.email = ['johntdyer@gmail.com']
17
+ gem.description = %q{Tropo strategy for OmniAuth.}
18
+ gem.summary = gem.description
19
+ gem.homepage = 'http://github.com/johntdyer/omniauth-tropo'
20
+
21
+ gem.name = 'omniauth-tropo'
22
+ gem.require_paths = ['lib']
23
+ gem.files = `git ls-files`.split("\n")
24
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
25
+ gem.version = OmniAuth::Tropo::VERSION
26
+ end
@@ -0,0 +1,53 @@
1
+ require File.expand_path('../../../spec_helper', __FILE__)
2
+
3
+ RESPONSE_JSON = <<-EOF
4
+ {
5
+ "href": "http://api.tropo.com/users/jdyer",
6
+ "id": "12345",
7
+ "address": "189 South Orange Avenue",
8
+ "address2": "#1000",
9
+ "city": "Orlando",
10
+ "country": "USA",
11
+ "email": "user@test.com",
12
+ "firstName": "John",
13
+ "jobTitle": "System Engineer",
14
+ "joinDate": "2008-04-05T19:57:49.643+0000",
15
+ "lastName": "Dyer",
16
+ "marketingOptIn": true,
17
+ "organization": "Voxeo Labs",
18
+ "notes": "foo",
19
+ "phoneNumber": "1234567890",
20
+ "postalCode": "32801",
21
+ "state": "FL",
22
+ "username": "jdyer",
23
+ "status": "active"
24
+ }
25
+ EOF
26
+
27
+ describe OmniAuth::Strategies::Tropo do
28
+ def app; lambda {|env| [200, {}, ["Hello HttpBasic!"]]}; end
29
+
30
+ let(:fresh_strategy) { Class.new OmniAuth::Strategies::Tropo }
31
+ let(:instance) { subject.new(app, "http://www.example.com/rest")}
32
+ subject { fresh_strategy }
33
+
34
+ it 'should be initialized with API endpoint' do
35
+ instance.options.endpoint.should == "http://www.example.com/rest"
36
+ end
37
+
38
+ it 'should set an expected auth hash' do
39
+ json = MultiJson.load(RESPONSE_JSON, :symbolize_keys => true)
40
+ instance.stub!(:request).and_return({'username' => 'jdyer', 'password' => '1234'})
41
+ instance.stub!(:json_response).and_return(json)
42
+ instance.uid.should == '12345'
43
+ instance.credentials[:username].should == 'jdyer'
44
+ instance.info[:name].should == 'John Dyer'
45
+ instance.extra[:job_title].should == 'System Engineer'
46
+ instance.extra[:state].should == 'FL'
47
+ instance.extra[:zip_code].should == '32801'
48
+ instance.extra[:number].should == '1234567890'
49
+ instance.extra[:email].should == 'user@test.com'
50
+ instance.extra[:address].should == '189 South Orange Avenue'
51
+ instance.extra[:address2].should == '#1000'
52
+ end
53
+ end
@@ -0,0 +1,16 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+
4
+ require 'simplecov'
5
+ SimpleCov.start
6
+ require 'rspec'
7
+ require 'rack/test'
8
+ require 'webmock/rspec'
9
+ require 'omniauth'
10
+ require 'omniauth-tropo'
11
+
12
+ RSpec.configure do |config|
13
+ config.include WebMock::API
14
+ config.include Rack::Test::Methods
15
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
16
+ end
metadata ADDED
@@ -0,0 +1,197 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-tropo
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John Dyer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: omniauth
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: omniauth-http-basic
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '1.0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '1.0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.7'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.7'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rack-test
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: multi_json
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: simplecov
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: webmock
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: yard
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ description: Tropo strategy for OmniAuth.
143
+ email:
144
+ - johntdyer@gmail.com
145
+ executables: []
146
+ extensions: []
147
+ extra_rdoc_files: []
148
+ files:
149
+ - .gitignore
150
+ - .rspec
151
+ - Gemfile
152
+ - Guardfile
153
+ - LICENSE
154
+ - README.md
155
+ - Rakefile
156
+ - example/Gemfile
157
+ - example/config.ru
158
+ - lib/omniauth-tropo.rb
159
+ - lib/omniauth-tropo/version.rb
160
+ - lib/omniauth/strategies/tropo.rb
161
+ - omniauth-tropo.gemspec
162
+ - spec/omniauth/strategies/tropo_spec.rb
163
+ - spec/spec_helper.rb
164
+ homepage: http://github.com/johntdyer/omniauth-tropo
165
+ licenses: []
166
+ post_install_message:
167
+ rdoc_options: []
168
+ require_paths:
169
+ - lib
170
+ required_ruby_version: !ruby/object:Gem::Requirement
171
+ none: false
172
+ requirements:
173
+ - - ! '>='
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ segments:
177
+ - 0
178
+ hash: 2352945515170662331
179
+ required_rubygems_version: !ruby/object:Gem::Requirement
180
+ none: false
181
+ requirements:
182
+ - - ! '>='
183
+ - !ruby/object:Gem::Version
184
+ version: '0'
185
+ segments:
186
+ - 0
187
+ hash: 2352945515170662331
188
+ requirements: []
189
+ rubyforge_project:
190
+ rubygems_version: 1.8.24
191
+ signing_key:
192
+ specification_version: 3
193
+ summary: Tropo strategy for OmniAuth.
194
+ test_files:
195
+ - spec/omniauth/strategies/tropo_spec.rb
196
+ - spec/spec_helper.rb
197
+ has_rdoc: