swarmauri_auth_idp_google 0.2.0.dev5__tar.gz

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.
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [2025] [Jacob Stewart @ Swarmauri]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
@@ -0,0 +1,118 @@
1
+ Metadata-Version: 2.4
2
+ Name: swarmauri_auth_idp_google
3
+ Version: 0.2.0.dev5
4
+ Summary: Google OAuth 2.0 / OAuth 2.1 / OIDC 1.0 identity provider implementations for Swarmauri
5
+ License-Expression: Apache-2.0
6
+ License-File: LICENSE
7
+ Keywords: swarmauri,sdk,experimental,identity,oauth2,oauth21,oidc,google,idp
8
+ Author: Jacob Stewart
9
+ Author-email: jacob@swarmauri.com
10
+ Requires-Python: >=3.10,<3.13
11
+ Classifier: Development Status :: 1 - Planning
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Natural Language :: English
15
+ Classifier: Programming Language :: Python
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Internet :: WWW/HTTP
22
+ Classifier: Topic :: Security :: Cryptography
23
+ Requires-Dist: httpx (>=0.27)
24
+ Requires-Dist: pyjwt[crypto] (>=2.8)
25
+ Requires-Dist: swarmauri_base
26
+ Requires-Dist: swarmauri_core
27
+ Description-Content-Type: text/markdown
28
+
29
+ ![Swarmauri Logo](https://github.com/swarmauri/swarmauri-sdk/blob/master/assets/swarmauri.brand.theme.svg)
30
+
31
+ <p align="center">
32
+ <a href="https://pypi.org/project/swarmauri_auth_idp_google/">
33
+ <img src="https://img.shields.io/pypi/dm/swarmauri_auth_idp_google" alt="PyPI - Downloads"/></a>
34
+ <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/experimental/swarmauri_auth_idp_google/">
35
+ <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/experimental/swarmauri_auth_idp_google.svg"/></a>
36
+ <a href="https://pypi.org/project/swarmauri_auth_idp_google/">
37
+ <img src="https://img.shields.io/pypi/pyversions/swarmauri_auth_idp_google" alt="PyPI - Python Version"/></a>
38
+ <a href="https://pypi.org/project/swarmauri_auth_idp_google/">
39
+ <img src="https://img.shields.io/pypi/l/swarmauri_auth_idp_google" alt="PyPI - License"/></a>
40
+ <a href="https://pypi.org/project/swarmauri_auth_idp_google/">
41
+ <img src="https://img.shields.io/pypi/v/swarmauri_auth_idp_google?label=swarmauri_auth_idp_google&color=green" alt="PyPI - swarmauri_auth_idp_google"/></a>
42
+ </p>
43
+
44
+ ---
45
+
46
+ # Swarmauri Auth IDP Google
47
+
48
+ Google OAuth 2.0 / OAuth 2.1 / OIDC 1.0 identity providers packaged for Swarmauri deployments.
49
+
50
+ ## Features
51
+
52
+ - PKCE-enabled Authorization Code flows with HMAC-signed state payloads.
53
+ - Discovery-driven OAuth 2.1/OIDC login that validates ID tokens and nonces.
54
+ - Profile hydration via Google UserInfo endpoints for normalized downstream payloads.
55
+ - Retry-aware HTTP integration tuned for Google Identity services.
56
+ - ComponentBase-compatible models registered under `swarmauri.auth_idp` entry points.
57
+
58
+ ## Installation
59
+
60
+ ### pip
61
+
62
+ ```bash
63
+ pip install swarmauri_auth_idp_google
64
+ ```
65
+
66
+ ### uv (project)
67
+
68
+ ```bash
69
+ uv add swarmauri_auth_idp_google
70
+ ```
71
+
72
+ ### uv (environment)
73
+
74
+ ```bash
75
+ uv pip install swarmauri_auth_idp_google
76
+ ```
77
+
78
+ ## Usage
79
+
80
+ ```python
81
+ import asyncio
82
+ from pydantic import SecretBytes, SecretStr
83
+ from swarmauri_auth_idp_google import GoogleOAuth20Login
84
+
85
+ login = GoogleOAuth20Login(
86
+ client_id="google-client-id",
87
+ client_secret=SecretStr("google-client-secret"),
88
+ redirect_uri="https://app.example.com/callback",
89
+ state_secret=SecretBytes(b"replace-with-random-bytes"),
90
+ )
91
+
92
+ async def run_flow() -> None:
93
+ auth = await login.auth_url()
94
+ print(auth["url"])
95
+ # Redirect the browser to `auth["url"]`, then capture the callback `code` and `state`.
96
+ # Later, call `login.exchange_and_identity(code, state)` inside your callback handler.
97
+
98
+ asyncio.run(run_flow())
99
+ ```
100
+
101
+ ### Workflow Summary
102
+
103
+ 1. Call `auth_url()` and redirect the browser to the returned URL.
104
+ 2. Persist the `state` and verify it during the callback handler.
105
+ 3. Exchange the authorization code through `exchange_and_identity()` to obtain tokens and profile metadata.
106
+
107
+ ## Entry Points
108
+
109
+ - `swarmauri.auth_idp:GoogleOAuth20Login`
110
+ - `swarmauri.auth_idp:GoogleOAuth21Login`
111
+ - `swarmauri.auth_idp:GoogleOIDC10Login`
112
+
113
+ ## Contributing
114
+
115
+ To contribute to swarmauri-sdk, review the
116
+ [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
117
+ which cover development workflow, testing, and coding standards.
118
+
@@ -0,0 +1,89 @@
1
+ ![Swarmauri Logo](https://github.com/swarmauri/swarmauri-sdk/blob/master/assets/swarmauri.brand.theme.svg)
2
+
3
+ <p align="center">
4
+ <a href="https://pypi.org/project/swarmauri_auth_idp_google/">
5
+ <img src="https://img.shields.io/pypi/dm/swarmauri_auth_idp_google" alt="PyPI - Downloads"/></a>
6
+ <a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/experimental/swarmauri_auth_idp_google/">
7
+ <img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/experimental/swarmauri_auth_idp_google.svg"/></a>
8
+ <a href="https://pypi.org/project/swarmauri_auth_idp_google/">
9
+ <img src="https://img.shields.io/pypi/pyversions/swarmauri_auth_idp_google" alt="PyPI - Python Version"/></a>
10
+ <a href="https://pypi.org/project/swarmauri_auth_idp_google/">
11
+ <img src="https://img.shields.io/pypi/l/swarmauri_auth_idp_google" alt="PyPI - License"/></a>
12
+ <a href="https://pypi.org/project/swarmauri_auth_idp_google/">
13
+ <img src="https://img.shields.io/pypi/v/swarmauri_auth_idp_google?label=swarmauri_auth_idp_google&color=green" alt="PyPI - swarmauri_auth_idp_google"/></a>
14
+ </p>
15
+
16
+ ---
17
+
18
+ # Swarmauri Auth IDP Google
19
+
20
+ Google OAuth 2.0 / OAuth 2.1 / OIDC 1.0 identity providers packaged for Swarmauri deployments.
21
+
22
+ ## Features
23
+
24
+ - PKCE-enabled Authorization Code flows with HMAC-signed state payloads.
25
+ - Discovery-driven OAuth 2.1/OIDC login that validates ID tokens and nonces.
26
+ - Profile hydration via Google UserInfo endpoints for normalized downstream payloads.
27
+ - Retry-aware HTTP integration tuned for Google Identity services.
28
+ - ComponentBase-compatible models registered under `swarmauri.auth_idp` entry points.
29
+
30
+ ## Installation
31
+
32
+ ### pip
33
+
34
+ ```bash
35
+ pip install swarmauri_auth_idp_google
36
+ ```
37
+
38
+ ### uv (project)
39
+
40
+ ```bash
41
+ uv add swarmauri_auth_idp_google
42
+ ```
43
+
44
+ ### uv (environment)
45
+
46
+ ```bash
47
+ uv pip install swarmauri_auth_idp_google
48
+ ```
49
+
50
+ ## Usage
51
+
52
+ ```python
53
+ import asyncio
54
+ from pydantic import SecretBytes, SecretStr
55
+ from swarmauri_auth_idp_google import GoogleOAuth20Login
56
+
57
+ login = GoogleOAuth20Login(
58
+ client_id="google-client-id",
59
+ client_secret=SecretStr("google-client-secret"),
60
+ redirect_uri="https://app.example.com/callback",
61
+ state_secret=SecretBytes(b"replace-with-random-bytes"),
62
+ )
63
+
64
+ async def run_flow() -> None:
65
+ auth = await login.auth_url()
66
+ print(auth["url"])
67
+ # Redirect the browser to `auth["url"]`, then capture the callback `code` and `state`.
68
+ # Later, call `login.exchange_and_identity(code, state)` inside your callback handler.
69
+
70
+ asyncio.run(run_flow())
71
+ ```
72
+
73
+ ### Workflow Summary
74
+
75
+ 1. Call `auth_url()` and redirect the browser to the returned URL.
76
+ 2. Persist the `state` and verify it during the callback handler.
77
+ 3. Exchange the authorization code through `exchange_and_identity()` to obtain tokens and profile metadata.
78
+
79
+ ## Entry Points
80
+
81
+ - `swarmauri.auth_idp:GoogleOAuth20Login`
82
+ - `swarmauri.auth_idp:GoogleOAuth21Login`
83
+ - `swarmauri.auth_idp:GoogleOIDC10Login`
84
+
85
+ ## Contributing
86
+
87
+ To contribute to swarmauri-sdk, review the
88
+ [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
89
+ which cover development workflow, testing, and coding standards.
@@ -0,0 +1,84 @@
1
+ [project]
2
+ name = "swarmauri_auth_idp_google"
3
+ version = "0.2.0.dev5"
4
+ description = "Google OAuth 2.0 / OAuth 2.1 / OIDC 1.0 identity provider implementations for Swarmauri"
5
+ license = "Apache-2.0"
6
+ readme = "README.md"
7
+ requires-python = ">=3.10,<3.13"
8
+ repository = "https://github.com/swarmauri/swarmauri-sdk"
9
+ authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
10
+ classifiers = [
11
+ "Development Status :: 1 - Planning",
12
+ "Intended Audience :: Developers",
13
+ "License :: OSI Approved :: Apache Software License",
14
+ "Natural Language :: English",
15
+ "Programming Language :: Python",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3 :: Only",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Topic :: Internet :: WWW/HTTP",
22
+ "Topic :: Security :: Cryptography",
23
+ ]
24
+ keywords = [
25
+ "swarmauri",
26
+ "sdk",
27
+ "experimental",
28
+ "identity",
29
+ "oauth2",
30
+ "oauth21",
31
+ "oidc",
32
+ "google",
33
+ "idp",
34
+ ]
35
+ dependencies = [
36
+ "swarmauri_core",
37
+ "swarmauri_base",
38
+ "httpx>=0.27",
39
+ "pyjwt[crypto]>=2.8",
40
+ ]
41
+
42
+ [project.entry-points.'swarmauri.auth_idp']
43
+ GoogleOAuth20Login = "swarmauri_auth_idp_google:GoogleOAuth20Login"
44
+ GoogleOAuth21Login = "swarmauri_auth_idp_google:GoogleOAuth21Login"
45
+ GoogleOIDC10Login = "swarmauri_auth_idp_google:GoogleOIDC10Login"
46
+
47
+ [tool.uv.sources]
48
+ swarmauri_tests_pylicense = { workspace = true }
49
+ swarmauri_core = { workspace = true }
50
+ swarmauri_base = { workspace = true }
51
+
52
+ [tool.pytest.ini_options]
53
+ markers = [
54
+ "test: standard test",
55
+ "unit: Unit tests",
56
+ "i9n: Integration tests",
57
+ "r8n: Regression tests",
58
+ "acceptance: Acceptance tests",
59
+ "perf: Performance tests",
60
+ "example: Documentation examples",
61
+ ]
62
+ timeout = 300
63
+ log_cli = true
64
+ log_cli_level = "INFO"
65
+ log_cli_format = "%(asctime)s [%(levelname)s] %(message)s"
66
+ log_cli_date_format = "%Y-%m-%d %H:%M:%S"
67
+ asyncio_default_fixture_loop_scope = "function"
68
+ addopts = "--pylicense-accept-deps=sniffio"
69
+
70
+ [dependency-groups]
71
+ dev = [
72
+ "pytest>=8.0",
73
+ "pytest-asyncio>=0.24.0",
74
+ "pytest-xdist>=3.6.1",
75
+ "pytest-json-report>=1.5.0",
76
+ "pytest-timeout>=2.3.1",
77
+ "pytest-benchmark>=4.0.0",
78
+ "ruff>=0.9.9",
79
+ "swarmauri_tests_pylicense",
80
+ ]
81
+
82
+ [build-system]
83
+ requires = ["poetry-core>=1.0.0"]
84
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1,30 @@
1
+ """Google OAuth 2.0 Authorization Code login implementation."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Mapping
6
+
7
+ from swarmauri_base.ComponentBase import ComponentBase
8
+ from swarmauri_base.auth_idp import OAuth20LoginBase
9
+
10
+ from .GoogleOAuthLoginMixin import GoogleOAuthLoginMixin
11
+
12
+
13
+ @ComponentBase.register_type(OAuth20LoginBase, "GoogleOAuth20Login")
14
+ class GoogleOAuth20Login(GoogleOAuthLoginMixin, OAuth20LoginBase):
15
+ """Implement the Google OAuth 2.0 PKCE flow with profile enrichment."""
16
+
17
+ async def auth_url(self) -> Mapping[str, str]:
18
+ payload = await self._auth_payload()
19
+ return {"url": payload["url"], "state": payload["state"]}
20
+
21
+ async def exchange_and_identity(self, code: str, state: str) -> Mapping[str, Any]:
22
+ tokens = await self._exchange_tokens(code, state)
23
+ profile = await self._fetch_profile(tokens["access_token"])
24
+ return {
25
+ "issuer": "google-oauth20",
26
+ "sub": profile.get("id"),
27
+ "email": profile.get("email"),
28
+ "name": profile.get("name"),
29
+ "raw": {"tokens": tokens, "userinfo": profile},
30
+ }
@@ -0,0 +1,31 @@
1
+ """Google OAuth 2.1 Authorization Code login implementation."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Mapping
6
+
7
+ from swarmauri_base.ComponentBase import ComponentBase
8
+ from swarmauri_base.auth_idp import OAuth21LoginBase
9
+
10
+ from .GoogleOIDCLoginMixin import GoogleOIDCLoginMixin
11
+
12
+
13
+ @ComponentBase.register_type(OAuth21LoginBase, "GoogleOAuth21Login")
14
+ class GoogleOAuth21Login(GoogleOIDCLoginMixin, OAuth21LoginBase):
15
+ """Implement the Google OAuth 2.1 Authorization Code flow with PKCE."""
16
+
17
+ async def auth_url(self) -> Mapping[str, str]:
18
+ payload = await self._auth_payload()
19
+ return {"url": payload["url"], "state": payload["state"]}
20
+
21
+ async def exchange_and_identity(self, code: str, state: str) -> Mapping[str, Any]:
22
+ result = await self._exchange_tokens(code, state)
23
+ tokens = result["tokens"]
24
+ claims = result["claims"]
25
+ return {
26
+ "issuer": "google-oauth21",
27
+ "sub": claims.get("sub"),
28
+ "email": claims.get("email"),
29
+ "name": claims.get("name") or claims.get("given_name"),
30
+ "raw": {"tokens": tokens, "claims": claims},
31
+ }
@@ -0,0 +1,87 @@
1
+ """Shared helpers for Google OAuth 2.0 style user login implementations."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Callable, Mapping
6
+
7
+ from pydantic import ConfigDict, Field, SecretBytes, SecretStr
8
+
9
+ from swarmauri_base.auth_idp import (
10
+ RetryingAsyncClient,
11
+ make_pkce_pair,
12
+ sign_state,
13
+ verify_state,
14
+ )
15
+
16
+ GOOGLE_AUTHORIZATION_ENDPOINT = "https://accounts.google.com/o/oauth2/v2/auth"
17
+ GOOGLE_TOKEN_ENDPOINT = "https://oauth2.googleapis.com/token"
18
+ GOOGLE_USERINFO_ENDPOINT = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json"
19
+ GOOGLE_DEFAULT_SCOPE = (
20
+ "https://www.googleapis.com/auth/userinfo.email "
21
+ "https://www.googleapis.com/auth/userinfo.profile"
22
+ )
23
+
24
+
25
+ class GoogleOAuthLoginMixin:
26
+ """Reusable PKCE/state/token helpers shared across Google OAuth logins."""
27
+
28
+ model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
29
+
30
+ client_id: str
31
+ client_secret: SecretStr
32
+ redirect_uri: str
33
+ state_secret: SecretBytes
34
+ scope: str = Field(default=GOOGLE_DEFAULT_SCOPE)
35
+ http_client_factory: Callable[[], RetryingAsyncClient] = Field(
36
+ default=RetryingAsyncClient, exclude=True, repr=False
37
+ )
38
+
39
+ def _client_secret_value(self) -> str:
40
+ return self.client_secret.get_secret_value()
41
+
42
+ def _state_secret_value(self) -> bytes:
43
+ return self.state_secret.get_secret_value()
44
+
45
+ async def _auth_payload(self) -> Mapping[str, str]:
46
+ verifier, challenge = make_pkce_pair()
47
+ state = sign_state(self._state_secret_value(), {"verifier": verifier})
48
+ url = (
49
+ f"{GOOGLE_AUTHORIZATION_ENDPOINT}?response_type=code"
50
+ f"&client_id={self.client_id}&redirect_uri={self.redirect_uri}"
51
+ f"&scope={self.scope}&state={state}"
52
+ f"&code_challenge={challenge}&code_challenge_method=S256"
53
+ f"&access_type=offline&prompt=select_account"
54
+ )
55
+ return {"url": url, "state": state, "verifier": verifier}
56
+
57
+ async def _exchange_tokens(self, code: str, state: str) -> Mapping[str, Any]:
58
+ payload = verify_state(self._state_secret_value(), state)
59
+ form = {
60
+ "grant_type": "authorization_code",
61
+ "code": code,
62
+ "redirect_uri": self.redirect_uri,
63
+ "client_id": self.client_id,
64
+ "client_secret": self._client_secret_value(),
65
+ "code_verifier": payload["verifier"],
66
+ }
67
+ async with self.http_client_factory() as client:
68
+ response = await client.post_retry(
69
+ GOOGLE_TOKEN_ENDPOINT,
70
+ data=form,
71
+ headers={"Accept": "application/json"},
72
+ )
73
+ response.raise_for_status()
74
+ return response.json()
75
+
76
+ async def _fetch_profile(self, access_token: str) -> Mapping[str, Any]:
77
+ headers = {
78
+ "Authorization": f"Bearer {access_token}",
79
+ "Accept": "application/json",
80
+ }
81
+ async with self.http_client_factory() as client:
82
+ response = await client.get_retry(GOOGLE_USERINFO_ENDPOINT, headers=headers)
83
+ response.raise_for_status()
84
+ return response.json()
85
+
86
+
87
+ __all__ = ["GoogleOAuthLoginMixin"]
@@ -0,0 +1,31 @@
1
+ """Google OpenID Connect 1.0 Authorization Code login implementation."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Mapping
6
+
7
+ from swarmauri_base.ComponentBase import ComponentBase
8
+ from swarmauri_base.auth_idp import OIDC10LoginBase
9
+
10
+ from .GoogleOIDCLoginMixin import GoogleOIDCLoginMixin
11
+
12
+
13
+ @ComponentBase.register_type(OIDC10LoginBase, "GoogleOIDC10Login")
14
+ class GoogleOIDC10Login(GoogleOIDCLoginMixin, OIDC10LoginBase):
15
+ """Implement Google OIDC 1.0 Authorization Code flow with PKCE."""
16
+
17
+ async def auth_url(self) -> Mapping[str, str]:
18
+ payload = await self._auth_payload()
19
+ return {"url": payload["url"], "state": payload["state"]}
20
+
21
+ async def exchange(self, code: str, state: str) -> Mapping[str, Any]:
22
+ result = await self._exchange_tokens(code, state)
23
+ tokens = result["tokens"]
24
+ claims = result["claims"]
25
+ return {
26
+ "issuer": "google-oidc",
27
+ "sub": claims.get("sub"),
28
+ "email": claims.get("email"),
29
+ "name": claims.get("name") or claims.get("given_name"),
30
+ "raw": {"tokens": tokens, "claims": claims},
31
+ }
@@ -0,0 +1,159 @@
1
+ """Shared helpers for Google OAuth 2.1 / OIDC user login implementations."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Callable, Mapping, Optional, Sequence
6
+
7
+ import jwt
8
+ from pydantic import ConfigDict, Field, SecretBytes, SecretStr
9
+
10
+ from swarmauri_base.auth_idp import (
11
+ RetryingAsyncClient,
12
+ make_nonce,
13
+ make_pkce_pair,
14
+ sign_state,
15
+ verify_state,
16
+ )
17
+
18
+ GOOGLE_DISCOVERY_ENDPOINT = (
19
+ "https://accounts.google.com/.well-known/openid-configuration"
20
+ )
21
+ DEFAULT_ALLOWED_ISSUERS = (
22
+ "https://accounts.google.com",
23
+ "accounts.google.com",
24
+ )
25
+
26
+
27
+ class GoogleOIDCLoginMixin:
28
+ """Discovery, PKCE, and ID token validation utilities for Google logins."""
29
+
30
+ model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
31
+
32
+ client_id: str
33
+ client_secret: SecretStr
34
+ redirect_uri: str
35
+ state_secret: SecretBytes
36
+ scope: str = Field(default="openid email profile")
37
+ allowed_issuers: Sequence[str] = Field(
38
+ default=DEFAULT_ALLOWED_ISSUERS, exclude=True, repr=False
39
+ )
40
+ discovery_endpoint: str = Field(
41
+ default=GOOGLE_DISCOVERY_ENDPOINT, exclude=True, repr=False
42
+ )
43
+ http_client_factory: Callable[[], RetryingAsyncClient] = Field(
44
+ default=RetryingAsyncClient, exclude=True, repr=False
45
+ )
46
+ discovery_cache: Optional[Mapping[str, Any]] = Field(
47
+ default=None, exclude=True, repr=False
48
+ )
49
+
50
+ def _client_secret_value(self) -> str:
51
+ return self.client_secret.get_secret_value()
52
+
53
+ def _state_secret_value(self) -> bytes:
54
+ return self.state_secret.get_secret_value()
55
+
56
+ async def _metadata(self) -> Mapping[str, Any]:
57
+ if self.discovery_cache is None:
58
+ async with self.http_client_factory() as client:
59
+ response = await client.get_retry(
60
+ self.discovery_endpoint, headers={"Accept": "application/json"}
61
+ )
62
+ response.raise_for_status()
63
+ self.discovery_cache = response.json()
64
+ return self.discovery_cache
65
+
66
+ async def _auth_payload(self) -> Mapping[str, str]:
67
+ metadata = await self._metadata()
68
+ verifier, challenge = make_pkce_pair()
69
+ nonce = make_nonce()
70
+ state = sign_state(
71
+ self._state_secret_value(), {"verifier": verifier, "nonce": nonce}
72
+ )
73
+ endpoint = metadata["authorization_endpoint"]
74
+ url = (
75
+ f"{endpoint}?response_type=code"
76
+ f"&client_id={self.client_id}&redirect_uri={self.redirect_uri}"
77
+ f"&scope={self.scope}&state={state}&nonce={nonce}"
78
+ f"&code_challenge={challenge}&code_challenge_method=S256"
79
+ f"&include_granted_scopes=true&prompt=select_account"
80
+ )
81
+ return {"url": url, "state": state, "verifier": verifier, "nonce": nonce}
82
+
83
+ async def _exchange_tokens(self, code: str, state: str) -> Mapping[str, Any]:
84
+ payload = verify_state(self._state_secret_value(), state)
85
+ metadata = await self._metadata()
86
+ form = {
87
+ "grant_type": "authorization_code",
88
+ "code": code,
89
+ "redirect_uri": self.redirect_uri,
90
+ "client_id": self.client_id,
91
+ "client_secret": self._client_secret_value(),
92
+ "code_verifier": payload["verifier"],
93
+ }
94
+ async with self.http_client_factory() as client:
95
+ response = await client.post_retry(
96
+ metadata["token_endpoint"],
97
+ data=form,
98
+ headers={"Accept": "application/json"},
99
+ )
100
+ response.raise_for_status()
101
+ tokens = response.json()
102
+ jwks_response = await client.get_retry(
103
+ metadata["jwks_uri"], headers={"Accept": "application/json"}
104
+ )
105
+ jwks_response.raise_for_status()
106
+ jwks = jwks_response.json()
107
+ claims = await self._decode_id_token(tokens, jwks, metadata)
108
+ if claims.get("nonce") != payload["nonce"]:
109
+ raise ValueError("nonce mismatch")
110
+ if metadata.get("userinfo_endpoint"):
111
+ if not claims.get("email") or not claims.get("name"):
112
+ async with self.http_client_factory() as client:
113
+ userinfo_response = await client.get_retry(
114
+ metadata["userinfo_endpoint"],
115
+ headers={
116
+ "Authorization": f"Bearer {tokens['access_token']}",
117
+ "Accept": "application/json",
118
+ },
119
+ )
120
+ userinfo_response.raise_for_status()
121
+ userinfo = userinfo_response.json()
122
+ claims = {**userinfo, **claims}
123
+ return {"tokens": tokens, "claims": claims}
124
+
125
+ async def _decode_id_token(
126
+ self,
127
+ tokens: Mapping[str, Any],
128
+ jwks: Mapping[str, Any],
129
+ metadata: Mapping[str, Any],
130
+ ) -> Mapping[str, Any]:
131
+ id_token = tokens.get("id_token")
132
+ if not id_token:
133
+ raise ValueError("no id_token in response")
134
+ header = jwt.get_unverified_header(id_token)
135
+ kid = header.get("kid")
136
+ if not kid:
137
+ raise ValueError("missing kid in id_token header")
138
+ key_entry = next(
139
+ (entry for entry in jwks.get("keys", []) if entry.get("kid") == kid),
140
+ None,
141
+ )
142
+ if not key_entry:
143
+ raise ValueError("signing key not found")
144
+ algorithm = header.get("alg", "RS256")
145
+ signer = jwt.algorithms.RSAAlgorithm.from_jwk(key_entry)
146
+ issuers = list(self.allowed_issuers)
147
+ issuer_from_metadata = metadata.get("issuer")
148
+ if issuer_from_metadata and issuer_from_metadata not in issuers:
149
+ issuers.append(issuer_from_metadata)
150
+ return jwt.decode(
151
+ id_token,
152
+ signer,
153
+ algorithms=[algorithm],
154
+ audience=self.client_id,
155
+ issuer=issuers,
156
+ )
157
+
158
+
159
+ __all__ = ["GoogleOIDCLoginMixin"]
@@ -0,0 +1,11 @@
1
+ """Google identity provider implementations for Swarmauri."""
2
+
3
+ from .GoogleOAuth20Login import GoogleOAuth20Login
4
+ from .GoogleOAuth21Login import GoogleOAuth21Login
5
+ from .GoogleOIDC10Login import GoogleOIDC10Login
6
+
7
+ __all__ = [
8
+ "GoogleOAuth20Login",
9
+ "GoogleOAuth21Login",
10
+ "GoogleOIDC10Login",
11
+ ]