omniauth-google2 1.0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 63427f9dc5e660bfe619a6bd03f8bdb8855dba46af54e2e7be226295505d262e
4
+ data.tar.gz: 339499439c68c4ea05ff007bde1b8721656f242257fb4c341156b2e3b4d725d9
5
+ SHA512:
6
+ metadata.gz: a57c2acf7b6207936fa2c209ce152e2789c1265aded76521b6c13681344859fea96b7e714282af807f542de2edcb80957e4fce6b926efab666cbe949b050595d
7
+ data.tar.gz: 7eade7ca6129243f8c05d5bdbd25f0a574e3ebd5337e2d564c087ff2b30f44281984fce7e4cd875a1a859a7db0083cc970f5d15c35b81c22ae3b8d73a4bc6410
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Claudio Poli
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,151 @@
1
+ # OmniAuth Google2 Strategy
2
+
3
+ [![Test](https://github.com/icoretech/omniauth-google2/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/icoretech/omniauth-google2/actions/workflows/test.yml?query=branch%3Amain)
4
+ [![Gem Version](https://img.shields.io/gem/v/omniauth-google2.svg)](https://rubygems.org/gems/omniauth-google2)
5
+
6
+ `omniauth-google2` provides a Google OAuth2/OpenID Connect strategy for OmniAuth.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'omniauth-google2'
14
+ ```
15
+
16
+ Then run:
17
+
18
+ ```bash
19
+ bundle install
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ Configure OmniAuth in your Rack/Rails app:
25
+
26
+ ```ruby
27
+ Rails.application.config.middleware.use OmniAuth::Builder do
28
+ provider :google2,
29
+ ENV.fetch('GOOGLE_CLIENT_ID'),
30
+ ENV.fetch('GOOGLE_CLIENT_SECRET')
31
+ end
32
+ ```
33
+
34
+ Compatibility alias is available, so you can keep existing callback paths using `google_oauth2`:
35
+
36
+ ```ruby
37
+ Rails.application.config.middleware.use OmniAuth::Builder do
38
+ provider :google_oauth2,
39
+ ENV.fetch('GOOGLE_CLIENT_ID'),
40
+ ENV.fetch('GOOGLE_CLIENT_SECRET')
41
+ end
42
+ ```
43
+
44
+ Google OAuth app setup: [Google Cloud Console](https://console.cloud.google.com/apis/credentials)
45
+
46
+ ## Options
47
+
48
+ Supported request options include:
49
+ - `scope` (default: `openid email profile`)
50
+ - `access_type` (default: `offline`)
51
+ - `include_granted_scopes`
52
+ - `prompt`
53
+ - `login_hint`
54
+ - `hd`
55
+ - `redirect_uri`
56
+ - `nonce`
57
+
58
+ Scopes are normalized so short names like `email profile` are converted to Google OAuth scope URLs when required.
59
+
60
+ ## Auth Hash
61
+
62
+ Example payload from `request.env['omniauth.auth']` (realistic shape, anonymized):
63
+
64
+ ```json
65
+ {
66
+ "uid": "111111111111111111111",
67
+ "info": {
68
+ "name": "sample-user",
69
+ "email": "sample@gmail.com",
70
+ "unverified_email": "sample@gmail.com",
71
+ "email_verified": true,
72
+ "first_name": "sample-user",
73
+ "image": "https://lh3.googleusercontent.com/a/example-avatar=s96-c"
74
+ },
75
+ "credentials": {
76
+ "token": "ya29.a0AfH6SM...",
77
+ "refresh_token": "1//0gAbCdEf123456",
78
+ "expires_at": 1772691847,
79
+ "expires": true,
80
+ "scope": "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email openid"
81
+ },
82
+ "extra": {
83
+ "raw_info": {
84
+ "sub": "111111111111111111111",
85
+ "name": "sample-user",
86
+ "given_name": "sample-user",
87
+ "picture": "https://lh3.googleusercontent.com/a/example-avatar=s96-c",
88
+ "email": "sample@gmail.com",
89
+ "email_verified": true
90
+ },
91
+ "id_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6I...redacted...",
92
+ "id_info": {
93
+ "iss": "https://accounts.google.com",
94
+ "aud": "1012003270838.apps.googleusercontent.com",
95
+ "sub": "111111111111111111111",
96
+ "email": "sample@gmail.com",
97
+ "email_verified": true,
98
+ "name": "sample-user",
99
+ "picture": "https://lh3.googleusercontent.com/a/example-avatar=s96-c",
100
+ "given_name": "sample-user",
101
+ "iat": 1772689518,
102
+ "exp": 1772693118
103
+ }
104
+ }
105
+ }
106
+ ```
107
+
108
+ ## Development
109
+
110
+ ```bash
111
+ bundle install
112
+ bundle exec rake
113
+ ```
114
+
115
+ Run Rails integration tests with an explicit Rails version:
116
+
117
+ ```bash
118
+ RAILS_VERSION='~> 8.1.0' bundle install
119
+ RAILS_VERSION='~> 8.1.0' bundle exec rake test_rails_integration
120
+ ```
121
+
122
+ ## Compatibility
123
+
124
+ - Ruby: `>= 3.2` (tested on `3.2`, `3.3`, `3.4`, `4.0`)
125
+ - `omniauth-oauth2`: `>= 1.8`, `< 1.9`
126
+ - Rails integration lanes: `~> 7.1.0`, `~> 7.2.0`, `~> 8.0.0`, `~> 8.1.0`
127
+
128
+ ## Endpoints
129
+
130
+ This gem uses Google OpenID Connect discovery endpoints:
131
+ - `https://accounts.google.com/o/oauth2/v2/auth`
132
+ - `https://oauth2.googleapis.com/token`
133
+ - `https://openidconnect.googleapis.com/v1/userinfo`
134
+
135
+ ## Smoke Variants
136
+
137
+ After a baseline smoke succeeds, run these extra request-phase variants:
138
+ - `?prompt=consent select_account`
139
+ - `?login_hint=user@example.com`
140
+ - `?hd=example.com`
141
+ - `?include_granted_scopes=true`
142
+
143
+ These verify option pass-through and help catch provider-side UX or consent regressions.
144
+
145
+ ## Release
146
+
147
+ Tag releases as `vX.Y.Z`; GitHub Actions publishes the gem to RubyGems.
148
+
149
+ ## License
150
+
151
+ MIT
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OmniAuth
4
+ module Google2
5
+ VERSION = '1.0.0'
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/google2/version'
4
+ require 'omniauth/strategies/google2'
@@ -0,0 +1,144 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'jwt'
4
+ require 'omniauth-oauth2'
5
+
6
+ module OmniAuth
7
+ module Strategies
8
+ # OmniAuth strategy for Google OAuth2/OpenID Connect.
9
+ class Google2 < OmniAuth::Strategies::OAuth2
10
+ BASE_SCOPE_URL = 'https://www.googleapis.com/auth/'
11
+ BASE_SCOPES = %w[openid email profile].freeze
12
+ DEFAULT_SCOPE = 'openid email profile'
13
+ USER_INFO_URL = 'https://openidconnect.googleapis.com/v1/userinfo'
14
+
15
+ option :name, 'google2'
16
+ option :authorize_options,
17
+ %i[scope state access_type include_granted_scopes prompt login_hint hd redirect_uri nonce]
18
+ option :scope, DEFAULT_SCOPE
19
+ option :skip_jwt, false
20
+
21
+ option :client_options,
22
+ site: 'https://openidconnect.googleapis.com',
23
+ authorize_url: 'https://accounts.google.com/o/oauth2/v2/auth',
24
+ token_url: 'https://oauth2.googleapis.com/token',
25
+ connection_opts: {
26
+ headers: {
27
+ user_agent: 'icoretech-omniauth-google2 gem',
28
+ accept: 'application/json',
29
+ content_type: 'application/json'
30
+ }
31
+ }
32
+
33
+ uid { raw_info['sub'] || raw_info['id'].to_s }
34
+
35
+ info do
36
+ {
37
+ name: raw_info['name'],
38
+ email: raw_info['email_verified'] ? raw_info['email'] : nil,
39
+ unverified_email: raw_info['email'],
40
+ email_verified: raw_info['email_verified'],
41
+ first_name: raw_info['given_name'],
42
+ last_name: raw_info['family_name'],
43
+ image: raw_info['picture'],
44
+ urls: raw_info['profile'] ? { google: raw_info['profile'] } : nil
45
+ }.compact
46
+ end
47
+
48
+ credentials do
49
+ {
50
+ 'token' => access_token.token,
51
+ 'refresh_token' => access_token.refresh_token,
52
+ 'expires_at' => access_token.expires_at,
53
+ 'expires' => access_token.expires?,
54
+ 'scope' => token_scope
55
+ }.compact
56
+ end
57
+
58
+ extra do
59
+ data = { 'raw_info' => raw_info }
60
+ id_token = access_token['id_token']
61
+ return data if blank?(id_token)
62
+
63
+ data['id_token'] = id_token
64
+ decoded = decode_id_token(id_token)
65
+ data['id_info'] = decoded if decoded
66
+ data
67
+ end
68
+
69
+ def authorize_params
70
+ super.tap do |params|
71
+ apply_request_authorize_overrides(params)
72
+ params[:scope] = normalize_scope(params[:scope] || options[:scope])
73
+ params[:access_type] ||= 'offline'
74
+ params[:include_granted_scopes] = normalize_include_granted_scopes(params[:include_granted_scopes])
75
+ persist_authorize_state(params)
76
+ end
77
+ end
78
+
79
+ def raw_info
80
+ @raw_info ||= access_token.get(USER_INFO_URL).parsed
81
+ end
82
+
83
+ # Ensure token exchange uses a stable callback URI that matches provider config.
84
+ def callback_url
85
+ options[:callback_url] || options[:redirect_uri] || super
86
+ end
87
+
88
+ # Prevent authorization response params from being appended to redirect_uri.
89
+ def query_string
90
+ return '' if request.params['code']
91
+
92
+ super
93
+ end
94
+
95
+ private
96
+
97
+ def normalize_scope(raw_scope)
98
+ raw_scope.to_s.split(/[\s,]+/).reject(&:empty?).map do |scope|
99
+ scope.start_with?('https://') || BASE_SCOPES.include?(scope) ? scope : "#{BASE_SCOPE_URL}#{scope}"
100
+ end.join(' ')
101
+ end
102
+
103
+ def apply_request_authorize_overrides(params)
104
+ options[:authorize_options].each do |key|
105
+ request_value = request.params[key.to_s]
106
+ params[key] = request_value unless blank?(request_value)
107
+ end
108
+ end
109
+
110
+ def normalize_include_granted_scopes(value)
111
+ value == true ? 'true' : value
112
+ end
113
+
114
+ def persist_authorize_state(params)
115
+ session['omniauth.state'] = params[:state] if params[:state]
116
+ end
117
+
118
+ def token_scope
119
+ access_token.params['scope'] || access_token['scope']
120
+ end
121
+
122
+ def decode_id_token(token)
123
+ return nil if options[:skip_jwt]
124
+
125
+ payload, = JWT.decode(token, nil, false)
126
+ payload
127
+ rescue JWT::DecodeError
128
+ nil
129
+ end
130
+
131
+ def blank?(value)
132
+ value.nil? || (value.respond_to?(:empty?) && value.empty?)
133
+ end
134
+ end
135
+
136
+ # Backward-compatible strategy name for existing `google_oauth2` callback paths.
137
+ class GoogleOauth2 < Google2
138
+ option :name, 'google_oauth2'
139
+ end
140
+ end
141
+ end
142
+
143
+ OmniAuth.config.add_camelization 'google2', 'Google2'
144
+ OmniAuth.config.add_camelization 'google_oauth2', 'GoogleOauth2'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'omniauth/google2'
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'omniauth/google2/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'omniauth-google2'
9
+ spec.version = OmniAuth::Google2::VERSION
10
+ spec.authors = ['Claudio Poli']
11
+ spec.email = ['masterkain@gmail.com']
12
+
13
+ spec.summary = 'OmniAuth strategy for Google OAuth2/OpenID Connect authentication.'
14
+ spec.description =
15
+ 'OAuth2/OpenID Connect strategy for OmniAuth that authenticates users with Google and exposes profile metadata.'
16
+ spec.homepage = 'https://github.com/icoretech/omniauth-google2'
17
+ spec.license = 'MIT'
18
+ spec.required_ruby_version = '>= 3.2'
19
+
20
+ spec.metadata['source_code_uri'] = 'https://github.com/icoretech/omniauth-google2'
21
+ spec.metadata['bug_tracker_uri'] = 'https://github.com/icoretech/omniauth-google2/issues'
22
+ spec.metadata['changelog_uri'] = 'https://github.com/icoretech/omniauth-google2/releases'
23
+ spec.metadata['rubygems_mfa_required'] = 'true'
24
+
25
+ spec.files = Dir[
26
+ 'lib/**/*.rb',
27
+ 'README*',
28
+ 'LICENSE*',
29
+ '*.gemspec'
30
+ ]
31
+ spec.require_paths = ['lib']
32
+
33
+ spec.add_dependency 'cgi', '>= 0.3.6'
34
+ spec.add_dependency 'jwt', '>= 2.9.2'
35
+ spec.add_dependency 'omniauth-oauth2', '>= 1.8', '< 1.9'
36
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth-google2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Claudio Poli
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: cgi
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: 0.3.6
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: 0.3.6
26
+ - !ruby/object:Gem::Dependency
27
+ name: jwt
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.9.2
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 2.9.2
40
+ - !ruby/object:Gem::Dependency
41
+ name: omniauth-oauth2
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '1.8'
47
+ - - "<"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.9'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '1.8'
57
+ - - "<"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.9'
60
+ description: OAuth2/OpenID Connect strategy for OmniAuth that authenticates users
61
+ with Google and exposes profile metadata.
62
+ email:
63
+ - masterkain@gmail.com
64
+ executables: []
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - LICENSE.txt
69
+ - README.md
70
+ - lib/omniauth-google2.rb
71
+ - lib/omniauth/google2.rb
72
+ - lib/omniauth/google2/version.rb
73
+ - lib/omniauth/strategies/google2.rb
74
+ - omniauth-google2.gemspec
75
+ homepage: https://github.com/icoretech/omniauth-google2
76
+ licenses:
77
+ - MIT
78
+ metadata:
79
+ source_code_uri: https://github.com/icoretech/omniauth-google2
80
+ bug_tracker_uri: https://github.com/icoretech/omniauth-google2/issues
81
+ changelog_uri: https://github.com/icoretech/omniauth-google2/releases
82
+ rubygems_mfa_required: 'true'
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '3.2'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubygems_version: 3.6.9
98
+ specification_version: 4
99
+ summary: OmniAuth strategy for Google OAuth2/OpenID Connect authentication.
100
+ test_files: []