swarmauri_auth_idp_github 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.
- swarmauri_auth_idp_github-0.2.0.dev5/LICENSE +201 -0
- swarmauri_auth_idp_github-0.2.0.dev5/PKG-INFO +120 -0
- swarmauri_auth_idp_github-0.2.0.dev5/README.md +91 -0
- swarmauri_auth_idp_github-0.2.0.dev5/pyproject.toml +84 -0
- swarmauri_auth_idp_github-0.2.0.dev5/swarmauri_auth_idp_github/GitHubAppClientMixin.py +103 -0
- swarmauri_auth_idp_github-0.2.0.dev5/swarmauri_auth_idp_github/GitHubOAuth20AppClient.py +22 -0
- swarmauri_auth_idp_github-0.2.0.dev5/swarmauri_auth_idp_github/GitHubOAuth20Login.py +30 -0
- swarmauri_auth_idp_github-0.2.0.dev5/swarmauri_auth_idp_github/GitHubOAuth21AppClient.py +22 -0
- swarmauri_auth_idp_github-0.2.0.dev5/swarmauri_auth_idp_github/GitHubOAuth21Login.py +30 -0
- swarmauri_auth_idp_github-0.2.0.dev5/swarmauri_auth_idp_github/GitHubOAuthLoginMixin.py +123 -0
- swarmauri_auth_idp_github-0.2.0.dev5/swarmauri_auth_idp_github/__init__.py +13 -0
|
@@ -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,120 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: swarmauri_auth_idp_github
|
|
3
|
+
Version: 0.2.0.dev5
|
|
4
|
+
Summary: GitHub OAuth 2.0 / OAuth 2.1 identity provider implementations for Swarmauri
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: swarmauri,sdk,experimental,identity,oauth2,oauth21,github,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
|
+

