omniauth-delivery 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 262d3753773bc1d165783ffc132566db10eebe35
4
+ data.tar.gz: 54590c071e35b714d96e060bf0ed91be28a171ce
5
+ SHA512:
6
+ metadata.gz: 1e7c6cad696e3d60588a30af1af7c7e455d26c85ce186830a6caed5171f9063aa806ad002d2684867477ab7c56d4fb275b0d19b38be8c71b664ad03aa1d81025
7
+ data.tar.gz: 52d939af164d603d4ccc4248e0725c06d33fe841c96c8073be8529638f00249420d49b3fbef01f5513e15f29a69811bf106aeb8507da94d7f490e0652aed95dd
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.project ADDED
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>omniauth-delivery</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ </buildSpec>
9
+ <natures>
10
+ <nature>com.aptana.ruby.core.rubynature</nature>
11
+ </natures>
12
+ </projectDescription>
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - ruby-head
6
+ - ree
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+
4
+ gem 'rake'
5
+ # Specify your gem's dependencies in omniauth-foursquare.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+
2
+
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,8 @@
1
+ require "omniauth-delivery/version"
2
+ require "omniauth/strategies/delivery"
3
+
4
+ module Omniauth
5
+ module Delivery
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Omniauth
2
+ module Delivery
3
+ VERSION = "0.0.5"
4
+ end
5
+ end
@@ -0,0 +1,69 @@
1
+ require 'omniauth-oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class Delivery < OmniAuth::Strategies::OAuth2
6
+ DEFAULT_SCOPE = "global"
7
+ PRODUCTION_USER_SITE = 'https://laundryapi.delivery.com'
8
+ PRODUCTION_API_SITE = 'https://api.delivery.com'
9
+ DEVELOPMENT_USER_SITE = 'http://laundryqa.delivery.com'
10
+ DEVELOPMENT_API_SITE = 'http://sandbox.delivery.com'
11
+ @@mode = :production
12
+
13
+ option :client_options, {
14
+ :site => PRODUCTION_API_SITE,
15
+ :authorize_url => '/third_party/authorize',
16
+ :token_url => '/third_party/access_token'
17
+ }
18
+
19
+ option :authorize_options, [:development]
20
+
21
+ uid { raw_info['usersid'] }
22
+
23
+ info do
24
+ {
25
+ :first_name => raw_info['first_name'],
26
+ :last_name => raw_info['last_name'],
27
+ :name => raw_info['first_name'].to_s + ' ' + raw_info['last_name'].to_s,
28
+ :email => raw_info['email'],
29
+ :addresses => raw_info['addresses'],
30
+ }
31
+ end
32
+
33
+ extra do
34
+ { :raw_info => raw_info }
35
+ end
36
+
37
+ def request_phase
38
+ @@mode = :development if authorize_params.include?(:development)
39
+ options[:authorize_options].delete(:development)
40
+ options.client_options.site = @@mode == :development ? DEVELOPMENT_API_SITE : PRODUCTION_API_SITE
41
+ options[:authorize_params] = client_params.merge(options[:authorize_params])
42
+ super
43
+ end
44
+
45
+ def auth_hash
46
+ OmniAuth::Utils.deep_merge(super, client_params.merge({
47
+ :grant_type => 'authorization_code'}))
48
+ end
49
+
50
+ def callback_phase
51
+ options.client_options.site = @@mode == :development ? DEVELOPMENT_API_SITE : PRODUCTION_API_SITE
52
+ super
53
+ end
54
+
55
+ def raw_info
56
+ access_token.options[:mode] = :query
57
+ access_token.options[:param_name] = :token
58
+ user_site = @@mode == :development ? DEVELOPMENT_USER_SITE : PRODUCTION_USER_SITE
59
+ @raw_info ||= access_token.post(user_site + '/api/v1/customer/auth').parsed
60
+ end
61
+
62
+ private
63
+
64
+ def client_params
65
+ {:client_id => options[:client_id], :redirect_uri => callback_url ,:response_type => "code", :scope => DEFAULT_SCOPE}
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omniauth-delivery/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "omniauth-delivery"
7
+ s.version = Omniauth::Delivery::VERSION
8
+ s.authors = ["Hoai Ngo"]
9
+ s.email = ["heochoat76041@gmail.com"]
10
+ s.homepage = "https://github.com/cubi76041/omniauth-delivery"
11
+ s.summary = %q{Delivery.com OAuth strategy for OmniAuth}
12
+ s.description = %q{Delivery.com OAuth strategy for OmniAuth}
13
+
14
+ s.rubyforge_project = "omniauth-delivery"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency 'omniauth', '~> 1.0'
22
+ s.add_dependency 'omniauth-oauth2', '~> 1.0'
23
+ s.add_development_dependency 'rspec', '~> 2.7'
24
+ s.add_development_dependency 'rack-test'
25
+ s.add_development_dependency 'simplecov'
26
+ s.add_development_dependency 'webmock'
27
+ end
@@ -0,0 +1,119 @@
1
+ require 'spec_helper'
2
+ require 'omniauth-delivery'
3
+
4
+ describe OmniAuth::Strategies::Delivery do
5
+ before :each do
6
+ @request = double('Request')
7
+ @request.stub(:params) { {} }
8
+ end
9
+
10
+ subject do
11
+ OmniAuth::Strategies::Delivery.new(nil, @options || {}).tap do |strategy|
12
+ strategy.stub(:request) { @request }
13
+ end
14
+ end
15
+
16
+ it_should_behave_like 'an oauth2 strategy'
17
+
18
+ describe '#client' do
19
+ it 'has correct Delivery site' do
20
+ subject.client.site.should eq('https://api.delivery.com')
21
+ end
22
+
23
+ it 'has correct authorize url' do
24
+ subject.client.options[:authorize_url].should eq('/third_party/authorize')
25
+ end
26
+
27
+ it 'has correct token url' do
28
+ subject.client.options[:token_url].should eq('/third_party/access_token')
29
+ end
30
+ end
31
+
32
+ describe '#info' do
33
+ before :each do
34
+ @raw_info = {
35
+ "email" => "test@example.com",
36
+ "first_name" => "Test",
37
+ "last_name" => "User",
38
+ "usersid" => 123456,
39
+ "addresses" => []
40
+ }
41
+
42
+ subject.stub(:raw_info) { @raw_info }
43
+ end
44
+
45
+ context 'when data is present in raw info' do
46
+ it 'returns the combined name' do
47
+ subject.info[:name].should eq('Test User')
48
+ end
49
+
50
+ it 'returns the first name' do
51
+ subject.info[:first_name].should eq('Test')
52
+ end
53
+
54
+ it 'returns the last name' do
55
+ subject.info[:last_name].should eq('User')
56
+ end
57
+
58
+ it 'returns the email' do
59
+ subject.info[:email].should eq('test@example.com')
60
+ end
61
+
62
+ it "sets the email blank if contact block is missing in raw_info" do
63
+ @raw_info.delete('contact')
64
+ subject.info[:email].should be_nil
65
+ end
66
+ end
67
+ end
68
+
69
+ describe '#credentials' do
70
+ before :each do
71
+ @access_token = double('OAuth2::AccessToken')
72
+ @access_token.stub(:token)
73
+ @access_token.stub(:expires?)
74
+ @access_token.stub(:expires_at)
75
+ @access_token.stub(:refresh_token)
76
+ subject.stub(:access_token) { @access_token }
77
+ end
78
+
79
+ it 'returns a Hash' do
80
+ subject.credentials.should be_a(Hash)
81
+ end
82
+
83
+ it 'returns the token' do
84
+ @access_token.stub(:token) { '123' }
85
+ subject.credentials['token'].should eq('123')
86
+ end
87
+
88
+ it 'returns the expiry status' do
89
+ @access_token.stub(:expires?) { true }
90
+ subject.credentials['expires'].should eq(true)
91
+
92
+ @access_token.stub(:expires?) { false }
93
+ subject.credentials['expires'].should eq(false)
94
+ end
95
+
96
+ it 'returns the refresh token and expiry time when expiring' do
97
+ ten_mins_from_now = (Time.now + 360).to_i
98
+ @access_token.stub(:expires?) { true }
99
+ @access_token.stub(:refresh_token) { '321' }
100
+ @access_token.stub(:expires_at) { ten_mins_from_now }
101
+ subject.credentials['refresh_token'].should eq('321')
102
+ subject.credentials['expires_at'].should eq(ten_mins_from_now)
103
+ end
104
+
105
+ it 'does not return the refresh token when it is nil and expiring' do
106
+ @access_token.stub(:expires?) { true }
107
+ @access_token.stub(:refresh_token) { nil }
108
+ subject.credentials['refresh_token'].should be_nil
109
+ subject.credentials.should_not have_key('refresh_token')
110
+ end
111
+
112
+ it 'does not return the refresh token when not expiring' do
113
+ @access_token.stub(:expires?) { false }
114
+ @access_token.stub(:refresh_token) { 'XXX' }
115
+ subject.credentials['refresh_token'].should be_nil
116
+ subject.credentials.should_not have_key('refresh_token')
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,6 @@
1
+ require 'bundler/setup'
2
+ require 'rspec'
3
+ Dir[File.expand_path('../support/**/*', __FILE__)].each { |f| require f }
4
+
5
+ RSpec.configure do |config|
6
+ end
@@ -0,0 +1,37 @@
1
+ # NOTE it would be useful if this lived in omniauth-oauth2 eventually
2
+ shared_examples 'an oauth2 strategy' do
3
+ describe '#client' do
4
+ it 'should be initialized with symbolized client_options' do
5
+ @options = { :client_options => { 'authorize_url' => 'https://example.com' } }
6
+ subject.client.options[:authorize_url].should == 'https://example.com'
7
+ end
8
+ end
9
+
10
+ describe '#authorize_params' do
11
+ it 'should include any authorize params passed in the :authorize_params option' do
12
+ @options = { :authorize_params => { :foo => 'bar', :baz => 'zip' } }
13
+ subject.authorize_params['foo'].should eq('bar')
14
+ subject.authorize_params['baz'].should eq('zip')
15
+ end
16
+
17
+ it 'should include top-level options that are marked as :authorize_options' do
18
+ @options = { :authorize_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
19
+ subject.authorize_params['scope'].should eq('bar')
20
+ subject.authorize_params['foo'].should eq('baz')
21
+ end
22
+ end
23
+
24
+ describe '#token_params' do
25
+ it 'should include any authorize params passed in the :authorize_params option' do
26
+ @options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
27
+ subject.token_params['foo'].should eq('bar')
28
+ subject.token_params['baz'].should eq('zip')
29
+ end
30
+
31
+ it 'should include top-level options that are marked as :authorize_options' do
32
+ @options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
33
+ subject.token_params['scope'].should eq('bar')
34
+ subject.token_params['foo'].should eq('baz')
35
+ end
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-delivery
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Hoai Ngo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: omniauth
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: omniauth-oauth2
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack-test
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Delivery.com OAuth strategy for OmniAuth
98
+ email:
99
+ - heochoat76041@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - .gitignore
105
+ - .project
106
+ - .rspec
107
+ - .travis.yml
108
+ - Gemfile
109
+ - README.md
110
+ - Rakefile
111
+ - lib/omniauth-delivery.rb
112
+ - lib/omniauth-delivery/version.rb
113
+ - lib/omniauth/strategies/delivery.rb
114
+ - omniauth-delivery.gemspec
115
+ - spec/omniauth/strategies/delivery_spec.rb
116
+ - spec/spec_helper.rb
117
+ - spec/support/shared_examples.rb
118
+ homepage: https://github.com/cubi76041/omniauth-delivery
119
+ licenses: []
120
+ metadata: {}
121
+ post_install_message:
122
+ rdoc_options: []
123
+ require_paths:
124
+ - lib
125
+ required_ruby_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - '>='
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ required_rubygems_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - '>='
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ requirements: []
136
+ rubyforge_project: omniauth-delivery
137
+ rubygems_version: 2.2.2
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: Delivery.com OAuth strategy for OmniAuth
141
+ test_files:
142
+ - spec/omniauth/strategies/delivery_spec.rb
143
+ - spec/spec_helper.rb
144
+ - spec/support/shared_examples.rb