omniauth-google-api 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem 'omniauth', "~> 1.0.0"
4
+ gem 'omniauth-oauth2'
5
+ gem 'multi_json'
6
+ gem 'cyaml'
7
+
8
+ group :development do
9
+ gem "bundler"
10
+ gem "jeweler"
11
+ end
12
+
13
+ group :development, :test do
14
+ gem "rack-test"
15
+ gem "rspec"
16
+ gem "webmock"
17
+ end
data/README ADDED
File without changes
data/README.md CHANGED
@@ -18,7 +18,7 @@ Add the middleware to a Rails app in `config/initializers/omniauth.rb`:
18
18
 
19
19
  ```ruby
20
20
  Rails.application.config.middleware.use OmniAuth::Builder do
21
- provider :googlei-api, CONSUMER_KEY, CONSUMER_SECRET, REDIRECT_URL
21
+ provider :googlei_api, CONSUMER_KEY, CONSUMER_SECRET, REDIRECT_URL
22
22
  end
23
23
  ```
24
24
 
@@ -0,0 +1,45 @@
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-api"
17
+ gem.homepage = "http://github.com/sterlingmichel/omniauth-google-api"
18
+ gem.license = "MIT"
19
+ gem.summary = %Q{A Google+ OAuth strategy for OmniAuth 1.0}
20
+ gem.description = "This tool will enable you to pull google+ and eventual all of its api"
21
+ gem.email = "sterlingmichel@gmail.com"
22
+ gem.authors = ["Sterling Michel"]
23
+ # dependencies defined in Gemfile
24
+ end
25
+
26
+
27
+ #Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ #require 'rspec/core'
30
+ #require 'rspec/core/rake_task'
31
+ #RSpec::Core::RakeTask.new(:spec) do |spec|
32
+ # spec.pattern = FileList['spec/**/*_spec.rb']
33
+ #end
34
+
35
+ #task :default => :sds
36
+
37
+ #require 'rdoc/task'
38
+ #Rake::RDocTask.new do |rdoc|
39
+ # version = File.exist?('VERSION') ? File.read('VERSION') : ""
40
+
41
+ # rdoc.rdoc_dir = 'rdoc'
42
+ # rdoc.title = "omniauth-google-api #{version}"
43
+ # rdoc.rdoc_files.include('README*')
44
+ # rdoc.rdoc_files.include('lib/**/*.rb')
45
+ ##end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.2
@@ -0,0 +1,3 @@
1
+ require "omniauth-google-api/version"
2
+ require 'omniauth/strategies/google_api.rb'
3
+
@@ -0,0 +1,5 @@
1
+ module OmniAuth
2
+ module GoogleApi
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,69 @@
1
+ require 'omniauth/strategies/oauth2'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ class GoogleApi < OmniAuth::Strategies::OAuth2
6
+
7
+ # Possible scopes: userinfo.email,userinfo.profile,plus.me
8
+ DEFAULT_SCOPE = "userinfo.email,userinfo.profile,plus.me"
9
+
10
+ option :name, 'google_api'
11
+ option :authorize_options, [:scope, :approval_prompt, :access_type]
12
+
13
+ option :client_options, {
14
+ :site => 'https://accounts.google.com',
15
+ :authorize_url => '/o/oauth2/auth',
16
+ :token_url => '/o/oauth2/token'
17
+ }
18
+
19
+ def authorize_params
20
+ base_scope_url = "https://www.googleapis.com/auth/"
21
+ super.tap do |params|
22
+ scopes = (params[:scope] || DEFAULT_SCOPE).split(",")
23
+ scopes.map! { |s| s =~ /^https?:\/\// ? s : "#{base_scope_url}#{s}" }
24
+ params[:scope] = scopes.join(' ')
25
+ params[:access_type] = 'offline' if params[:access_type].nil?
26
+ params[:approval_prompt] = 'force' if params[:approval_prompt].nil?
27
+ end
28
+ end
29
+
30
+ uid{ raw_info['id'] || verified_email }
31
+
32
+ info do
33
+ prune!({
34
+ :name => raw_info['name'],
35
+ :email => verified_email,
36
+ :first_name => raw_info['given_name'],
37
+ :last_name => raw_info['family_name'],
38
+ :image => raw_info['picture'],
39
+ })
40
+ end
41
+
42
+ extra do
43
+ prune!({
44
+ 'raw_info' => raw_info
45
+ })
46
+ end
47
+
48
+ protected
49
+
50
+ def raw_info
51
+ @raw_info ||= access_token.get('https://www.googleapis.com/oauth2/v1/userinfo').parsed
52
+ end
53
+
54
+ private
55
+
56
+ def prune!(hash)
57
+ hash.delete_if do |_, value|
58
+ prune!(value) if value.is_a?(Hash)
59
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
60
+ end
61
+ end
62
+
63
+ def verified_email
64
+ raw_info['verified_email'] ? raw_info['email'] : nil
65
+ end
66
+
67
+ end
68
+ end
69
+ end
data/note ADDED
@@ -0,0 +1,7 @@
1
+ Sign up for an account on Gemcutter
2
+ Make sure you’re running at least RubyGems 1.3.3. gem -v
3
+ Create your gem. Get started with Jeweler
4
+ Install the gemcutter gem with: gem install gemcutter
5
+ Build your gem with: gem build yourgem.gemspec
6
+ Push it! gem push yourgem-0.0.1.gem
7
+
@@ -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::GoogleApi" do
10
+
11
+ def app
12
+ Rack::Builder.new {
13
+ use OmniAuth::Test::PhonySession
14
+ use OmniAuth::Builder do
15
+ provider :googleApi
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-api" => {'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
@@ -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-api'
8
+
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniauth-google-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
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: 2012-01-16 00:00:00.000000000 Z
12
+ date: 2012-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: omniauth
16
- requirement: &2156326800 !ruby/object:Gem::Requirement
16
+ requirement: &2158387940 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2156326800
24
+ version_requirements: *2158387940
25
25
  - !ruby/object:Gem::Dependency
26
- name: omniauth-oauth
27
- requirement: &2156326100 !ruby/object:Gem::Requirement
26
+ name: omniauth-oauth2
27
+ requirement: &2158387140 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2156326100
35
+ version_requirements: *2158387140
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: multi_json
38
- requirement: &2156325380 !ruby/object:Gem::Requirement
38
+ requirement: &2158385940 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,21 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *2156325380
46
+ version_requirements: *2158385940
47
+ - !ruby/object:Gem::Dependency
48
+ name: cyaml
49
+ requirement: &2158401260 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *2158401260
47
58
  - !ruby/object:Gem::Dependency
48
59
  name: bundler
49
- requirement: &2156324380 !ruby/object:Gem::Requirement
60
+ requirement: &2158400640 !ruby/object:Gem::Requirement
50
61
  none: false
51
62
  requirements:
52
63
  - - ! '>='
@@ -54,10 +65,10 @@ dependencies:
54
65
  version: '0'
55
66
  type: :development
56
67
  prerelease: false
57
- version_requirements: *2156324380
68
+ version_requirements: *2158400640
58
69
  - !ruby/object:Gem::Dependency
59
70
  name: jeweler
60
- requirement: &2156323240 !ruby/object:Gem::Requirement
71
+ requirement: &2158399880 !ruby/object:Gem::Requirement
61
72
  none: false
62
73
  requirements:
63
74
  - - ! '>='
@@ -65,10 +76,10 @@ dependencies:
65
76
  version: '0'
66
77
  type: :development
67
78
  prerelease: false
68
- version_requirements: *2156323240
79
+ version_requirements: *2158399880
69
80
  - !ruby/object:Gem::Dependency
70
81
  name: rack-test
71
- requirement: &2156321620 !ruby/object:Gem::Requirement
82
+ requirement: &2158398800 !ruby/object:Gem::Requirement
72
83
  none: false
73
84
  requirements:
74
85
  - - ! '>='
@@ -76,10 +87,10 @@ dependencies:
76
87
  version: '0'
77
88
  type: :development
78
89
  prerelease: false
79
- version_requirements: *2156321620
90
+ version_requirements: *2158398800
80
91
  - !ruby/object:Gem::Dependency
81
92
  name: rspec
82
- requirement: &2156320540 !ruby/object:Gem::Requirement
93
+ requirement: &2158398180 !ruby/object:Gem::Requirement
83
94
  none: false
84
95
  requirements:
85
96
  - - ! '>='
@@ -87,10 +98,10 @@ dependencies:
87
98
  version: '0'
88
99
  type: :development
89
100
  prerelease: false
90
- version_requirements: *2156320540
101
+ version_requirements: *2158398180
91
102
  - !ruby/object:Gem::Dependency
92
103
  name: webmock
93
- requirement: &2156335880 !ruby/object:Gem::Requirement
104
+ requirement: &2158397200 !ruby/object:Gem::Requirement
94
105
  none: false
95
106
  requirements:
96
107
  - - ! '>='
@@ -98,16 +109,27 @@ dependencies:
98
109
  version: '0'
99
110
  type: :development
100
111
  prerelease: false
101
- version_requirements: *2156335880
102
- description: A Google+ OAuth strategy for OmniAuth 1.0
112
+ version_requirements: *2158397200
113
+ description: This tool will enable you to pull google+ and eventual all of its api
103
114
  email: sterlingmichel@gmail.com
104
115
  executables: []
105
116
  extensions: []
106
117
  extra_rdoc_files:
107
118
  - LICENSE.txt
119
+ - README
108
120
  - README.md
109
121
  files:
122
+ - Gemfile
110
123
  - LICENSE.txt
124
+ - README
125
+ - Rakefile
126
+ - VERSION
127
+ - lib/omniauth-google-api.rb
128
+ - lib/omniauth-google-api/version.rb
129
+ - lib/omniauth/strategies/google_api.rb
130
+ - note
131
+ - spec/omniauth/strategies/google_api_spec.rb
132
+ - spec/spec_helper.rb
111
133
  - README.md
112
134
  homepage: http://github.com/sterlingmichel/omniauth-google-api
113
135
  licenses:
@@ -122,6 +144,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
122
144
  - - ! '>='
123
145
  - !ruby/object:Gem::Version
124
146
  version: '0'
147
+ segments:
148
+ - 0
149
+ hash: -2215161885211397943
125
150
  required_rubygems_version: !ruby/object:Gem::Requirement
126
151
  none: false
127
152
  requirements: