omniauth-google-oauth2 0.0.10 → 0.1.0

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/examples/config.ru CHANGED
@@ -1,4 +1,4 @@
1
- # Sample app for Google OAuth2 Strateg
1
+ # Sample app for Google OAuth2 Strategy
2
2
  # Run with "bundle exec rackup"
3
3
 
4
4
  require 'rubygems'
@@ -17,13 +17,13 @@ class App < Sinatra::Base
17
17
  end
18
18
 
19
19
  get '/auth/:provider/callback' do
20
- content_type 'application/json'
21
- MultiJson.encode(request.env)
20
+ content_type 'text/plain'
21
+ request.env['omniauth.auth'].to_hash.inspect
22
22
  end
23
23
 
24
24
  get '/auth/failure' do
25
- content_type 'application/json'
26
- MultiJson.encode(request.env)
25
+ content_type 'text/plain'
26
+ request.env['omniauth.auth'].to_hash.inspect
27
27
  end
28
28
  end
29
29
 
@@ -1,5 +1,5 @@
1
1
  module OmniAuth
2
2
  module GoogleOauth2
3
- VERSION = "0.0.10"
3
+ VERSION = "0.1.0"
4
4
  end
5
5
  end
@@ -3,18 +3,29 @@ require 'omniauth/strategies/oauth2'
3
3
  module OmniAuth
4
4
  module Strategies
5
5
  class GoogleOauth2 < OmniAuth::Strategies::OAuth2
6
+ option :name, 'google_oauth2'
7
+
6
8
  option :client_options, {
7
9
  :site => 'https://accounts.google.com',
8
- :authorize_path => '/o/oauth2/auth',
9
- :token_path => '/o/oauth2/token'
10
+ :authorize_url => '/o/oauth2/auth',
11
+ :token_url => '/o/oauth2/token'
10
12
  }
11
13
 
12
14
  def request_phase
15
+ redirect client.auth_code.authorize_url(authorize_options)
16
+ end
17
+
18
+ def authorize_options
19
+ opts = {
20
+ :client_id => options[:client_id],
21
+ :redirect_uri => callback_url,
22
+ :response_type => "code",
23
+ :scope => options[:scope]
24
+ }
13
25
  google_email_scope = "www.googleapis.com/auth/userinfo.email"
14
- options[:scope] ||= "https://#{google_email_scope}"
15
- options[:scope] << " https://#{google_email_scope}" unless options[:scope] =~ %r[http[s]?:\/\/#{google_email_scope}]
16
- redirect client.auth_code.authorize_url(
17
- {:redirect_uri => callback_url, :response_type => "code"}.merge(options))
26
+ opts[:scope] ||= "https://#{google_email_scope}"
27
+ opts[:scope] << " https://#{google_email_scope}" unless opts[:scope] =~ %r[http[s]?:\/\/#{google_email_scope}]
28
+ opts
18
29
  end
19
30
 
20
31
  def auth_hash
@@ -27,10 +38,16 @@ module OmniAuth
27
38
  end
28
39
 
29
40
  info do
41
+ if user_data['data']['isVerified']
42
+ email = user_data['data']['email'] rescue nil
43
+ else
44
+ email = nil
45
+ end
46
+
30
47
  {
31
- 'email' => "TESTING EMAIL",
32
- 'uid' => "TESTING UID",
33
- 'name' => "TESTING NAME"
48
+ 'email' => email,
49
+ 'uid' => email,
50
+ 'name' => email
34
51
  }
35
52
  end
36
53
 
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: 11
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 10
10
- version: 0.0.10
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Josh Ellithorpe