standard_id-google 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 95c20a20efa84d33b74f4e388d7b1555930686793abd05a8a6a539466ed8cce5
4
+ data.tar.gz: 5739ad0bb2ed57bfa108d6d1d1edc5accf75e9d16f408cc575ab11d1ebe39ee1
5
+ SHA512:
6
+ metadata.gz: 73cd9fc0d21f75c81686aa98b3c63452e85cc3c38d86c9c43d794976b95179c9f7fda0c479867c6e583a9f40610d2328b916cfb4c4de739daa67c2bbb7664460
7
+ data.tar.gz: ac3238d7819d350f30f188ee01425a1595d761d1ca018c69871a62f0ecfbcf3e483b74f43bd6b1c1f45c66a6f79c8994d1117551652a96622987b4a82c21a2ca
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ # Omakase Ruby styling for Rails
2
+ inherit_gem: { rubocop-rails-omakase: rubocop.yml }
3
+
4
+ # Overwrite or add rules to create your own house style
5
+
6
+ # Use `[a, [b, c]]` not `[ a, [ b, c ] ]`
7
+ Layout/SpaceInsideArrayLiteralBrackets:
8
+ EnforcedStyle: no_space
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.4.4
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-12-20
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) Jaryl Sim
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # StandardId Google Provider
2
+
3
+ This gem extracts the Google OAuth provider from the core [`standard_id`](https://github.com/rarebit-one/standard_id) engine so installations can opt into Google login independently of the base gem.
4
+
5
+ ## Installation
6
+
7
+ Add the gem next to `standard_id`:
8
+
9
+ ```ruby
10
+ # Gemfile
11
+ gem "standard_id"
12
+ gem "standard_id-google"
13
+ ```
14
+
15
+ Then run:
16
+
17
+ ```bash
18
+ bundle install
19
+ ```
20
+
21
+ The gem automatically registers itself with StandardId when it is required.
22
+
23
+ ## Configuration
24
+
25
+ Configure your Google credentials inside the StandardId configuration block:
26
+
27
+ ```ruby
28
+ StandardId.configure do |config|
29
+ config.social.google_client_id = ENV.fetch("GOOGLE_OAUTH_CLIENT_ID", nil)
30
+ config.social.google_client_secret = ENV.fetch("GOOGLE_OAUTH_CLIENT_SECRET", nil)
31
+ end
32
+ ```
33
+
34
+ With those values in place, StandardId routes such as `/auth/callback/google` continue to function using this provider gem.
35
+
36
+ ## Testing
37
+
38
+ Run the provider test suite with:
39
+
40
+ ```bash
41
+ bundle exec rspec
42
+ ```
43
+
44
+ ## Development
45
+
46
+ 1. `bin/setup`
47
+ 2. `bundle exec rspec`
48
+
49
+ To release a new version:
50
+
51
+ 1. Update the version in `lib/standard_id/google/version.rb`.
52
+ 2. Run `bundle exec rake release` to tag, push, and publish to RubyGems.
53
+
54
+ ## License
55
+
56
+ The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,189 @@
1
+ require "json"
2
+ require "uri"
3
+
4
+ module StandardId
5
+ module Providers
6
+ class Google < Base
7
+ AUTH_ENDPOINT = "https://accounts.google.com/o/oauth2/v2/auth".freeze
8
+ TOKEN_ENDPOINT = "https://oauth2.googleapis.com/token".freeze
9
+ USERINFO_ENDPOINT = "https://www.googleapis.com/oauth2/v2/userinfo".freeze
10
+ TOKEN_INFO_ENDPOINT = "https://oauth2.googleapis.com/tokeninfo".freeze
11
+ DEFAULT_SCOPE = "openid email profile".freeze
12
+
13
+ class << self
14
+ def provider_name
15
+ "google"
16
+ end
17
+
18
+ def authorization_url(state:, redirect_uri:, **options)
19
+ scope = options[:scope] || DEFAULT_SCOPE
20
+ prompt = options[:prompt]
21
+
22
+ query = {
23
+ client_id: credentials[:client_id],
24
+ redirect_uri: redirect_uri,
25
+ response_type: "code",
26
+ scope: scope,
27
+ state: state
28
+ }
29
+
30
+ query[:prompt] = prompt if prompt.present?
31
+
32
+ "#{AUTH_ENDPOINT}?#{URI.encode_www_form(query)}"
33
+ end
34
+
35
+ def get_user_info(code: nil, id_token: nil, access_token: nil, redirect_uri: nil, **_options)
36
+ if id_token.present?
37
+ build_response(
38
+ verify_id_token(id_token: id_token),
39
+ tokens: { id_token: id_token }
40
+ )
41
+ elsif access_token.present?
42
+ build_response(
43
+ fetch_user_info(access_token: access_token),
44
+ tokens: { access_token: access_token }
45
+ )
46
+ elsif code.present?
47
+ exchange_code_for_user_info(code: code, redirect_uri: redirect_uri)
48
+ else
49
+ raise StandardId::InvalidRequestError, "Either code, id_token, or access_token must be provided"
50
+ end
51
+ end
52
+
53
+ def config_schema
54
+ {
55
+ google_client_id: { type: :string, default: nil },
56
+ google_client_secret: { type: :string, default: nil }
57
+ }
58
+ end
59
+
60
+ def default_scope
61
+ DEFAULT_SCOPE
62
+ end
63
+
64
+ def exchange_code_for_user_info(code:, redirect_uri:)
65
+ raise StandardId::InvalidRequestError, "Missing authorization code" if code.blank?
66
+
67
+ token_response = HttpClient.post_form(TOKEN_ENDPOINT, {
68
+ client_id: credentials[:client_id],
69
+ client_secret: credentials[:client_secret],
70
+ code: code,
71
+ grant_type: "authorization_code",
72
+ redirect_uri: redirect_uri
73
+ }.compact)
74
+
75
+ unless token_response.is_a?(Net::HTTPSuccess)
76
+ raise StandardId::InvalidRequestError, "Failed to exchange Google authorization code"
77
+ end
78
+
79
+ parsed_token = JSON.parse(token_response.body)
80
+ access_token = parsed_token["access_token"]
81
+ raise StandardId::InvalidRequestError, "Google response missing access token" if access_token.blank?
82
+
83
+ tokens = extract_token_payload(parsed_token)
84
+ user_info = fetch_user_info(access_token: access_token)
85
+
86
+ build_response(user_info, tokens: tokens)
87
+ rescue StandardError => e
88
+ raise e if e.is_a?(StandardId::OAuthError)
89
+
90
+ raise StandardId::OAuthError, e.message, cause: e
91
+ end
92
+
93
+ def verify_id_token(id_token:)
94
+ raise StandardId::InvalidRequestError, "Missing id_token" if id_token.blank?
95
+
96
+ response = HttpClient.post_form(TOKEN_INFO_ENDPOINT, id_token: id_token)
97
+
98
+ raise StandardId::InvalidRequestError, "Invalid or expired id_token" unless response.is_a?(Net::HTTPSuccess)
99
+
100
+ token_info = JSON.parse(response.body)
101
+
102
+ unless token_info["aud"] == credentials[:client_id]
103
+ raise StandardId::InvalidRequestError,
104
+ "ID token audience mismatch. Expected: #{credentials[:client_id]}, got: #{token_info["aud"]}"
105
+ end
106
+
107
+ unless ["accounts.google.com", "https://accounts.google.com"].include?(token_info["iss"])
108
+ raise StandardId::InvalidRequestError,
109
+ "ID token issuer invalid. Expected Google, got: #{token_info["iss"]}"
110
+ end
111
+
112
+ {
113
+ "sub" => token_info["sub"],
114
+ "email" => token_info["email"],
115
+ "email_verified" => token_info["email_verified"],
116
+ "name" => token_info["name"],
117
+ "given_name" => token_info["given_name"],
118
+ "family_name" => token_info["family_name"],
119
+ "picture" => token_info["picture"],
120
+ "locale" => token_info["locale"]
121
+ }.compact
122
+ rescue StandardError => e
123
+ raise e if e.is_a?(StandardId::OAuthError)
124
+
125
+ raise StandardId::OAuthError, e.message, cause: e
126
+ end
127
+
128
+ def fetch_user_info(access_token:)
129
+ raise StandardId::InvalidRequestError, "Missing access token" if access_token.blank?
130
+
131
+ verify_token(access_token)
132
+ user_response = HttpClient.get_with_bearer(USERINFO_ENDPOINT, access_token)
133
+
134
+ unless user_response.is_a?(Net::HTTPSuccess)
135
+ raise StandardId::InvalidRequestError, "Failed to fetch Google user info"
136
+ end
137
+
138
+ JSON.parse(user_response.body)
139
+ rescue StandardError => e
140
+ raise e if e.is_a?(StandardId::OAuthError)
141
+
142
+ raise StandardId::OAuthError, e.message, cause: e
143
+ end
144
+
145
+ private
146
+
147
+ def credentials
148
+ @credentials ||= begin
149
+ if StandardId.config.social.google_client_id.blank? || StandardId.config.social.google_client_secret.blank?
150
+ raise StandardId::InvalidRequestError, "Google provider is not configured"
151
+ end
152
+
153
+ {
154
+ client_id: StandardId.config.social.google_client_id,
155
+ client_secret: StandardId.config.social.google_client_secret
156
+ }
157
+ end
158
+ end
159
+
160
+ def verify_token(access_token)
161
+ response = HttpClient.post_form("https://www.googleapis.com/oauth2/v3/tokeninfo", access_token: access_token)
162
+
163
+ unless response.is_a?(Net::HTTPSuccess)
164
+ raise StandardId::InvalidRequestError, "Invalid or expired access token"
165
+ end
166
+
167
+ token_info = JSON.parse(response.body)
168
+
169
+ unless token_info["aud"] == credentials[:client_id]
170
+ raise StandardId::InvalidRequestError,
171
+ "Access token audience mismatch. Expected: #{credentials[:client_id]}, got: #{token_info["aud"]}"
172
+ end
173
+
174
+ token_info
175
+ end
176
+
177
+ def extract_token_payload(parsed_token)
178
+ {
179
+ access_token: parsed_token["access_token"],
180
+ refresh_token: parsed_token["refresh_token"],
181
+ id_token: parsed_token["id_token"]
182
+ }.compact
183
+ end
184
+ end
185
+ end
186
+ end
187
+ end
188
+
189
+ StandardId::ProviderRegistry.register(:google, StandardId::Providers::Google)
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module StandardId
4
+ module Google
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ require "active_support/core_ext/numeric/time"
2
+ require "active_support/core_ext/hash/indifferent_access"
3
+ require "standard_id"
4
+ require "standard_id/google/providers/google"
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: standard_id-google
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jaryl Sim
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: activesupport
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '8.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '8.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: standard_id
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '0.1'
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 0.1.7
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '0.1'
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 0.1.7
46
+ description: Extracted StandardId::Providers::Apple implementation packaged as a standalone
47
+ gem so StandardId installations can opt into Sign in with Apple independently.
48
+ email:
49
+ - code@jaryl.dev
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - ".rspec"
55
+ - ".rubocop.yml"
56
+ - ".ruby-version"
57
+ - CHANGELOG.md
58
+ - CODE_OF_CONDUCT.md
59
+ - LICENSE.txt
60
+ - README.md
61
+ - Rakefile
62
+ - lib/standard_id/google.rb
63
+ - lib/standard_id/google/providers/google.rb
64
+ - lib/standard_id/google/version.rb
65
+ homepage: https://github.com/rarebit-one/standard_id_apple
66
+ licenses:
67
+ - MIT
68
+ metadata:
69
+ homepage_uri: https://github.com/rarebit-one/standard_id_apple
70
+ source_code_uri: https://github.com/rarebit-one/standard_id_apple
71
+ changelog_uri: https://github.com/rarebit-one/standard_id_apple/blob/main/CHANGELOG.md
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 3.2.0
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubygems_version: 3.6.7
87
+ specification_version: 4
88
+ summary: Google Sign In provider plugin for the StandardId engine.
89
+ test_files: []