omniauth-google-oauth2 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +5 -0
- data/examples/config.ru +4 -2
- data/lib/omniauth/google_oauth2/version.rb +1 -1
- data/lib/omniauth/strategies/google_oauth2.rb +4 -3
- data/omniauth-contrib.gemspec +3 -0
- data/spec/omniauth/strategies/google_oauth2_spec.rb +38 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/support/shared_examples.rb +37 -0
- metadata +40 -5
data/Rakefile
CHANGED
data/examples/config.ru
CHANGED
@@ -7,6 +7,8 @@ require 'sinatra'
|
|
7
7
|
require 'omniauth'
|
8
8
|
require 'omniauth-google-oauth2'
|
9
9
|
|
10
|
+
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
|
11
|
+
|
10
12
|
class App < Sinatra::Base
|
11
13
|
get '/' do
|
12
14
|
<<-HTML
|
@@ -18,12 +20,12 @@ class App < Sinatra::Base
|
|
18
20
|
|
19
21
|
get '/auth/:provider/callback' do
|
20
22
|
content_type 'text/plain'
|
21
|
-
request.env['omniauth.auth'].to_hash.inspect
|
23
|
+
request.env['omniauth.auth'].to_hash.inspect rescue "No Data"
|
22
24
|
end
|
23
25
|
|
24
26
|
get '/auth/failure' do
|
25
27
|
content_type 'text/plain'
|
26
|
-
request.env['omniauth.auth'].to_hash.inspect
|
28
|
+
request.env['omniauth.auth'].to_hash.inspect rescue "No Data"
|
27
29
|
end
|
28
30
|
end
|
29
31
|
|
@@ -12,10 +12,11 @@ module OmniAuth
|
|
12
12
|
}
|
13
13
|
|
14
14
|
def request_phase
|
15
|
-
|
15
|
+
setup_authorize_params
|
16
|
+
super
|
16
17
|
end
|
17
18
|
|
18
|
-
def
|
19
|
+
def setup_authorize_params
|
19
20
|
opts = {
|
20
21
|
:client_id => options[:client_id],
|
21
22
|
:redirect_uri => callback_url,
|
@@ -25,7 +26,7 @@ module OmniAuth
|
|
25
26
|
google_email_scope = "www.googleapis.com/auth/userinfo.email"
|
26
27
|
opts[:scope] ||= "https://#{google_email_scope}"
|
27
28
|
opts[:scope] << " https://#{google_email_scope}" unless opts[:scope] =~ %r[http[s]?:\/\/#{google_email_scope}]
|
28
|
-
opts
|
29
|
+
options[:authorize_params] = opts.merge(options[:authorize_params])
|
29
30
|
end
|
30
31
|
|
31
32
|
def auth_hash
|
data/omniauth-contrib.gemspec
CHANGED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'omniauth-google-oauth2'
|
3
|
+
|
4
|
+
describe OmniAuth::Strategies::GoogleOauth2 do
|
5
|
+
subject do
|
6
|
+
OmniAuth::Strategies::GoogleOauth2.new(nil, @options || {})
|
7
|
+
end
|
8
|
+
|
9
|
+
it_should_behave_like 'an oauth2 strategy'
|
10
|
+
|
11
|
+
describe '#client' do
|
12
|
+
it 'has correct Google site' do
|
13
|
+
subject.client.site.should eq('https://accounts.google.com')
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'has correct authorize url' do
|
17
|
+
subject.client.options[:authorize_url].should eq('/o/oauth2/auth')
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'has correct token url' do
|
21
|
+
subject.client.options[:token_url].should eq('/o/oauth2/token')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe '#callback_path' do
|
26
|
+
it "has the correct callback path" do
|
27
|
+
subject.callback_path.should eq('/auth/google_oauth2/callback')
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# These are setup during the request_phase
|
32
|
+
# At init they are blank
|
33
|
+
describe '#authorize_params' do
|
34
|
+
it "has no authorize params at init" do
|
35
|
+
subject.authorize_params.should be_empty
|
36
|
+
end
|
37
|
+
end
|
38
|
+
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 token params passed in the :token_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 :token_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,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniauth-google-oauth2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Josh Ellithorpe
|
@@ -47,6 +47,36 @@ dependencies:
|
|
47
47
|
version: "0"
|
48
48
|
type: :runtime
|
49
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: 23
|
59
|
+
segments:
|
60
|
+
- 2
|
61
|
+
- 6
|
62
|
+
- 0
|
63
|
+
version: 2.6.0
|
64
|
+
type: :development
|
65
|
+
version_requirements: *id003
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: rake
|
68
|
+
prerelease: false
|
69
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
hash: 3
|
75
|
+
segments:
|
76
|
+
- 0
|
77
|
+
version: "0"
|
78
|
+
type: :development
|
79
|
+
version_requirements: *id004
|
50
80
|
description: A Google oauth2 strategy for OmniAuth 1.0
|
51
81
|
email:
|
52
82
|
- quest@mac.com
|
@@ -68,6 +98,9 @@ files:
|
|
68
98
|
- lib/omniauth/google_oauth2/version.rb
|
69
99
|
- lib/omniauth/strategies/google_oauth2.rb
|
70
100
|
- omniauth-contrib.gemspec
|
101
|
+
- spec/omniauth/strategies/google_oauth2_spec.rb
|
102
|
+
- spec/spec_helper.rb
|
103
|
+
- spec/support/shared_examples.rb
|
71
104
|
has_rdoc: true
|
72
105
|
homepage: ""
|
73
106
|
licenses: []
|
@@ -102,5 +135,7 @@ rubygems_version: 1.6.2
|
|
102
135
|
signing_key:
|
103
136
|
specification_version: 3
|
104
137
|
summary: A Google oauth2 strategy for OmniAuth 1.0
|
105
|
-
test_files:
|
106
|
-
|
138
|
+
test_files:
|
139
|
+
- spec/omniauth/strategies/google_oauth2_spec.rb
|
140
|
+
- spec/spec_helper.rb
|
141
|
+
- spec/support/shared_examples.rb
|