|
|
30
|
+
|
|
31
|
+
<p align="center">
|
|
32
|
+
<a href="https://pypi.org/project/swarmauri_auth_idp_github/">
|
|
33
|
+
<img src="https://img.shields.io/pypi/dm/swarmauri_auth_idp_github" alt="PyPI - Downloads"/></a>
|
|
34
|
+
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/experimental/swarmauri_auth_idp_github/">
|
|
35
|
+
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/experimental/swarmauri_auth_idp_github.svg"/></a>
|
|
36
|
+
<a href="https://pypi.org/project/swarmauri_auth_idp_github/">
|
|
37
|
+
<img src="https://img.shields.io/pypi/pyversions/swarmauri_auth_idp_github" alt="PyPI - Python Version"/></a>
|
|
38
|
+
<a href="https://pypi.org/project/swarmauri_auth_idp_github/">
|
|
39
|
+
<img src="https://img.shields.io/pypi/l/swarmauri_auth_idp_github" alt="PyPI - License"/></a>
|
|
40
|
+
<a href="https://pypi.org/project/swarmauri_auth_idp_github/">
|
|
41
|
+
<img src="https://img.shields.io/pypi/v/swarmauri_auth_idp_github?label=swarmauri_auth_idp_github&color=green" alt="PyPI - swarmauri_auth_idp_github"/></a>
|
|
42
|
+
</p>
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
# Swarmauri Auth IDP GitHub
|
|
47
|
+
|
|
48
|
+
GitHub OAuth 2.0 / 2.1 logins and installation token helpers packaged for Swarmauri deployments.
|
|
49
|
+
|
|
50
|
+
## Features
|
|
51
|
+
|
|
52
|
+
- PKCE-enabled Authorization Code flows with HMAC-signed state payloads.
|
|
53
|
+
- Token exchange helpers that return normalized identity payloads for downstream services.
|
|
54
|
+
- Profile enrichment that fetches the authenticated user's primary verified email.
|
|
55
|
+
- Installation access tokens for GitHub Apps with automatic caching and retry-aware HTTP.
|
|
56
|
+
- ComponentBase-compatible models that register under `swarmauri.auth_idp` entry points.
|
|
57
|
+
|
|
58
|
+
## Installation
|
|
59
|
+
|
|
60
|
+
### pip
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
pip install swarmauri_auth_idp_github
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### uv (project)
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
uv add swarmauri_auth_idp_github
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### uv (environment)
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
uv pip install swarmauri_auth_idp_github
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Usage
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
import asyncio
|
|
82
|
+
from pydantic import SecretBytes, SecretStr
|
|
83
|
+
from swarmauri_auth_idp_github import GitHubOAuth21Login
|
|
84
|
+
|
|
85
|
+
login = GitHubOAuth21Login(
|
|
86
|
+
client_id="github-client-id",
|
|
87
|
+
client_secret=SecretStr("github-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
|
+
4. Instantiate `GitHubOAuth21AppClient` to fetch GitHub App installation tokens when acting on behalf of repositories.
|
|
107
|
+
|
|
108
|
+
## Entry Points
|
|
109
|
+
|
|
110
|
+
- `swarmauri.auth_idp:GitHubOAuth20Login`
|
|
111
|
+
- `swarmauri.auth_idp:GitHubOAuth21Login`
|
|
112
|
+
- `swarmauri.auth_idp:GitHubOAuth20AppClient`
|
|
113
|
+
- `swarmauri.auth_idp:GitHubOAuth21AppClient`
|
|
114
|
+
|
|
115
|
+
## Contributing
|
|
116
|
+
|
|
117
|
+
To contribute to swarmauri-sdk, review the
|
|
118
|
+
[guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
|
|
119
|
+
which cover development workflow, testing, and coding standards.
|
|
120
|
+
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://pypi.org/project/swarmauri_auth_idp_github/">
|
|
5
|
+
<img src="https://img.shields.io/pypi/dm/swarmauri_auth_idp_github" alt="PyPI - Downloads"/></a>
|
|
6
|
+
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/experimental/swarmauri_auth_idp_github/">
|
|
7
|
+
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/experimental/swarmauri_auth_idp_github.svg"/></a>
|
|
8
|
+
<a href="https://pypi.org/project/swarmauri_auth_idp_github/">
|
|
9
|
+
<img src="https://img.shields.io/pypi/pyversions/swarmauri_auth_idp_github" alt="PyPI - Python Version"/></a>
|
|
10
|
+
<a href="https://pypi.org/project/swarmauri_auth_idp_github/">
|
|
11
|
+
<img src="https://img.shields.io/pypi/l/swarmauri_auth_idp_github" alt="PyPI - License"/></a>
|
|
12
|
+
<a href="https://pypi.org/project/swarmauri_auth_idp_github/">
|
|
13
|
+
<img src="https://img.shields.io/pypi/v/swarmauri_auth_idp_github?label=swarmauri_auth_idp_github&color=green" alt="PyPI - swarmauri_auth_idp_github"/></a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
# Swarmauri Auth IDP GitHub
|
|
19
|
+
|
|
20
|
+
GitHub OAuth 2.0 / 2.1 logins and installation token helpers packaged for Swarmauri deployments.
|
|
21
|
+
|
|
22
|
+
## Features
|
|
23
|
+
|
|
24
|
+
- PKCE-enabled Authorization Code flows with HMAC-signed state payloads.
|
|
25
|
+
- Token exchange helpers that return normalized identity payloads for downstream services.
|
|
26
|
+
- Profile enrichment that fetches the authenticated user's primary verified email.
|
|
27
|
+
- Installation access tokens for GitHub Apps with automatic caching and retry-aware HTTP.
|
|
28
|
+
- ComponentBase-compatible models that register under `swarmauri.auth_idp` entry points.
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
### pip
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install swarmauri_auth_idp_github
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### uv (project)
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
uv add swarmauri_auth_idp_github
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### uv (environment)
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
uv pip install swarmauri_auth_idp_github
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import asyncio
|
|
54
|
+
from pydantic import SecretBytes, SecretStr
|
|
55
|
+
from swarmauri_auth_idp_github import GitHubOAuth21Login
|
|
56
|
+
|
|
57
|
+
login = GitHubOAuth21Login(
|
|
58
|
+
client_id="github-client-id",
|
|
59
|
+
client_secret=SecretStr("github-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
|
+
4. Instantiate `GitHubOAuth21AppClient` to fetch GitHub App installation tokens when acting on behalf of repositories.
|
|
79
|
+
|
|
80
|
+
## Entry Points
|
|
81
|
+
|
|
82
|
+
- `swarmauri.auth_idp:GitHubOAuth20Login`
|
|
83
|
+
- `swarmauri.auth_idp:GitHubOAuth21Login`
|
|
84
|
+
- `swarmauri.auth_idp:GitHubOAuth20AppClient`
|
|
85
|
+
- `swarmauri.auth_idp:GitHubOAuth21AppClient`
|
|
86
|
+
|
|
87
|
+
## Contributing
|
|
88
|
+
|
|
89
|
+
To contribute to swarmauri-sdk, review the
|
|
90
|
+
[guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/CONTRIBUTING.md)
|
|
91
|
+
which cover development workflow, testing, and coding standards.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "swarmauri_auth_idp_github"
|
|
3
|
+
version = "0.2.0.dev5"
|
|
4
|
+
description = "GitHub OAuth 2.0 / OAuth 2.1 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
|
+
"github",
|
|
32
|
+
"idp",
|
|
33
|
+
]
|
|
34
|
+
dependencies = [
|
|
35
|
+
"swarmauri_core",
|
|
36
|
+
"swarmauri_base",
|
|
37
|
+
"httpx>=0.27",
|
|
38
|
+
"pyjwt[crypto]>=2.8",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[project.entry-points.'swarmauri.auth_idp']
|
|
42
|
+
GitHubOAuth20Login = "swarmauri_auth_idp_github:GitHubOAuth20Login"
|
|
43
|
+
GitHubOAuth21Login = "swarmauri_auth_idp_github:GitHubOAuth21Login"
|
|
44
|
+
GitHubOAuth20AppClient = "swarmauri_auth_idp_github:GitHubOAuth20AppClient"
|
|
45
|
+
GitHubOAuth21AppClient = "swarmauri_auth_idp_github:GitHubOAuth21AppClient"
|
|
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,103 @@
|
|
|
1
|
+
"""Shared helpers for GitHub App installation token clients."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import time
|
|
6
|
+
from datetime import datetime, timezone
|
|
7
|
+
from typing import Any, Callable, Dict, Mapping, Optional, Sequence, Tuple
|
|
8
|
+
|
|
9
|
+
import jwt
|
|
10
|
+
from pydantic import ConfigDict, Field, SecretStr
|
|
11
|
+
|
|
12
|
+
from swarmauri_base.auth_idp.http import RetryingAsyncClient
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class GitHubAppClientMixin:
|
|
16
|
+
"""Reusable JWT and caching helpers for GitHub App installation tokens."""
|
|
17
|
+
|
|
18
|
+
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
|
|
19
|
+
|
|
20
|
+
app_id: str
|
|
21
|
+
installation_id: int
|
|
22
|
+
private_key_pem: SecretStr
|
|
23
|
+
api_base: str = Field(default="https://api.github.com")
|
|
24
|
+
permissions: Optional[Mapping[str, str]] = None
|
|
25
|
+
repository_ids: Optional[Sequence[int]] = None
|
|
26
|
+
repository_names: Optional[Sequence[str]] = None
|
|
27
|
+
cache_skew_seconds: int = Field(default=30, ge=0)
|
|
28
|
+
http_client_factory: Callable[[], RetryingAsyncClient] = Field(
|
|
29
|
+
default=RetryingAsyncClient, exclude=True, repr=False
|
|
30
|
+
)
|
|
31
|
+
cached_token: Optional[Tuple[str, float]] = Field(
|
|
32
|
+
default=None, exclude=True, repr=False
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
def _installation_endpoint(self) -> str:
|
|
36
|
+
base = self.api_base.rstrip("/")
|
|
37
|
+
return f"{base}/app/installations/{self.installation_id}/access_tokens"
|
|
38
|
+
|
|
39
|
+
def _private_key_value(self) -> str:
|
|
40
|
+
return self.private_key_pem.get_secret_value()
|
|
41
|
+
|
|
42
|
+
def _app_jwt(self) -> str:
|
|
43
|
+
now = int(time.time())
|
|
44
|
+
payload = {"iat": now - 60, "exp": now + 600, "iss": self.app_id}
|
|
45
|
+
return jwt.encode(payload, self._private_key_value(), algorithm="RS256")
|
|
46
|
+
|
|
47
|
+
def _request_payload(self) -> Dict[str, Any]:
|
|
48
|
+
payload: Dict[str, Any] = {}
|
|
49
|
+
if self.permissions:
|
|
50
|
+
payload["permissions"] = dict(self.permissions)
|
|
51
|
+
if self.repository_ids:
|
|
52
|
+
payload["repository_ids"] = list(self.repository_ids)
|
|
53
|
+
if self.repository_names:
|
|
54
|
+
payload["repository_names"] = list(self.repository_names)
|
|
55
|
+
return payload
|
|
56
|
+
|
|
57
|
+
@staticmethod
|
|
58
|
+
def _expires_at(payload: Mapping[str, Any]) -> float:
|
|
59
|
+
expires_at = payload.get("expires_at")
|
|
60
|
+
if isinstance(expires_at, str):
|
|
61
|
+
try:
|
|
62
|
+
if expires_at.endswith("Z"):
|
|
63
|
+
expires_at = expires_at[:-1] + "+00:00"
|
|
64
|
+
return (
|
|
65
|
+
datetime.fromisoformat(expires_at)
|
|
66
|
+
.astimezone(timezone.utc)
|
|
67
|
+
.timestamp()
|
|
68
|
+
)
|
|
69
|
+
except ValueError:
|
|
70
|
+
pass
|
|
71
|
+
expires_in = payload.get("expires_in")
|
|
72
|
+
if isinstance(expires_in, (int, float)):
|
|
73
|
+
return time.time() + float(expires_in)
|
|
74
|
+
return time.time() + 3600
|
|
75
|
+
|
|
76
|
+
async def _fetch_token(self) -> Tuple[str, float]:
|
|
77
|
+
payload = self._request_payload()
|
|
78
|
+
async with self.http_client_factory() as client:
|
|
79
|
+
response = await client.post_retry(
|
|
80
|
+
self._installation_endpoint(),
|
|
81
|
+
json=payload or {},
|
|
82
|
+
headers={
|
|
83
|
+
"Authorization": f"Bearer {self._app_jwt()}",
|
|
84
|
+
"Accept": "application/vnd.github+json",
|
|
85
|
+
},
|
|
86
|
+
)
|
|
87
|
+
response.raise_for_status()
|
|
88
|
+
data = response.json()
|
|
89
|
+
token = data["token"]
|
|
90
|
+
expires = self._expires_at(data)
|
|
91
|
+
return token, expires
|
|
92
|
+
|
|
93
|
+
async def _cached_access_token(self) -> str:
|
|
94
|
+
cached = self.cached_token
|
|
95
|
+
now = time.time()
|
|
96
|
+
if cached and now < cached[1] - self.cache_skew_seconds:
|
|
97
|
+
return cached[0]
|
|
98
|
+
token, expires_at = await self._fetch_token()
|
|
99
|
+
self.cached_token = (token, expires_at)
|
|
100
|
+
return token
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
__all__ = ["GitHubAppClientMixin"]
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""GitHub App installation client producing OAuth 2.0 compatible tokens."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
from swarmauri_base.ComponentBase import ComponentBase
|
|
8
|
+
from swarmauri_base.auth_idp import OAuth20AppClientBase
|
|
9
|
+
|
|
10
|
+
from .GitHubAppClientMixin import GitHubAppClientMixin
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@ComponentBase.register_type(OAuth20AppClientBase, "GitHubOAuth20AppClient")
|
|
14
|
+
class GitHubOAuth20AppClient(GitHubAppClientMixin, OAuth20AppClientBase):
|
|
15
|
+
"""Fetch GitHub App installation access tokens."""
|
|
16
|
+
|
|
17
|
+
async def access_token(self, scope: Optional[str] = None) -> str:
|
|
18
|
+
if scope:
|
|
19
|
+
raise ValueError(
|
|
20
|
+
"GitHub installation tokens do not support scope overrides"
|
|
21
|
+
)
|
|
22
|
+
return await self._cached_access_token()
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""GitHub 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 .GitHubOAuthLoginMixin import GitHubOAuthLoginMixin
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@ComponentBase.register_type(OAuth20LoginBase, "GitHubOAuth20Login")
|
|
14
|
+
class GitHubOAuth20Login(GitHubOAuthLoginMixin, OAuth20LoginBase):
|
|
15
|
+
"""Implement the GitHub OAuth 2.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_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": "github-oauth20",
|
|
26
|
+
"sub": str(profile.get("id")),
|
|
27
|
+
"email": profile.get("email"),
|
|
28
|
+
"name": profile.get("name") or profile.get("login"),
|
|
29
|
+
"raw": {"tokens": tokens, "user": profile},
|
|
30
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""GitHub App installation client producing OAuth 2.1 compatible tokens."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
from swarmauri_base.ComponentBase import ComponentBase
|
|
8
|
+
from swarmauri_base.auth_idp import OAuth21AppClientBase
|
|
9
|
+
|
|
10
|
+
from .GitHubAppClientMixin import GitHubAppClientMixin
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@ComponentBase.register_type(OAuth21AppClientBase, "GitHubOAuth21AppClient")
|
|
14
|
+
class GitHubOAuth21AppClient(GitHubAppClientMixin, OAuth21AppClientBase):
|
|
15
|
+
"""Fetch GitHub App installation access tokens."""
|
|
16
|
+
|
|
17
|
+
async def access_token(self, scope: Optional[str] = None) -> str:
|
|
18
|
+
if scope:
|
|
19
|
+
raise ValueError(
|
|
20
|
+
"GitHub installation tokens do not support scope overrides"
|
|
21
|
+
)
|
|
22
|
+
return await self._cached_access_token()
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""GitHub 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 .GitHubOAuthLoginMixin import GitHubOAuthLoginMixin
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@ComponentBase.register_type(OAuth21LoginBase, "GitHubOAuth21Login")
|
|
14
|
+
class GitHubOAuth21Login(GitHubOAuthLoginMixin, OAuth21LoginBase):
|
|
15
|
+
"""Implement the GitHub 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
|
+
tokens = await self._exchange_tokens(code, state)
|
|
23
|
+
profile = await self._fetch_profile(tokens["access_token"])
|
|
24
|
+
return {
|
|
25
|
+
"issuer": "github-oauth21",
|
|
26
|
+
"sub": str(profile.get("id")),
|
|
27
|
+
"email": profile.get("email"),
|
|
28
|
+
"name": profile.get("name") or profile.get("login"),
|
|
29
|
+
"raw": {"tokens": tokens, "user": profile},
|
|
30
|
+
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"""Shared helpers for GitHub OAuth 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
|
+
|
|
17
|
+
class GitHubOAuthLoginMixin:
|
|
18
|
+
"""Reusable PKCE, token exchange, and profile helpers for GitHub logins."""
|
|
19
|
+
|
|
20
|
+
model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True)
|
|
21
|
+
|
|
22
|
+
client_id: str
|
|
23
|
+
client_secret: SecretStr
|
|
24
|
+
redirect_uri: str
|
|
25
|
+
state_secret: SecretBytes
|
|
26
|
+
scope: str = Field(default="read:user user:email")
|
|
27
|
+
oauth_base: str = Field(default="https://github.com/login/oauth")
|
|
28
|
+
api_base: str = Field(default="https://api.github.com")
|
|
29
|
+
http_client_factory: Callable[[], RetryingAsyncClient] = Field(
|
|
30
|
+
default=RetryingAsyncClient, exclude=True, repr=False
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
def _client_secret_value(self) -> str:
|
|
34
|
+
return self.client_secret.get_secret_value()
|
|
35
|
+
|
|
36
|
+
def _state_secret_value(self) -> bytes:
|
|
37
|
+
return self.state_secret.get_secret_value()
|
|
38
|
+
|
|
39
|
+
def _authorization_endpoint(self) -> str:
|
|
40
|
+
return f"{self.oauth_base.rstrip('/')}/authorize"
|
|
41
|
+
|
|
42
|
+
def _token_endpoint(self) -> str:
|
|
43
|
+
return f"{self.oauth_base.rstrip('/')}/access_token"
|
|
44
|
+
|
|
45
|
+
def _user_endpoint(self) -> str:
|
|
46
|
+
return f"{self.api_base.rstrip('/')}/user"
|
|
47
|
+
|
|
48
|
+
def _emails_endpoint(self) -> str:
|
|
49
|
+
return f"{self.api_base.rstrip('/')}/user/emails"
|
|
50
|
+
|
|
51
|
+
async def _auth_payload(self) -> Mapping[str, str]:
|
|
52
|
+
verifier, challenge = make_pkce_pair()
|
|
53
|
+
state = sign_state(self._state_secret_value(), {"verifier": verifier})
|
|
54
|
+
url = (
|
|
55
|
+
f"{self._authorization_endpoint()}?client_id={self.client_id}"
|
|
56
|
+
f"&redirect_uri={self.redirect_uri}"
|
|
57
|
+
f"&scope={self.scope}&state={state}"
|
|
58
|
+
f"&code_challenge={challenge}&code_challenge_method=S256"
|
|
59
|
+
)
|
|
60
|
+
return {"url": url, "state": state, "verifier": verifier}
|
|
61
|
+
|
|
62
|
+
async def _exchange_tokens(self, code: str, state: str) -> Mapping[str, Any]:
|
|
63
|
+
payload = verify_state(self._state_secret_value(), state)
|
|
64
|
+
form = {
|
|
65
|
+
"client_id": self.client_id,
|
|
66
|
+
"client_secret": self._client_secret_value(),
|
|
67
|
+
"code": code,
|
|
68
|
+
"redirect_uri": self.redirect_uri,
|
|
69
|
+
"code_verifier": payload["verifier"],
|
|
70
|
+
}
|
|
71
|
+
async with self.http_client_factory() as client:
|
|
72
|
+
response = await client.post_retry(
|
|
73
|
+
self._token_endpoint(),
|
|
74
|
+
data=form,
|
|
75
|
+
headers={"Accept": "application/json"},
|
|
76
|
+
)
|
|
77
|
+
response.raise_for_status()
|
|
78
|
+
return response.json()
|
|
79
|
+
|
|
80
|
+
async def _fetch_profile(self, access_token: str) -> Mapping[str, Any]:
|
|
81
|
+
headers = {
|
|
82
|
+
"Authorization": f"Bearer {access_token}",
|
|
83
|
+
"Accept": "application/vnd.github+json",
|
|
84
|
+
}
|
|
85
|
+
async with self.http_client_factory() as client:
|
|
86
|
+
user_response = await client.get_retry(
|
|
87
|
+
self._user_endpoint(), headers=headers
|
|
88
|
+
)
|
|
89
|
+
user_response.raise_for_status()
|
|
90
|
+
profile = user_response.json()
|
|
91
|
+
email = profile.get("email")
|
|
92
|
+
if not email:
|
|
93
|
+
try:
|
|
94
|
+
emails_response = await client.get_retry(
|
|
95
|
+
self._emails_endpoint(), headers=headers
|
|
96
|
+
)
|
|
97
|
+
emails_response.raise_for_status()
|
|
98
|
+
emails = emails_response.json()
|
|
99
|
+
if isinstance(emails, list):
|
|
100
|
+
primary = next(
|
|
101
|
+
(
|
|
102
|
+
entry
|
|
103
|
+
for entry in emails
|
|
104
|
+
if isinstance(entry, Mapping)
|
|
105
|
+
and entry.get("verified")
|
|
106
|
+
and entry.get("primary")
|
|
107
|
+
),
|
|
108
|
+
None,
|
|
109
|
+
)
|
|
110
|
+
fallback = primary or next(
|
|
111
|
+
(entry for entry in emails if isinstance(entry, Mapping)),
|
|
112
|
+
None,
|
|
113
|
+
)
|
|
114
|
+
if fallback:
|
|
115
|
+
email = fallback.get("email")
|
|
116
|
+
except Exception: # pragma: no cover - best effort lookup
|
|
117
|
+
email = None
|
|
118
|
+
if email and not profile.get("email"):
|
|
119
|
+
profile["email"] = email
|
|
120
|
+
return profile
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
__all__ = ["GitHubOAuthLoginMixin"]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""GitHub identity provider implementations for Swarmauri."""
|
|
2
|
+
|
|
3
|
+
from .GitHubOAuth20AppClient import GitHubOAuth20AppClient
|
|
4
|
+
from .GitHubOAuth20Login import GitHubOAuth20Login
|
|
5
|
+
from .GitHubOAuth21AppClient import GitHubOAuth21AppClient
|
|
6
|
+
from .GitHubOAuth21Login import GitHubOAuth21Login
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"GitHubOAuth20AppClient",
|
|
10
|
+
"GitHubOAuth20Login",
|
|
11
|
+
"GitHubOAuth21AppClient",
|
|
12
|
+
"GitHubOAuth21Login",
|
|
13
|
+
]
|