omniauth-square 0.1.1 → 0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +1 -3
- data/lib/omniauth/strategies/square.rb +52 -41
- data/lib/omniauth-square/version.rb +1 -1
- data/omniauth-square.gemspec +3 -3
- data/spec/omniauth/strategies/square_spec.rb +72 -70
- data/spec/spec_helper.rb +9 -2
- metadata +8 -8
- data/spec/support/shared_examples.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fbc8b1e3899fde29413ae907a92edafe6e9abc9
|
4
|
+
data.tar.gz: 3048aa68a28366aed6b7b7c4556c6f9c405b4799
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8cb2528181d44ea921c1d4ce7f0aacdfc6ab62c5f7c4ec4909d9f3c8b67571f8d5c550ff8a3664c174e975ebe8bcb3cb87270767851c9afc21cec812fde5c003
|
7
|
+
data.tar.gz: ff69b8212bb7a13ed19d2923684e6188bd4aee22d1f064a7fdd01e1e016ab5262a158d8b9d0b29c3a12f754277a835cb336560e5294e6abec3265402e6180b6f
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -4,8 +4,6 @@ This gem contains the Square strategy for OmniAuth.
|
|
4
4
|
|
5
5
|
Square uses the OAuth2 flow, you can read about it here: http://connect.squareup.com
|
6
6
|
|
7
|
-
## This gem is unfinished at the moment.
|
8
|
-
|
9
7
|
## How To Use It
|
10
8
|
|
11
9
|
So let's say you're using Rails, you need to add the strategy to your `Gemfile`:
|
@@ -28,7 +26,7 @@ Now just follow the README at: https://github.com/intridea/omniauth
|
|
28
26
|
|
29
27
|
## License
|
30
28
|
|
31
|
-
Copyright (c) 2013 by [Daniel Archer](https://github.com/danieljacobarcher/), [Jen Aprahamian](https://github.com/jennifermarie/), [Adam Bouck](https://github.com/abouck/)
|
29
|
+
Copyright (c) 2013 by [Daniel Archer](https://github.com/danieljacobarcher/), [Jen Aprahamian](https://github.com/jennifermarie/), [Adam Bouck](https://github.com/abouck/), [Ray Zane](https://github.com/rzane)
|
32
30
|
|
33
31
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
34
32
|
|
@@ -3,64 +3,75 @@ require 'omniauth/strategies/oauth2'
|
|
3
3
|
module OmniAuth
|
4
4
|
module Strategies
|
5
5
|
class Square < OmniAuth::Strategies::OAuth2
|
6
|
-
DEFAULT_SCOPE = 'merchant_id'
|
7
6
|
|
8
7
|
option :client_options, {
|
9
|
-
:site
|
10
|
-
:authorize_url => '
|
11
|
-
:token_url
|
8
|
+
:site => 'https://squareup.com/',
|
9
|
+
:authorize_url => '/oauth2/authorize',
|
10
|
+
:token_url => '/oauth2/token'
|
12
11
|
}
|
13
12
|
|
14
|
-
|
15
|
-
mode: :query,
|
16
|
-
header_format: 'OAuth %s'
|
17
|
-
}
|
18
|
-
|
19
|
-
option :provider_ignores_state, true
|
13
|
+
uid { raw_info['id'] }
|
20
14
|
|
21
|
-
|
22
|
-
|
15
|
+
info do
|
16
|
+
prune!(
|
17
|
+
:name => raw_info["name"],
|
18
|
+
:email => raw_info["email"],
|
19
|
+
:phone => (raw_info["business_phone"]||{}).values.join(''),
|
20
|
+
:location => (raw_info["business_address"]||{})["locality"]
|
21
|
+
)
|
23
22
|
end
|
24
23
|
|
25
|
-
|
24
|
+
extra do
|
25
|
+
{ :raw_info => raw_info }
|
26
|
+
end
|
26
27
|
|
27
|
-
|
28
|
+
def raw_info
|
29
|
+
@raw_info ||= access_token.get('https://connect.squareup.com/v1/me').parsed
|
28
30
|
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
protected
|
33
|
+
|
34
|
+
def build_access_token
|
35
|
+
parsed_response = fetch_access_token
|
36
|
+
|
37
|
+
parsed_response['expires_at'] = Time.parse(parsed_response['expires_at']).to_i
|
38
|
+
parsed_response.merge!(deep_symbolize(options.auth_token_params))
|
39
|
+
|
40
|
+
::OAuth2::AccessToken.from_hash(client, parsed_response)
|
37
41
|
end
|
38
42
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
private
|
44
|
+
|
45
|
+
def fetch_access_token
|
46
|
+
opts = access_token_request_payload
|
47
|
+
response = client.request(client.options[:token_method], client.token_url, opts)
|
48
|
+
parsed = response.parsed
|
49
|
+
error = ::OAuth2::Error.new(response)
|
50
|
+
fail(error) if opts[:raise_errors] && !(parsed.is_a?(Hash) && parsed['access_token'])
|
51
|
+
parsed
|
45
52
|
end
|
46
53
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
54
|
+
def access_token_request_payload
|
55
|
+
params = {
|
56
|
+
:code => request.params['code'],
|
57
|
+
:redirect_uri => callback_url
|
58
|
+
}
|
52
59
|
|
53
|
-
|
54
|
-
|
55
|
-
session['omniauth.request_type'] = params[:request_type] if v == 'request_type'
|
56
|
-
end
|
57
|
-
end
|
60
|
+
params.merge! client.auth_code.client_params
|
61
|
+
params.merge! token_params.to_hash(:symbolize_keys => true)
|
58
62
|
|
59
|
-
|
60
|
-
|
63
|
+
opts = {
|
64
|
+
:raise_errors => params.delete(:raise_errors),
|
65
|
+
:parse => params.delete(:parse),
|
66
|
+
:headers => {'Content-Type' => 'application/x-www-form-urlencoded'}
|
67
|
+
}
|
68
|
+
|
69
|
+
headers = params.delete(:headers)
|
70
|
+
opts[:body] = params
|
71
|
+
opts[:headers].merge!(headers) if headers
|
72
|
+
opts
|
61
73
|
end
|
62
74
|
|
63
|
-
private
|
64
75
|
def prune!(hash)
|
65
76
|
hash.delete_if do |_, value|
|
66
77
|
prune!(value) if value.is_a?(Hash)
|
@@ -71,4 +82,4 @@ module OmniAuth
|
|
71
82
|
end
|
72
83
|
end
|
73
84
|
|
74
|
-
OmniAuth.config.add_camelization 'square', 'Square'
|
85
|
+
OmniAuth.config.add_camelization 'square', 'Square'
|
data/omniauth-square.gemspec
CHANGED
@@ -5,8 +5,8 @@ require "omniauth-square/version"
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "omniauth-square"
|
7
7
|
s.version = Omniauth::Square::VERSION
|
8
|
-
s.authors = ["Daniel Archer", "Jennifer Aprahamian", "Adam Bouck"]
|
9
|
-
s.email = ["me@dja.io", "j.aprahamian@gmail.com", "adam.j.bouck@gmail.com"]
|
8
|
+
s.authors = ["Daniel Archer", "Jennifer Aprahamian", "Adam Bouck", "Ray Zane"]
|
9
|
+
s.email = ["me@dja.io", "j.aprahamian@gmail.com", "adam.j.bouck@gmail.com", "raymondzane@gmail.com"]
|
10
10
|
s.homepage = "https://github.com/danieljacobarcher/omniauth-square"
|
11
11
|
s.summary = %q{Square OAuth strategy for OmniAuth}
|
12
12
|
s.description = %q{Square OAuth strategy for OmniAuth}
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
|
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
|
-
s.add_runtime_dependency 'omniauth-oauth2'
|
22
|
+
s.add_runtime_dependency 'omniauth-oauth2', '~> 1.1.1'
|
23
23
|
s.add_development_dependency 'rspec', '~> 2.7'
|
24
24
|
s.add_development_dependency 'rack-test'
|
25
25
|
s.add_development_dependency 'simplecov'
|
@@ -1,117 +1,92 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'omniauth-square'
|
3
2
|
|
4
3
|
describe OmniAuth::Strategies::Square do
|
5
4
|
before :each do
|
6
|
-
@request = double('Request')
|
5
|
+
@request = double('Request', :scheme => '', :url => '')
|
7
6
|
@request.stub(:params) { {} }
|
8
|
-
@client_id = '123'
|
9
|
-
@client_secret = 'afalsf'
|
10
|
-
@raw_info = {
|
11
|
-
'name' => 'Sebastian Rabuini',
|
12
|
-
'email' => 'sebas@wasabit.com.ar',
|
13
|
-
'bio' => 'Sebas',
|
14
|
-
'blog_url' => 'sebas_blog',
|
15
|
-
'online_bio_url' => 'http://wasabitlabs.com',
|
16
|
-
'twitter_url' => 'http://twitter.com/#!/sebasr',
|
17
|
-
'facebook_url' => 'http://www.facebook.com/sebastian.rabuini',
|
18
|
-
'linkedin_url' => 'http://www.linkedin.com/in/srabuini',
|
19
|
-
'follower_count' => 6,
|
20
|
-
'investor' => false,
|
21
|
-
'locations' => [
|
22
|
-
{'id' => 1963, 'tag_type' => 'LocationTag', 'name' => 'buenos aires',
|
23
|
-
'display_name' => 'Buenos Aires',
|
24
|
-
'angellist_url' => 'https://angel.co/buenos-aires'}
|
25
|
-
],
|
26
|
-
'roles' => [
|
27
|
-
{'id' => 14726, 'tag_type' => 'RoleTag', 'name' => 'developer',
|
28
|
-
'display_name' => 'Developer',
|
29
|
-
'angellist_url' => 'https://angel.co/developer'},
|
30
|
-
{'id' => 14725, 'tag_type' => 'RoleTag', 'name' => 'entrepreneur',
|
31
|
-
'display_name' => 'Entrepreneur',
|
32
|
-
'angellist_url' => 'https://angel.co/entrepreneur-1'}
|
33
|
-
],
|
34
|
-
'skills' => [
|
35
|
-
{"id" => 82532, "tag_type" => "SkillTag", "name" => "ruby on rails",
|
36
|
-
"display_name" => "Ruby on Rails",
|
37
|
-
"angellist_url" => "https://angel.co/ruby-on-rails-1"}
|
38
|
-
],
|
39
|
-
'scopes' => ["email","comment","message","talent"],
|
40
|
-
'angellist_url' => 'https://angel.co/sebasr',
|
41
|
-
'image' => 'https://s3.amazonaws.com/photos.angel.co/users/90585-medium_jpg?1327684569'
|
42
|
-
}
|
43
7
|
end
|
44
8
|
|
45
9
|
subject do
|
46
|
-
|
47
|
-
OmniAuth::Strategies::Square.new(nil, *args).tap do |strategy|
|
10
|
+
OmniAuth::Strategies::Square.new(nil, @options || {}).tap do |strategy|
|
48
11
|
strategy.stub(:request) { @request }
|
49
12
|
end
|
50
13
|
end
|
51
14
|
|
52
|
-
it_should_behave_like 'an oauth2 strategy'
|
53
|
-
|
54
15
|
describe '#client' do
|
55
|
-
it 'has correct
|
56
|
-
subject.client.site.should eq('https://
|
16
|
+
it 'has correct Square site' do
|
17
|
+
subject.client.site.should eq('https://squareup.com/')
|
57
18
|
end
|
58
19
|
|
59
20
|
it 'has correct authorize url' do
|
60
|
-
subject.client.options[:authorize_url].should eq('
|
21
|
+
subject.client.options[:authorize_url].should eq('/oauth2/authorize')
|
61
22
|
end
|
62
23
|
|
63
24
|
it 'has correct token url' do
|
64
|
-
subject.client.options[:token_url].should eq('
|
25
|
+
subject.client.options[:token_url].should eq('/oauth2/token')
|
65
26
|
end
|
66
27
|
end
|
67
28
|
|
68
29
|
describe '#info' do
|
69
30
|
before :each do
|
31
|
+
@raw_info = {
|
32
|
+
"id" => "JGHJ0343",
|
33
|
+
"name" => "Dave Davis",
|
34
|
+
"email" => "dave@example.com",
|
35
|
+
"country_code" => "US",
|
36
|
+
"language_code" => "en-US",
|
37
|
+
"business_name" => "Dave's Milkshakes",
|
38
|
+
"business_address" => {
|
39
|
+
"address_line_1" => "1455 Market St",
|
40
|
+
"locality" => "San Francisco",
|
41
|
+
"administrative_district_level_1" => "CA",
|
42
|
+
"postal_code" => "94103"
|
43
|
+
},
|
44
|
+
"business_phone" => {
|
45
|
+
"calling_code" => "+1",
|
46
|
+
"number" => "4155551234"
|
47
|
+
},
|
48
|
+
"business_type" => "restaurants"
|
49
|
+
}
|
50
|
+
|
70
51
|
subject.stub(:raw_info) { @raw_info }
|
71
52
|
end
|
72
53
|
|
73
54
|
context 'when data is present in raw info' do
|
74
|
-
it 'returns the
|
75
|
-
subject.info[
|
55
|
+
it 'returns the name' do
|
56
|
+
subject.info[:name].should eq('Dave Davis')
|
76
57
|
end
|
77
58
|
|
78
|
-
it 'returns the
|
79
|
-
subject.info[
|
59
|
+
it 'returns the email' do
|
60
|
+
subject.info[:email].should eq('dave@example.com')
|
80
61
|
end
|
81
62
|
|
82
|
-
it 'returns the
|
83
|
-
subject.info[
|
63
|
+
it 'returns the phone number' do
|
64
|
+
subject.info[:phone].should eq('+14155551234')
|
84
65
|
end
|
85
66
|
|
86
|
-
it
|
87
|
-
subject.info[
|
67
|
+
it 'returns the user location' do
|
68
|
+
subject.info[:location].should eq('San Francisco')
|
88
69
|
end
|
89
70
|
|
90
|
-
it
|
91
|
-
|
71
|
+
it 'sets the location blank if business_address isnt provided' do
|
72
|
+
@raw_info.delete('business_address')
|
73
|
+
subject.info[:location].should be_nil
|
92
74
|
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
describe '#authorize_params' do
|
97
|
-
before :each do
|
98
|
-
subject.stub(:session => {})
|
99
|
-
end
|
100
75
|
|
101
|
-
|
102
|
-
|
76
|
+
it 'returns raw info' do
|
77
|
+
subject.extra[:raw_info]['business_name'].should eq("Dave's Milkshakes")
|
78
|
+
end
|
103
79
|
end
|
104
80
|
end
|
105
81
|
|
106
82
|
describe '#credentials' do
|
107
83
|
before :each do
|
108
84
|
@access_token = double('OAuth2::AccessToken')
|
109
|
-
@access_token.stub(:token)
|
85
|
+
@access_token.stub(:token)
|
110
86
|
@access_token.stub(:expires?)
|
111
87
|
@access_token.stub(:expires_at)
|
112
88
|
@access_token.stub(:refresh_token)
|
113
89
|
subject.stub(:access_token) { @access_token }
|
114
|
-
subject.stub(:raw_info) { @raw_info }
|
115
90
|
end
|
116
91
|
|
117
92
|
it 'returns a Hash' do
|
@@ -119,13 +94,10 @@ describe OmniAuth::Strategies::Square do
|
|
119
94
|
end
|
120
95
|
|
121
96
|
it 'returns the token' do
|
97
|
+
@access_token.stub(:token) { '123' }
|
122
98
|
subject.credentials['token'].should eq('123')
|
123
99
|
end
|
124
100
|
|
125
|
-
it "return scopes" do
|
126
|
-
subject.credentials['scope'].should eq("email comment message talent")
|
127
|
-
end
|
128
|
-
|
129
101
|
it 'returns the expiry status' do
|
130
102
|
@access_token.stub(:expires?) { true }
|
131
103
|
subject.credentials['expires'].should eq(true)
|
@@ -157,4 +129,34 @@ describe OmniAuth::Strategies::Square do
|
|
157
129
|
subject.credentials.should_not have_key('refresh_token')
|
158
130
|
end
|
159
131
|
end
|
132
|
+
|
133
|
+
describe '#build_access_token' do
|
134
|
+
it 'converts iso8601 expires_at to an integer' do
|
135
|
+
now = Time.now
|
136
|
+
subject.stub(:fetch_access_token).and_return({'expires_at' => now.iso8601})
|
137
|
+
token = subject.send(:build_access_token)
|
138
|
+
expect(token.expires_at).to eq(now.to_i)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
describe '#access_token_request_payload' do
|
143
|
+
before do
|
144
|
+
@request.stub(:params).and_return('code' => '11111')
|
145
|
+
subject.stub(:callback_url).and_return('http://example.com')
|
146
|
+
end
|
147
|
+
|
148
|
+
let!(:payload) { subject.send(:access_token_request_payload) }
|
149
|
+
|
150
|
+
it 'sets the Content-Type header' do
|
151
|
+
expect(payload[:headers]['Content-Type']).to eq('application/x-www-form-urlencoded')
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'sets the redirect_uri' do
|
155
|
+
expect(payload[:body][:redirect_uri]).to eq('http://example.com')
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'sets the authorization code' do
|
159
|
+
expect(payload[:body][:code]).to eq('11111')
|
160
|
+
end
|
161
|
+
end
|
160
162
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
|
-
require '
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
2
3
|
require 'rspec'
|
3
|
-
|
4
|
+
require 'rack/test'
|
5
|
+
require 'webmock/rspec'
|
6
|
+
require 'omniauth'
|
7
|
+
require 'omniauth-square'
|
4
8
|
|
5
9
|
RSpec.configure do |config|
|
10
|
+
config.include WebMock::API
|
11
|
+
config.include Rack::Test::Methods
|
12
|
+
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
6
13
|
end
|
metadata
CHANGED
@@ -1,31 +1,32 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-square
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.9'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Archer
|
8
8
|
- Jennifer Aprahamian
|
9
9
|
- Adam Bouck
|
10
|
+
- Ray Zane
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date:
|
14
|
+
date: 2014-07-18 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: omniauth-oauth2
|
17
18
|
requirement: !ruby/object:Gem::Requirement
|
18
19
|
requirements:
|
19
|
-
- -
|
20
|
+
- - ~>
|
20
21
|
- !ruby/object:Gem::Version
|
21
|
-
version:
|
22
|
+
version: 1.1.1
|
22
23
|
type: :runtime
|
23
24
|
prerelease: false
|
24
25
|
version_requirements: !ruby/object:Gem::Requirement
|
25
26
|
requirements:
|
26
|
-
- -
|
27
|
+
- - ~>
|
27
28
|
- !ruby/object:Gem::Version
|
28
|
-
version:
|
29
|
+
version: 1.1.1
|
29
30
|
- !ruby/object:Gem::Dependency
|
30
31
|
name: rspec
|
31
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,6 +88,7 @@ email:
|
|
87
88
|
- me@dja.io
|
88
89
|
- j.aprahamian@gmail.com
|
89
90
|
- adam.j.bouck@gmail.com
|
91
|
+
- raymondzane@gmail.com
|
90
92
|
executables: []
|
91
93
|
extensions: []
|
92
94
|
extra_rdoc_files: []
|
@@ -101,7 +103,6 @@ files:
|
|
101
103
|
- omniauth-square.gemspec
|
102
104
|
- spec/omniauth/strategies/square_spec.rb
|
103
105
|
- spec/spec_helper.rb
|
104
|
-
- spec/support/shared_examples.rb
|
105
106
|
homepage: https://github.com/danieljacobarcher/omniauth-square
|
106
107
|
licenses:
|
107
108
|
- MIT
|
@@ -129,4 +130,3 @@ summary: Square OAuth strategy for OmniAuth
|
|
129
130
|
test_files:
|
130
131
|
- spec/omniauth/strategies/square_spec.rb
|
131
132
|
- spec/spec_helper.rb
|
132
|
-
- spec/support/shared_examples.rb
|
@@ -1,23 +0,0 @@
|
|
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 '#token_params' do
|
11
|
-
it 'should include any authorize params passed in the :authorize_params option' do
|
12
|
-
@options = { :token_params => { :foo => 'bar', :baz => 'zip' } }
|
13
|
-
subject.token_params['foo'].should eq('bar')
|
14
|
-
subject.token_params['baz'].should eq('zip')
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'should include top-level options that are marked as :authorize_options' do
|
18
|
-
@options = { :token_options => [:scope, :foo], :scope => 'bar', :foo => 'baz' }
|
19
|
-
subject.token_params['scope'].should eq('bar')
|
20
|
-
subject.token_params['foo'].should eq('baz')
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|