omniauth-foursquare 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/.travis.yml +6 -0
- data/README.md +42 -0
- data/Rakefile +6 -0
- data/lib/omniauth-foursquare/version.rb +1 -1
- data/spec/omniauth/strategies/foursquare_spec.rb +99 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/support/shared_examples.rb +37 -0
- metadata +27 -18
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/.travis.yml
ADDED
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# OmniAuth Foursquare
|
2
|
+
|
3
|
+
This gem contains the Foursquare strategy for OmniAuth.
|
4
|
+
|
5
|
+
Foursquare uses the OAuth2 flow, you can read about it here: https://developer.foursquare.com/docs/oauth.html
|
6
|
+
|
7
|
+
## How To Use It
|
8
|
+
|
9
|
+
So let's say you're using Rails, you need to add the strategy to your `Gemfile`:
|
10
|
+
|
11
|
+
gem 'omniauth-foursquare'
|
12
|
+
|
13
|
+
You can pull them in directly from github e.g.:
|
14
|
+
|
15
|
+
gem 'omniauth-foursquare', :git => 'https://github.com/arunagw/omniauth-foursquare.git'
|
16
|
+
|
17
|
+
Once these are in, you need to add the following to your `config/initializers/omniauth.rb`:
|
18
|
+
|
19
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
20
|
+
provider :foursquare, "consumer_key", "consumer_secret"
|
21
|
+
end
|
22
|
+
|
23
|
+
You will obviously have to put in your key and secret, which you get when you register your app with Foursquare (they call them API Key and Secret Key).
|
24
|
+
|
25
|
+
Now just follow the README at: https://github.com/intridea/omniauth
|
26
|
+
|
27
|
+
## Supported Rubies
|
28
|
+
|
29
|
+
OmniAuth Foursquare is tested under 1.8.7, 1.9.2, 1.9.3 and Ruby Enterprise Edition.
|
30
|
+
|
31
|
+
[![CI Build
|
32
|
+
Status](https://secure.travis-ci.org/arunagw/omniauth-foursquare.png)](http://travis-ci.org/arunagw/omniauth-foursquare)
|
33
|
+
|
34
|
+
## License
|
35
|
+
|
36
|
+
Copyright (c) 2011 by Arun Agrawal
|
37
|
+
|
38
|
+
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:
|
39
|
+
|
40
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
CHANGED
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'omniauth-foursquare'
|
3
|
+
|
4
|
+
describe OmniAuth::Strategies::Foursquare do
|
5
|
+
before :each do
|
6
|
+
@request = double('Request')
|
7
|
+
@request.stub(:params) { {} }
|
8
|
+
end
|
9
|
+
|
10
|
+
subject do
|
11
|
+
OmniAuth::Strategies::Foursquare.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 Foursquare site' do
|
20
|
+
subject.client.site.should eq('https://foursquare.com')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'has correct authorize url' do
|
24
|
+
subject.client.options[:authorize_url].should eq('/oauth2/authorize')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'has correct token url' do
|
28
|
+
subject.client.options[:token_url].should eq('/oauth2/access_token')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#info' do
|
33
|
+
before :each do
|
34
|
+
@raw_info ||= { 'firstName' => 'Fred', 'lastName' => 'Smith' }
|
35
|
+
subject.stub(:raw_info) { @raw_info }
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when data is present in raw info' do
|
39
|
+
it 'returns the first name' do
|
40
|
+
subject.info[:first_name].should eq('Fred')
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'returns the last name' do
|
44
|
+
subject.info[:last_name].should eq('Smith')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#credentials' do
|
50
|
+
before :each do
|
51
|
+
@access_token = double('OAuth2::AccessToken')
|
52
|
+
@access_token.stub(:token)
|
53
|
+
@access_token.stub(:expires?)
|
54
|
+
@access_token.stub(:expires_at)
|
55
|
+
@access_token.stub(:refresh_token)
|
56
|
+
subject.stub(:access_token) { @access_token }
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'returns a Hash' do
|
60
|
+
subject.credentials.should be_a(Hash)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'returns the token' do
|
64
|
+
@access_token.stub(:token) { '123' }
|
65
|
+
subject.credentials['token'].should eq('123')
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'returns the expiry status' do
|
69
|
+
@access_token.stub(:expires?) { true }
|
70
|
+
subject.credentials['expires'].should eq(true)
|
71
|
+
|
72
|
+
@access_token.stub(:expires?) { false }
|
73
|
+
subject.credentials['expires'].should eq(false)
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'returns the refresh token and expiry time when expiring' do
|
77
|
+
ten_mins_from_now = (Time.now + 360).to_i
|
78
|
+
@access_token.stub(:expires?) { true }
|
79
|
+
@access_token.stub(:refresh_token) { '321' }
|
80
|
+
@access_token.stub(:expires_at) { ten_mins_from_now }
|
81
|
+
subject.credentials['refresh_token'].should eq('321')
|
82
|
+
subject.credentials['expires_at'].should eq(ten_mins_from_now)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'does not return the refresh token when it is nil and expiring' do
|
86
|
+
@access_token.stub(:expires?) { true }
|
87
|
+
@access_token.stub(:refresh_token) { nil }
|
88
|
+
subject.credentials['refresh_token'].should be_nil
|
89
|
+
subject.credentials.should_not have_key('refresh_token')
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'does not return the refresh token when not expiring' do
|
93
|
+
@access_token.stub(:expires?) { false }
|
94
|
+
@access_token.stub(:refresh_token) { 'XXX' }
|
95
|
+
subject.credentials['refresh_token'].should be_nil
|
96
|
+
subject.credentials.should_not have_key('refresh_token')
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-foursquare
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-11-
|
12
|
+
date: 2011-11-15 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: omniauth
|
16
|
-
requirement: &
|
16
|
+
requirement: &70335668645640 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '1.0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70335668645640
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: omniauth-oauth2
|
27
|
-
requirement: &
|
27
|
+
requirement: &70335668644900 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '1.0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70335668644900
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70335668644340 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '2.7'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70335668644340
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rack-test
|
49
|
-
requirement: &
|
49
|
+
requirement: &70335668642680 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70335668642680
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: simplecov
|
60
|
-
requirement: &
|
60
|
+
requirement: &70335668642040 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70335668642040
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: webmock
|
71
|
-
requirement: &
|
71
|
+
requirement: &70335668641500 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70335668641500
|
80
80
|
description: Foursquare OAuth strategy for OmniAuth
|
81
81
|
email:
|
82
82
|
- arunagw@gmail.com
|
@@ -85,12 +85,18 @@ extensions: []
|
|
85
85
|
extra_rdoc_files: []
|
86
86
|
files:
|
87
87
|
- .gitignore
|
88
|
+
- .rspec
|
89
|
+
- .travis.yml
|
88
90
|
- Gemfile
|
91
|
+
- README.md
|
89
92
|
- Rakefile
|
90
93
|
- lib/omniauth-foursquare.rb
|
91
94
|
- lib/omniauth-foursquare/version.rb
|
92
95
|
- lib/omniauth/strategies/foursquare.rb
|
93
96
|
- omniauth-foursquare.gemspec
|
97
|
+
- spec/omniauth/strategies/foursquare_spec.rb
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
- spec/support/shared_examples.rb
|
94
100
|
homepage: https://github.com/arunagw/omniauth-foursquare
|
95
101
|
licenses: []
|
96
102
|
post_install_message:
|
@@ -105,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
111
|
version: '0'
|
106
112
|
segments:
|
107
113
|
- 0
|
108
|
-
hash:
|
114
|
+
hash: 1474676171529160353
|
109
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
116
|
none: false
|
111
117
|
requirements:
|
@@ -114,11 +120,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
120
|
version: '0'
|
115
121
|
segments:
|
116
122
|
- 0
|
117
|
-
hash:
|
123
|
+
hash: 1474676171529160353
|
118
124
|
requirements: []
|
119
125
|
rubyforge_project: omniauth-foursquare
|
120
|
-
rubygems_version: 1.8.
|
126
|
+
rubygems_version: 1.8.10
|
121
127
|
signing_key:
|
122
128
|
specification_version: 3
|
123
129
|
summary: Foursquare OAuth strategy for OmniAuth
|
124
|
-
test_files:
|
130
|
+
test_files:
|
131
|
+
- spec/omniauth/strategies/foursquare_spec.rb
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
- spec/support/shared_examples.rb
|