omniauth-groupme 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +6 -0
- data/LICENSE +18 -0
- data/README.md +6 -0
- data/Rakefile +7 -0
- data/lib/omniauth-groupme.rb +8 -0
- data/lib/omniauth-groupme/version.rb +5 -0
- data/lib/omniauth/strategies/groupme.rb +58 -0
- data/omniauth-groupme.gemspec +27 -0
- data/spec/omniauth/strategies/groupme_spec.rb +120 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/support/shared_examples.rb +37 -0
- metadata +166 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (C) 2012 GroupMe Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in the
|
5
|
+
Software without restriction, including without limitation the rights to use, copy,
|
6
|
+
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
7
|
+
and to permit persons to whom the Software is furnished to do so, subject to the
|
8
|
+
following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all copies
|
11
|
+
or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
14
|
+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
15
|
+
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
16
|
+
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
17
|
+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
18
|
+
DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'omniauth-oauth2'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
class GroupMe < OmniAuth::Strategies::OAuth2
|
6
|
+
option :client_options, {
|
7
|
+
:site => 'https://groupme.com',
|
8
|
+
:authorize_url => '/oauth/authorize',
|
9
|
+
:token_url => '/oauth/access_token'
|
10
|
+
}
|
11
|
+
|
12
|
+
uid { raw_info['id'] }
|
13
|
+
|
14
|
+
info do
|
15
|
+
first_name, last_name = raw_info['name'].split(/\s+/)
|
16
|
+
{
|
17
|
+
:first_name => first_name,
|
18
|
+
:last_name => last_name,
|
19
|
+
:name => raw_info['name'],
|
20
|
+
:email => raw_info['email'],
|
21
|
+
:image => raw_info['avatar_url'],
|
22
|
+
:location => raw_info['country']
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
extra do
|
27
|
+
{ :raw_info => raw_info }
|
28
|
+
end
|
29
|
+
|
30
|
+
def request_phase
|
31
|
+
options[:authorize_params] = client_params.merge(options[:authorize_params])
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
35
|
+
def auth_hash
|
36
|
+
OmniAuth::Utils.deep_merge(super, client_params.merge({
|
37
|
+
:grant_type => 'authorization_code'}))
|
38
|
+
end
|
39
|
+
|
40
|
+
def raw_info
|
41
|
+
access_token.options[:mode] = :query
|
42
|
+
access_token.options[:param_name] = :oauth_token
|
43
|
+
response = access_token.get('https://v2.groupme.com/users/me').parsed['response']
|
44
|
+
@raw_info ||= response['user']
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def client_params
|
50
|
+
{
|
51
|
+
:client_id => options[:client_id],
|
52
|
+
:redirect_uri => callback_url,
|
53
|
+
:response_type => "code"
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "omniauth-groupme/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "omniauth-groupme"
|
7
|
+
s.version = Omniauth::GroupMe::VERSION
|
8
|
+
s.authors = ["Pat Nakajima"]
|
9
|
+
s.email = ["pat@groupme.com"]
|
10
|
+
s.homepage = "https://github.com/groupme/omniauth-groupme"
|
11
|
+
s.summary = %q{GroupMe OAuth strategy for OmniAuth}
|
12
|
+
s.description = %q{GroupMe OAuth strategy for OmniAuth}
|
13
|
+
|
14
|
+
s.rubyforge_project = "omniauth-groupme"
|
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,120 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'omniauth-groupme'
|
3
|
+
|
4
|
+
describe OmniAuth::Strategies::GroupMe do
|
5
|
+
before :each do
|
6
|
+
@request = double('Request')
|
7
|
+
@request.stub(:params) { {} }
|
8
|
+
end
|
9
|
+
|
10
|
+
subject do
|
11
|
+
OmniAuth::Strategies::GroupMe.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 GroupMe site' do
|
20
|
+
subject.client.site.should eq('https://groupme.com')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'has correct authorize url' do
|
24
|
+
subject.client.options[:authorize_url].should eq('/oauth/authorize')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'has correct token url' do
|
28
|
+
subject.client.options[:token_url].should eq('/oauth/access_token')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#info' do
|
33
|
+
before :each do
|
34
|
+
@raw_info = {
|
35
|
+
'name' => 'Fred Smith',
|
36
|
+
'email' => 'fred@example.com',
|
37
|
+
'avatar_url' => 'https://img-s.groupme.com/userpix_thumbs/blank_boy.jpg',
|
38
|
+
'country' => 'Chicago'
|
39
|
+
}
|
40
|
+
subject.stub(:raw_info) { @raw_info }
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when data is present in raw info' do
|
44
|
+
it 'returns the combined name' do
|
45
|
+
subject.info[:name].should eq('Fred Smith')
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'returns the first name' do
|
49
|
+
subject.info[:first_name].should eq('Fred')
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'returns the last name' do
|
53
|
+
subject.info[:last_name].should eq('Smith')
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'returns the email' do
|
57
|
+
subject.info[:email].should eq('fred@example.com')
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'returns the user image' do
|
61
|
+
subject.info[:image].should eq('https://img-s.groupme.com/userpix_thumbs/blank_boy.jpg')
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'returns the user location' do
|
65
|
+
subject.info[:location].should eq('Chicago')
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#credentials' do
|
71
|
+
before :each do
|
72
|
+
@access_token = double('OAuth2::AccessToken')
|
73
|
+
@access_token.stub(:token)
|
74
|
+
@access_token.stub(:expires?)
|
75
|
+
@access_token.stub(:expires_at)
|
76
|
+
@access_token.stub(:refresh_token)
|
77
|
+
subject.stub(:access_token) { @access_token }
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'returns a Hash' do
|
81
|
+
subject.credentials.should be_a(Hash)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'returns the token' do
|
85
|
+
@access_token.stub(:token) { '123' }
|
86
|
+
subject.credentials['token'].should eq('123')
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'returns the expiry status' do
|
90
|
+
@access_token.stub(:expires?) { true }
|
91
|
+
subject.credentials['expires'].should eq(true)
|
92
|
+
|
93
|
+
@access_token.stub(:expires?) { false }
|
94
|
+
subject.credentials['expires'].should eq(false)
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'returns the refresh token and expiry time when expiring' do
|
98
|
+
ten_mins_from_now = (Time.now + 360).to_i
|
99
|
+
@access_token.stub(:expires?) { true }
|
100
|
+
@access_token.stub(:refresh_token) { '321' }
|
101
|
+
@access_token.stub(:expires_at) { ten_mins_from_now }
|
102
|
+
subject.credentials['refresh_token'].should eq('321')
|
103
|
+
subject.credentials['expires_at'].should eq(ten_mins_from_now)
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'does not return the refresh token when it is nil and expiring' do
|
107
|
+
@access_token.stub(:expires?) { true }
|
108
|
+
@access_token.stub(:refresh_token) { nil }
|
109
|
+
subject.credentials['refresh_token'].should be_nil
|
110
|
+
subject.credentials.should_not have_key('refresh_token')
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'does not return the refresh token when not expiring' do
|
114
|
+
@access_token.stub(:expires?) { false }
|
115
|
+
@access_token.stub(:refresh_token) { 'XXX' }
|
116
|
+
subject.credentials['refresh_token'].should be_nil
|
117
|
+
subject.credentials.should_not have_key('refresh_token')
|
118
|
+
end
|
119
|
+
end
|
120
|
+
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
ADDED
@@ -0,0 +1,166 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-groupme
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 17
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 7
|
10
|
+
version: 0.0.7
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Pat Nakajima
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-05-10 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: 15
|
44
|
+
segments:
|
45
|
+
- 1
|
46
|
+
- 0
|
47
|
+
version: "1.0"
|
48
|
+
type: :runtime
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: rspec
|
52
|
+
prerelease: false
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ~>
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
hash: 13
|
59
|
+
segments:
|
60
|
+
- 2
|
61
|
+
- 7
|
62
|
+
version: "2.7"
|
63
|
+
type: :development
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: rack-test
|
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: simplecov
|
81
|
+
prerelease: false
|
82
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
type: :development
|
92
|
+
version_requirements: *id005
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: webmock
|
95
|
+
prerelease: false
|
96
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
hash: 3
|
102
|
+
segments:
|
103
|
+
- 0
|
104
|
+
version: "0"
|
105
|
+
type: :development
|
106
|
+
version_requirements: *id006
|
107
|
+
description: GroupMe OAuth strategy for OmniAuth
|
108
|
+
email:
|
109
|
+
- pat@groupme.com
|
110
|
+
executables: []
|
111
|
+
|
112
|
+
extensions: []
|
113
|
+
|
114
|
+
extra_rdoc_files: []
|
115
|
+
|
116
|
+
files:
|
117
|
+
- .gitignore
|
118
|
+
- Gemfile
|
119
|
+
- LICENSE
|
120
|
+
- README.md
|
121
|
+
- Rakefile
|
122
|
+
- lib/omniauth-groupme.rb
|
123
|
+
- lib/omniauth-groupme/version.rb
|
124
|
+
- lib/omniauth/strategies/groupme.rb
|
125
|
+
- omniauth-groupme.gemspec
|
126
|
+
- spec/omniauth/strategies/groupme_spec.rb
|
127
|
+
- spec/spec_helper.rb
|
128
|
+
- spec/support/shared_examples.rb
|
129
|
+
homepage: https://github.com/groupme/omniauth-groupme
|
130
|
+
licenses: []
|
131
|
+
|
132
|
+
post_install_message:
|
133
|
+
rdoc_options: []
|
134
|
+
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
hash: 3
|
143
|
+
segments:
|
144
|
+
- 0
|
145
|
+
version: "0"
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
hash: 3
|
152
|
+
segments:
|
153
|
+
- 0
|
154
|
+
version: "0"
|
155
|
+
requirements: []
|
156
|
+
|
157
|
+
rubyforge_project: omniauth-groupme
|
158
|
+
rubygems_version: 1.8.15
|
159
|
+
signing_key:
|
160
|
+
specification_version: 3
|
161
|
+
summary: GroupMe OAuth strategy for OmniAuth
|
162
|
+
test_files:
|
163
|
+
- spec/omniauth/strategies/groupme_spec.rb
|
164
|
+
- spec/spec_helper.rb
|
165
|
+
- spec/support/shared_examples.rb
|
166
|
+
has_rdoc:
|