omniauth-amazon 1.0.0

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.
@@ -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 @@
1
+ --colour
@@ -0,0 +1,9 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - ree
6
+ - jruby-18mode
7
+ - jruby-19mode
8
+ - rbx-18mode
9
+ - rbx-19mode
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in omniauth-amazon.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Stafford Brunk
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,61 @@
1
+ # OmniAuth::Amazon
2
+ [![Build Status](https://travis-ci.org/wingrunr21/omniauth-amazon.png)](https://travis-ci.org/wingrunr21/omniauth-amazon) [![Gem Version](https://badge.fury.io/rb/omniauth-amazon.png)](http://badge.fury.io/rb/omniauth-amazon)
3
+
4
+ [Login with Amazon](https://login.amazon.com/) OAuth2 strategy for OmniAuth 1.0
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'omniauth-amazon'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install omniauth-amazon
19
+
20
+ ## Prereqs
21
+
22
+ You must create an application via the [Amazon App Console](https://login.amazon.com/manageApps). Once that is complete, register two URLs under the <i>Web Settings</i>:
23
+
24
+ https://localhost:3000/auth/amazon/callback
25
+ https://your_website_here/auth/amazon/callback
26
+
27
+ Amazon requires HTTPS for the whitelisted callback URL. They don't appear to
28
+ like ```.dev``` domains too much but happily accept localhost.
29
+
30
+ ## Usage
31
+
32
+ Usage is similar to other OAuth2 based OmniAuth strategies:
33
+
34
+ ```ruby
35
+ Rails.application.config.middleware.use OmniAuth::Builder do
36
+ provider :amazon, ENV['AMAZON_CLIENT_ID'], ENV['AMAZON_CLIENT_SECRET']
37
+ end
38
+ ```
39
+
40
+ ## Configuration
41
+
42
+ Config options can be passed to `provider` via a `Hash`:
43
+
44
+ * `scope`: A space-separated list of permissions. Can be `profile`,
45
+ `postal_code`, or both. Defaults to both: `profile postal_code`
46
+
47
+ ## Resources
48
+ * [Login with Amazon button guide](https://login.amazon.com/button-guide)
49
+ * [Login with Amazon style guide](https://login.amazon.com/style-guide)
50
+
51
+ ## Todo
52
+ 1. Fix ```raw_info``` to see why ```client.request``` has to be used in query
53
+ mode
54
+
55
+ ## Contributing
56
+
57
+ 1. Fork it
58
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
59
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
60
+ 4. Push to the branch (`git push origin my-new-feature`)
61
+ 5. Create new Pull Request
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ desc "Run specs"
5
+ RSpec::Core::RakeTask.new
6
+
7
+ desc 'Default: run specs.'
8
+ task :default => :spec
@@ -0,0 +1 @@
1
+ require 'omniauth/amazon'
@@ -0,0 +1,3 @@
1
+ require "omniauth/amazon/version"
2
+ require "omniauth/strategies/amazon"
3
+
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module Amazon
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,62 @@
1
+ require 'omniauth-oauth2'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class Amazon < OmniAuth::Strategies::OAuth2
7
+ option :name, 'amazon'
8
+
9
+ option :client_options, {
10
+ :site => 'https://www.amazon.com/',
11
+ :authorize_url => 'https://www.amazon.com/ap/oa',
12
+ :token_url => 'https://api.amazon.com/auth/o2/token'
13
+ }
14
+
15
+ option :access_token_options, {
16
+ :mode => :query
17
+ }
18
+
19
+ option :authorize_params, {
20
+ :scope => 'profile postal_code'
21
+ }
22
+
23
+ def build_access_token
24
+ token_params = {
25
+ :redirect_uri => callback_url,
26
+ :client_id => client.id,
27
+ :client_secret => client.secret
28
+ }
29
+ verifier = request.params['code']
30
+ client.auth_code.get_token(verifier, token_params)
31
+ end
32
+
33
+ uid { raw_info['Profile']['CustomerId'] }
34
+
35
+ info do
36
+ {
37
+ 'email' => raw_info['Profile']['PrimaryEmail'],
38
+ 'name' => raw_info['Profile']['Name']
39
+ }
40
+ end
41
+
42
+ extra do
43
+ {
44
+ 'postal_code' => raw_info['Profile']['PostalCode']
45
+ }
46
+ end
47
+
48
+ def raw_info
49
+ access_token.options[:parse] = :json
50
+
51
+ # This way is not working right now, do it the longer way
52
+ # for the time being
53
+ #
54
+ #@raw_info ||= access_token.get('/ap/user/profile').parsed
55
+
56
+ url = "/ap/user/profile"
57
+ params = {:params => { :access_token => access_token.token}}
58
+ @raw_info ||= access_token.client.request(:get, url, params).parsed
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'omniauth/amazon/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "omniauth-amazon"
8
+ spec.version = OmniAuth::Amazon::VERSION
9
+ spec.authors = ["Stafford Brunk"]
10
+ spec.email = ["stafford.brunk@gmail.com"]
11
+ spec.description = %q{Login with Amazon OAuth2 strategy for OmniAuth 1.0}
12
+ spec.summary = %q{Login with Amazon OAuth2 strategy for OmniAuth 1.0}
13
+ spec.homepage = "https://github.com/wingrunr21/omniauth-amazon"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'omniauth', '~> 1.0'
22
+ spec.add_dependency 'omniauth-oauth2', '~> 1.1'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency 'rspec', '~> 2.13'
27
+ spec.add_development_dependency 'rack-test'
28
+ spec.add_development_dependency 'simplecov'
29
+ spec.add_development_dependency 'webmock'
30
+ end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe OmniAuth::Strategies::Amazon do
4
+ subject do
5
+ strategy = OmniAuth::Strategies::Amazon.new(nil, @options || {})
6
+ strategy.stub(:session) { { } }
7
+ strategy
8
+ end
9
+
10
+ describe '#client' do
11
+ it 'should have the correct Amazon site' do
12
+ expect(subject.client.site).to eq("https://www.amazon.com/")
13
+ end
14
+
15
+ it 'should have the correct authorization url' do
16
+ expect(subject.client.options[:authorize_url]).to eq("https://www.amazon.com/ap/oa")
17
+ end
18
+
19
+ it 'should have the correct token url' do
20
+ expect(subject.client.options[:token_url]).to eq('https://api.amazon.com/auth/o2/token')
21
+ end
22
+ end
23
+
24
+ describe '#callback_path' do
25
+ it 'should have the correct callback path' do
26
+ expect(subject.callback_path).to eq('/auth/amazon/callback')
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,18 @@
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'simplecov'
4
+ SimpleCov.start
5
+ require 'rspec'
6
+ require 'rack/test'
7
+ require 'webmock/rspec'
8
+ require 'omniauth'
9
+ require 'omniauth-amazon'
10
+
11
+ RSpec.configure do |config|
12
+ config.include WebMock::API
13
+ config.include Rack::Test::Methods
14
+ config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
15
+ config.expect_with :rspec do |c|
16
+ c.syntax = :expect
17
+ end
18
+ end
@@ -0,0 +1,39 @@
1
+ # Courtesy omniauth-37signals:
2
+ # https://github.com/tallgreentree/omniauth-37signals/blob/master/spec/support/shared_examples.rb
3
+
4
+ shared_examples 'an oauth2 strategy' do
5
+ describe '#client' do
6
+ it 'should be initialized with symbolized client_options' do
7
+ @options = { :client_options => { 'authorize_url' => 'https://example.com' } }
8
+ subject.client.options[:authorize_url].should == 'https://example.com'
9
+ end
10
+ end
11
+
12
+ describe '#authorize_params' do
13
+ it 'should include any authorize params passed in the :authorize_params option' do
14
+ @options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
15
+ subject.authorize_params['foo'].should eq('bar')
16
+ subject.authorize_params['baz'].should eq('zip')
17
+ end
18
+
19
+ it 'should include top-level options that are marked as :authorize_options' do
20
+ @options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
21
+ subject.authorize_params['scope'].should eq('bar')
22
+ subject.authorize_params['foo'].should eq('baz')
23
+ end
24
+ end
25
+
26
+ describe '#token_params' do
27
+ it 'should include any token params passed in the :token_params option' do
28
+ @options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
29
+ subject.token_params['foo'].should eq('bar')
30
+ subject.token_params['baz'].should eq('zip')
31
+ end
32
+
33
+ it 'should include top-level options that are marked as :token_options' do
34
+ @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
35
+ subject.token_params['scope'].should eq('bar')
36
+ subject.token_params['foo'].should eq('baz')
37
+ end
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,197 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-amazon
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Stafford Brunk
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2013-05-29 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: omniauth
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 15
29
+ segments:
30
+ - 1
31
+ - 0
32
+ version: "1.0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: omniauth-oauth2
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 13
44
+ segments:
45
+ - 1
46
+ - 1
47
+ version: "1.1"
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: bundler
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 9
59
+ segments:
60
+ - 1
61
+ - 3
62
+ version: "1.3"
63
+ type: :development
64
+ version_requirements: *id003
65
+ - !ruby/object:Gem::Dependency
66
+ name: rake
67
+ prerelease: false
68
+ requirement: &id004 !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 3
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ type: :development
78
+ version_requirements: *id004
79
+ - !ruby/object:Gem::Dependency
80
+ name: rspec
81
+ prerelease: false
82
+ requirement: &id005 !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ hash: 25
88
+ segments:
89
+ - 2
90
+ - 13
91
+ version: "2.13"
92
+ type: :development
93
+ version_requirements: *id005
94
+ - !ruby/object:Gem::Dependency
95
+ name: rack-test
96
+ prerelease: false
97
+ requirement: &id006 !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ hash: 3
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ type: :development
107
+ version_requirements: *id006
108
+ - !ruby/object:Gem::Dependency
109
+ name: simplecov
110
+ prerelease: false
111
+ requirement: &id007 !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ type: :development
121
+ version_requirements: *id007
122
+ - !ruby/object:Gem::Dependency
123
+ name: webmock
124
+ prerelease: false
125
+ requirement: &id008 !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ hash: 3
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ type: :development
135
+ version_requirements: *id008
136
+ description: Login with Amazon OAuth2 strategy for OmniAuth 1.0
137
+ email:
138
+ - stafford.brunk@gmail.com
139
+ executables: []
140
+
141
+ extensions: []
142
+
143
+ extra_rdoc_files: []
144
+
145
+ files:
146
+ - .gitignore
147
+ - .rspec
148
+ - .travis.yml
149
+ - Gemfile
150
+ - LICENSE.txt
151
+ - README.md
152
+ - Rakefile
153
+ - lib/omniauth-amazon.rb
154
+ - lib/omniauth/amazon.rb
155
+ - lib/omniauth/amazon/version.rb
156
+ - lib/omniauth/strategies/amazon.rb
157
+ - omniauth-amazon.gemspec
158
+ - spec/omniauth/strategies/amazon_spec.rb
159
+ - spec/spec_helper.rb
160
+ - spec/support/shared_examples.rb
161
+ homepage: https://github.com/wingrunr21/omniauth-amazon
162
+ licenses:
163
+ - MIT
164
+ post_install_message:
165
+ rdoc_options: []
166
+
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ none: false
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ hash: 3
175
+ segments:
176
+ - 0
177
+ version: "0"
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ none: false
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ hash: 3
184
+ segments:
185
+ - 0
186
+ version: "0"
187
+ requirements: []
188
+
189
+ rubyforge_project:
190
+ rubygems_version: 1.8.24
191
+ signing_key:
192
+ specification_version: 3
193
+ summary: Login with Amazon OAuth2 strategy for OmniAuth 1.0
194
+ test_files:
195
+ - spec/omniauth/strategies/amazon_spec.rb
196
+ - spec/spec_helper.rb
197
+ - spec/support/shared_examples.rb