omniauth-google 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/Gemfile +16 -0
- data/Gemfile.lock +48 -0
- data/LICENSE.txt +20 -0
- data/README.md +43 -0
- data/Rakefile +43 -0
- data/VERSION +1 -0
- data/lib/omniauth-google.rb +3 -0
- data/lib/omniauth-google/version.rb +5 -0
- data/lib/omniauth/strategies/google.rb +87 -0
- data/omniauth-google.gemspec +73 -0
- data/spec/omniauth/strategies/google_spec.rb +155 -0
- data/spec/spec_helper.rb +12 -0
- metadata +151 -0
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
|
3
|
+
gem 'omniauth', "~> 1.0.0"
|
4
|
+
gem 'omniauth-oauth'
|
5
|
+
gem 'multi_json'
|
6
|
+
|
7
|
+
group :development do
|
8
|
+
gem "bundler"
|
9
|
+
gem "jeweler"
|
10
|
+
end
|
11
|
+
|
12
|
+
group :development, :test do
|
13
|
+
gem "rack-test"
|
14
|
+
gem "rspec"
|
15
|
+
gem "webmock"
|
16
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
addressable (2.2.6)
|
5
|
+
crack (0.3.1)
|
6
|
+
diff-lcs (1.1.3)
|
7
|
+
git (1.2.5)
|
8
|
+
hashie (1.2.0)
|
9
|
+
jeweler (1.6.4)
|
10
|
+
bundler (~> 1.0)
|
11
|
+
git (>= 1.2.5)
|
12
|
+
rake
|
13
|
+
multi_json (1.0.4)
|
14
|
+
oauth (0.4.5)
|
15
|
+
omniauth (1.0.1)
|
16
|
+
hashie (~> 1.2)
|
17
|
+
rack
|
18
|
+
omniauth-oauth (1.0.0)
|
19
|
+
oauth
|
20
|
+
omniauth (~> 1.0)
|
21
|
+
rack (1.3.5)
|
22
|
+
rack-test (0.6.1)
|
23
|
+
rack (>= 1.0)
|
24
|
+
rake (0.9.2.2)
|
25
|
+
rspec (2.7.0)
|
26
|
+
rspec-core (~> 2.7.0)
|
27
|
+
rspec-expectations (~> 2.7.0)
|
28
|
+
rspec-mocks (~> 2.7.0)
|
29
|
+
rspec-core (2.7.1)
|
30
|
+
rspec-expectations (2.7.0)
|
31
|
+
diff-lcs (~> 1.1.2)
|
32
|
+
rspec-mocks (2.7.0)
|
33
|
+
webmock (1.7.8)
|
34
|
+
addressable (~> 2.2, > 2.2.5)
|
35
|
+
crack (>= 0.1.7)
|
36
|
+
|
37
|
+
PLATFORMS
|
38
|
+
ruby
|
39
|
+
|
40
|
+
DEPENDENCIES
|
41
|
+
bundler
|
42
|
+
jeweler
|
43
|
+
multi_json
|
44
|
+
omniauth (~> 1.0.0)
|
45
|
+
omniauth-oauth
|
46
|
+
rack-test
|
47
|
+
rspec
|
48
|
+
webmock
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Yesware, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# omniauth-google
|
2
|
+
|
3
|
+
A Google OAuth strategy for OmniAuth 1.0.
|
4
|
+
|
5
|
+
## Installing
|
6
|
+
|
7
|
+
Add to your `Gemfile`:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'omniauth-google'
|
11
|
+
```
|
12
|
+
|
13
|
+
Then `bundle install`.
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
Add the middleware to a Rails app in `config/initializers/omniauth.rb`:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
Rails.application.config.middleware.use OmniAuth::Builder do
|
21
|
+
provider :google, CONSUMER_KEY, CONSUMER_SECRET
|
22
|
+
end
|
23
|
+
```
|
24
|
+
|
25
|
+
## Acknowledgments
|
26
|
+
|
27
|
+
This code was extracted from OmniAuth v0.3 and is really the work of those folks!
|
28
|
+
|
29
|
+
## Contributing to omniauth-google
|
30
|
+
|
31
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
32
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
33
|
+
* Fork the project
|
34
|
+
* Start a feature/bugfix branch
|
35
|
+
* Commit and push until you are happy with your contribution
|
36
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
37
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
38
|
+
|
39
|
+
## Copyright
|
40
|
+
|
41
|
+
Copyright (c) 2011 Yesware, Inc. See LICENSE.txt for
|
42
|
+
further details.
|
43
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
gem.name = "omniauth-google"
|
17
|
+
gem.homepage = "http://github.com/Yesware/omniauth-google"
|
18
|
+
gem.license = "MIT"
|
19
|
+
gem.summary = %Q{A Google OAuth strategy for OmniAuth 1.0}
|
20
|
+
gem.description = gem.summary
|
21
|
+
gem.email = "info@yesware.com"
|
22
|
+
gem.authors = ["mjbellantoni@yahoo.com"]
|
23
|
+
# dependencies defined in Gemfile
|
24
|
+
end
|
25
|
+
Jeweler::RubygemsDotOrgTasks.new
|
26
|
+
|
27
|
+
require 'rspec/core'
|
28
|
+
require 'rspec/core/rake_task'
|
29
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
30
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
31
|
+
end
|
32
|
+
|
33
|
+
task :default => :test
|
34
|
+
|
35
|
+
require 'rake/rdoctask'
|
36
|
+
Rake::RDocTask.new do |rdoc|
|
37
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
38
|
+
|
39
|
+
rdoc.rdoc_dir = 'rdoc'
|
40
|
+
rdoc.title = "omniauth-google #{version}"
|
41
|
+
rdoc.rdoc_files.include('README*')
|
42
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
43
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'omniauth-oauth'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
# Authenticate to Google via OAuth and retrieve basic
|
6
|
+
# user information.
|
7
|
+
#
|
8
|
+
# Usage:
|
9
|
+
# use OmniAuth::Strategies::Google, 'consumerkey', 'consumersecret'
|
10
|
+
class Google < OmniAuth::Strategies::OAuth
|
11
|
+
def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
|
12
|
+
client_options = {
|
13
|
+
:access_token_path => '/accounts/OAuthGetAccessToken',
|
14
|
+
:authorize_path => '/accounts/OAuthAuthorizeToken',
|
15
|
+
:request_token_path => '/accounts/OAuthGetRequestToken',
|
16
|
+
:site => 'https://www.google.com',
|
17
|
+
}
|
18
|
+
google_contacts_auth = 'www.google.com/m8/feeds'
|
19
|
+
options[:scope] ||= "https://#{google_contacts_auth}"
|
20
|
+
options[:scope] << " https://#{google_contacts_auth}" unless options[:scope] =~ %r[http[s]?:\/\/#{google_contacts_auth}]
|
21
|
+
options[:client_options] = client_options
|
22
|
+
|
23
|
+
super(app, consumer_key, consumer_secret, options, &block)
|
24
|
+
end
|
25
|
+
|
26
|
+
uid do
|
27
|
+
user_info['uid']
|
28
|
+
end
|
29
|
+
|
30
|
+
info do
|
31
|
+
user_info
|
32
|
+
end
|
33
|
+
|
34
|
+
extra do
|
35
|
+
{ 'user_hash' => user_hash }
|
36
|
+
end
|
37
|
+
|
38
|
+
def user_info
|
39
|
+
email = user_hash['feed']['id']['$t']
|
40
|
+
|
41
|
+
name = user_hash['feed']['author'].first['name']['$t']
|
42
|
+
name = email if name.strip == '(unknown)'
|
43
|
+
|
44
|
+
{
|
45
|
+
'email' => email,
|
46
|
+
'uid' => email,
|
47
|
+
'name' => name,
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def user_hash
|
52
|
+
# Google is very strict about keeping authorization and
|
53
|
+
# authentication separated.
|
54
|
+
# They give no endpoint to get a user's profile directly that I can
|
55
|
+
# find. We *can* get their name and email out of the contacts feed,
|
56
|
+
# however. It will fail in the extremely rare case of a user who has
|
57
|
+
# a Google Account but has never even signed up for Gmail. This has
|
58
|
+
# not been seen in the field.
|
59
|
+
@user_hash ||= MultiJson.decode(@access_token.get('https://www.google.com/m8/feeds/contacts/default/full?max-results=1&alt=json').body)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Monkeypatch OmniAuth to pass the scope and authorize_params in the consumer.get_request_token call
|
63
|
+
def request_phase
|
64
|
+
request_options = {:scope => options[:scope]}
|
65
|
+
request_options.merge!(options[:authorize_params])
|
66
|
+
|
67
|
+
request_token = consumer.get_request_token({:oauth_callback => callback_url}, request_options)
|
68
|
+
session['oauth'] ||= {}
|
69
|
+
session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
|
70
|
+
r = Rack::Response.new
|
71
|
+
|
72
|
+
if request_token.callback_confirmed?
|
73
|
+
r.redirect(request_token.authorize_url)
|
74
|
+
else
|
75
|
+
r.redirect(request_token.authorize_url(:oauth_callback => callback_url))
|
76
|
+
end
|
77
|
+
|
78
|
+
r.finish
|
79
|
+
|
80
|
+
rescue ::Timeout::Error => e
|
81
|
+
fail!(:timeout, e)
|
82
|
+
rescue ::Net::HTTPFatalError, ::OpenSSL::SSL::SSLError => e
|
83
|
+
fail!(:service_unavailable, e)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "omniauth-google"
|
8
|
+
s.version = "1.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["mjbellantoni@yahoo.com"]
|
12
|
+
s.date = "2011-12-28"
|
13
|
+
s.description = "A Google OAuth strategy for OmniAuth 1.0"
|
14
|
+
s.email = "info@yesware.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
"Gemfile",
|
22
|
+
"Gemfile.lock",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"lib/omniauth-google.rb",
|
28
|
+
"lib/omniauth-google/version.rb",
|
29
|
+
"lib/omniauth/strategies/google.rb",
|
30
|
+
"omniauth-google.gemspec",
|
31
|
+
"spec/omniauth/strategies/google_spec.rb",
|
32
|
+
"spec/spec_helper.rb"
|
33
|
+
]
|
34
|
+
s.homepage = "http://github.com/Yesware/omniauth-google"
|
35
|
+
s.licenses = ["MIT"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = "1.8.10"
|
38
|
+
s.summary = "A Google OAuth strategy for OmniAuth 1.0"
|
39
|
+
|
40
|
+
if s.respond_to? :specification_version then
|
41
|
+
s.specification_version = 3
|
42
|
+
|
43
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
44
|
+
s.add_runtime_dependency(%q<omniauth>, ["~> 1.0.0"])
|
45
|
+
s.add_runtime_dependency(%q<omniauth-oauth>, [">= 0"])
|
46
|
+
s.add_runtime_dependency(%q<multi_json>, [">= 0"])
|
47
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
48
|
+
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<rack-test>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<webmock>, [">= 0"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<omniauth>, ["~> 1.0.0"])
|
54
|
+
s.add_dependency(%q<omniauth-oauth>, [">= 0"])
|
55
|
+
s.add_dependency(%q<multi_json>, [">= 0"])
|
56
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
57
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
58
|
+
s.add_dependency(%q<rack-test>, [">= 0"])
|
59
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
60
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
61
|
+
end
|
62
|
+
else
|
63
|
+
s.add_dependency(%q<omniauth>, ["~> 1.0.0"])
|
64
|
+
s.add_dependency(%q<omniauth-oauth>, [">= 0"])
|
65
|
+
s.add_dependency(%q<multi_json>, [">= 0"])
|
66
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
67
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
68
|
+
s.add_dependency(%q<rack-test>, [">= 0"])
|
69
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
70
|
+
s.add_dependency(%q<webmock>, [">= 0"])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
@@ -0,0 +1,155 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
config.include WebMock::API
|
5
|
+
config.include Rack::Test::Methods
|
6
|
+
config.extend OmniAuth::Test::StrategyMacros, :type => :strategy
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "OmniAuth::Strategies::Google" do
|
10
|
+
|
11
|
+
def app
|
12
|
+
Rack::Builder.new {
|
13
|
+
use OmniAuth::Test::PhonySession
|
14
|
+
use OmniAuth::Builder do
|
15
|
+
provider :google
|
16
|
+
end
|
17
|
+
run lambda { |env| [404, {'Content-Type' => 'text/plain'}, [env.key?('omniauth.auth').to_s]] }
|
18
|
+
}.to_app
|
19
|
+
end
|
20
|
+
|
21
|
+
def session
|
22
|
+
last_request.env['rack.session']
|
23
|
+
end
|
24
|
+
|
25
|
+
before do
|
26
|
+
stub_request(:post, 'https://www.google.com/accounts/OAuthGetRequestToken').
|
27
|
+
to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret&oauth_callback_confirmed=true")
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '/auth/google' do
|
31
|
+
context 'successful' do
|
32
|
+
before do
|
33
|
+
get '/auth/google'
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should redirect to authorize_url' do
|
37
|
+
last_response.should be_redirect
|
38
|
+
last_response.headers['Location'].should == 'https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=yourtoken'
|
39
|
+
end
|
40
|
+
|
41
|
+
# it 'should redirect to authorize_url with authorize_params when set' do
|
42
|
+
# # get '/auth/example.org_with_authorize_params'
|
43
|
+
# get '/auth/google_with_authorize_params'
|
44
|
+
# last_response.should be_redirect
|
45
|
+
# [
|
46
|
+
# 'https://api.example.org/oauth/authorize?abc=def&oauth_token=yourtoken',
|
47
|
+
# 'https://api.example.org/oauth/authorize?oauth_token=yourtoken&abc=def'
|
48
|
+
# ].should be_include(last_response.headers['Location'])
|
49
|
+
# end
|
50
|
+
|
51
|
+
it 'should set appropriate session variables' do
|
52
|
+
session['oauth'].should == {"google" => {'callback_confirmed' => true, 'request_token' => 'yourtoken', 'request_secret' => 'yoursecret'}}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'unsuccessful' do
|
57
|
+
before do
|
58
|
+
stub_request(:post, 'https://www.google.com/accounts/OAuthGetRequestToken').
|
59
|
+
to_raise(::Net::HTTPFatalError.new(%Q{502 "Bad Gateway"}, nil))
|
60
|
+
get '/auth/google'
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should call fail! with :service_unavailable' do
|
64
|
+
last_request.env['omniauth.error'].should be_kind_of(::Net::HTTPFatalError)
|
65
|
+
last_request.env['omniauth.error.type'] = :service_unavailable
|
66
|
+
end
|
67
|
+
|
68
|
+
context "SSL failure" do
|
69
|
+
before do
|
70
|
+
stub_request(:post, 'https://www.google.com/accounts/OAuthGetRequestToken').
|
71
|
+
to_raise(::OpenSSL::SSL::SSLError.new("SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed"))
|
72
|
+
get '/auth/google'
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'should call fail! with :service_unavailable' do
|
76
|
+
last_request.env['omniauth.error'].should be_kind_of(::OpenSSL::SSL::SSLError)
|
77
|
+
last_request.env['omniauth.error.type'] = :service_unavailable
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '/auth/google/callback' do
|
84
|
+
before do
|
85
|
+
body =<<BODY
|
86
|
+
{
|
87
|
+
"feed" : {
|
88
|
+
"id" : {
|
89
|
+
"$t" : "http://www.google.com/m8/feeds/contacts/dudeman%example.com/base/6d45af48e519ef7"
|
90
|
+
},
|
91
|
+
"author" : [
|
92
|
+
{
|
93
|
+
"name" : {"$t" : "Dude Man"}
|
94
|
+
}
|
95
|
+
]
|
96
|
+
}
|
97
|
+
}
|
98
|
+
BODY
|
99
|
+
|
100
|
+
stub_request(:post, 'https://www.google.com/accounts/OAuthGetAccessToken').
|
101
|
+
to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret")
|
102
|
+
stub_request(:get, "https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=1").
|
103
|
+
to_return(:status => 200, :body => body, :headers => {})
|
104
|
+
get '/auth/google/callback', {:oauth_verifier => 'dudeman'}, {'rack.session' => {'oauth' => {"google" => {'callback_confirmed' => true, 'request_token' => 'yourtoken', 'request_secret' => 'yoursecret'}}}}
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should exchange the request token for an access token' do
|
108
|
+
last_request.env['omniauth.auth']['provider'].should == 'google'
|
109
|
+
last_request.env['omniauth.auth']['extra']['access_token'].should be_kind_of(OAuth::AccessToken)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'should call through to the master app' do
|
113
|
+
last_response.body.should == 'true'
|
114
|
+
end
|
115
|
+
|
116
|
+
context "bad gateway (or any 5xx) for access_token" do
|
117
|
+
before do
|
118
|
+
stub_request(:post, 'https://www.google.com/accounts/OAuthGetAccessToken').
|
119
|
+
to_raise(::Net::HTTPFatalError.new(%Q{502 "Bad Gateway"}, nil))
|
120
|
+
get '/auth/google/callback', {:oauth_verifier => 'dudeman'}, {'rack.session' => {'oauth' => {"google" => {'callback_confirmed' => true, 'request_token' => 'yourtoken', 'request_secret' => 'yoursecret'}}}}
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should call fail! with :service_unavailable' do
|
124
|
+
last_request.env['omniauth.error'].should be_kind_of(::Net::HTTPFatalError)
|
125
|
+
last_request.env['omniauth.error.type'] = :service_unavailable
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context "SSL failure" do
|
130
|
+
before do
|
131
|
+
stub_request(:post, 'https://www.google.com/accounts/OAuthGetAccessToken').
|
132
|
+
to_raise(::OpenSSL::SSL::SSLError.new("SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed"))
|
133
|
+
get '/auth/google/callback', {:oauth_verifier => 'dudeman'}, {'rack.session' => {'oauth' => {"google" => {'callback_confirmed' => true, 'request_token' => 'yourtoken', 'request_secret' => 'yoursecret'}}}}
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should call fail! with :service_unavailable' do
|
137
|
+
last_request.env['omniauth.error'].should be_kind_of(::OpenSSL::SSL::SSLError)
|
138
|
+
last_request.env['omniauth.error.type'] = :service_unavailable
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe '/auth/google/callback with expired session' do
|
144
|
+
before do
|
145
|
+
stub_request(:post, 'https://www.google.com/accounts/OAuthGetAccessToken').
|
146
|
+
to_return(:body => "oauth_token=yourtoken&oauth_token_secret=yoursecret")
|
147
|
+
get '/auth/google/callback', {:oauth_verifier => 'dudeman'}, {'rack.session' => {}}
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'should call fail! with :session_expired' do
|
151
|
+
last_request.env['omniauth.error'].should be_kind_of(::OmniAuth::NoSessionError)
|
152
|
+
last_request.env['omniauth.error.type'] = :session_expired
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'webmock/rspec'
|
5
|
+
require 'rack/test'
|
6
|
+
require 'omniauth'
|
7
|
+
require 'omniauth-google'
|
8
|
+
|
9
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,151 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omniauth-google
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- mjbellantoni@yahoo.com
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-28 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: omniauth
|
16
|
+
requirement: &2154131500 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 1.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2154131500
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: omniauth-oauth
|
27
|
+
requirement: &2154131020 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2154131020
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: multi_json
|
38
|
+
requirement: &2154130540 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2154130540
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: &2154130060 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2154130060
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: jeweler
|
60
|
+
requirement: &2154129580 !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
type: :development
|
67
|
+
prerelease: false
|
68
|
+
version_requirements: *2154129580
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rack-test
|
71
|
+
requirement: &2154129100 !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: *2154129100
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: rspec
|
82
|
+
requirement: &2154128620 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *2154128620
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: webmock
|
93
|
+
requirement: &2154128140 !ruby/object:Gem::Requirement
|
94
|
+
none: false
|
95
|
+
requirements:
|
96
|
+
- - ! '>='
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
type: :development
|
100
|
+
prerelease: false
|
101
|
+
version_requirements: *2154128140
|
102
|
+
description: A Google OAuth strategy for OmniAuth 1.0
|
103
|
+
email: info@yesware.com
|
104
|
+
executables: []
|
105
|
+
extensions: []
|
106
|
+
extra_rdoc_files:
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
files:
|
110
|
+
- .document
|
111
|
+
- Gemfile
|
112
|
+
- Gemfile.lock
|
113
|
+
- LICENSE.txt
|
114
|
+
- README.md
|
115
|
+
- Rakefile
|
116
|
+
- VERSION
|
117
|
+
- lib/omniauth-google.rb
|
118
|
+
- lib/omniauth-google/version.rb
|
119
|
+
- lib/omniauth/strategies/google.rb
|
120
|
+
- omniauth-google.gemspec
|
121
|
+
- spec/omniauth/strategies/google_spec.rb
|
122
|
+
- spec/spec_helper.rb
|
123
|
+
homepage: http://github.com/Yesware/omniauth-google
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
none: false
|
132
|
+
requirements:
|
133
|
+
- - ! '>='
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
segments:
|
137
|
+
- 0
|
138
|
+
hash: 3936791412719806080
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
none: false
|
141
|
+
requirements:
|
142
|
+
- - ! '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 1.8.10
|
148
|
+
signing_key:
|
149
|
+
specification_version: 3
|
150
|
+
summary: A Google OAuth strategy for OmniAuth 1.0
|
151
|
+
test_files: []
|