apron-auth 0.1.0__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.
- apron_auth-0.1.0/.github/workflows/ci.yaml +32 -0
- apron_auth-0.1.0/.github/workflows/release.yaml +39 -0
- apron_auth-0.1.0/.gitignore +17 -0
- apron_auth-0.1.0/.pre-commit-config.yaml +34 -0
- apron_auth-0.1.0/LICENSE +201 -0
- apron_auth-0.1.0/Makefile +19 -0
- apron_auth-0.1.0/PKG-INFO +274 -0
- apron_auth-0.1.0/README.md +261 -0
- apron_auth-0.1.0/pyproject.toml +51 -0
- apron_auth-0.1.0/ruff.toml +50 -0
- apron_auth-0.1.0/scripts/setup_uv.sh +43 -0
- apron_auth-0.1.0/setup.cfg +4 -0
- apron_auth-0.1.0/src/apron_auth/__init__.py +36 -0
- apron_auth-0.1.0/src/apron_auth/client.py +282 -0
- apron_auth-0.1.0/src/apron_auth/errors.py +35 -0
- apron_auth-0.1.0/src/apron_auth/models.py +152 -0
- apron_auth-0.1.0/src/apron_auth/pkce.py +25 -0
- apron_auth-0.1.0/src/apron_auth/protocols.py +85 -0
- apron_auth-0.1.0/src/apron_auth/providers/__init__.py +3 -0
- apron_auth-0.1.0/src/apron_auth/providers/atlassian.py +71 -0
- apron_auth-0.1.0/src/apron_auth/providers/github.py +141 -0
- apron_auth-0.1.0/src/apron_auth/providers/google.py +90 -0
- apron_auth-0.1.0/src/apron_auth/providers/hubspot.py +126 -0
- apron_auth-0.1.0/src/apron_auth/providers/linear.py +41 -0
- apron_auth-0.1.0/src/apron_auth/providers/microsoft.py +78 -0
- apron_auth-0.1.0/src/apron_auth/providers/notion.py +109 -0
- apron_auth-0.1.0/src/apron_auth/providers/salesforce.py +82 -0
- apron_auth-0.1.0/src/apron_auth/providers/slack.py +98 -0
- apron_auth-0.1.0/src/apron_auth/providers/typeform.py +42 -0
- apron_auth-0.1.0/src/apron_auth/py.typed +0 -0
- apron_auth-0.1.0/src/apron_auth/scopes.py +20 -0
- apron_auth-0.1.0/src/apron_auth/stores.py +71 -0
- apron_auth-0.1.0/src/apron_auth.egg-info/PKG-INFO +274 -0
- apron_auth-0.1.0/src/apron_auth.egg-info/SOURCES.txt +66 -0
- apron_auth-0.1.0/src/apron_auth.egg-info/dependency_links.txt +1 -0
- apron_auth-0.1.0/src/apron_auth.egg-info/requires.txt +3 -0
- apron_auth-0.1.0/src/apron_auth.egg-info/top_level.txt +1 -0
- apron_auth-0.1.0/tests/conftest.py +22 -0
- apron_auth-0.1.0/tests/integration/__init__.py +0 -0
- apron_auth-0.1.0/tests/integration/test_atlassian.py +56 -0
- apron_auth-0.1.0/tests/integration/test_github.py +56 -0
- apron_auth-0.1.0/tests/integration/test_google.py +68 -0
- apron_auth-0.1.0/tests/integration/test_linear.py +56 -0
- apron_auth-0.1.0/tests/integration/test_microsoft.py +44 -0
- apron_auth-0.1.0/tests/integration/test_salesforce.py +56 -0
- apron_auth-0.1.0/tests/integration/test_slack.py +56 -0
- apron_auth-0.1.0/tests/providers/__init__.py +0 -0
- apron_auth-0.1.0/tests/providers/test_atlassian.py +62 -0
- apron_auth-0.1.0/tests/providers/test_disconnect_fully_revokes.py +69 -0
- apron_auth-0.1.0/tests/providers/test_github.py +152 -0
- apron_auth-0.1.0/tests/providers/test_google.py +101 -0
- apron_auth-0.1.0/tests/providers/test_hubspot.py +214 -0
- apron_auth-0.1.0/tests/providers/test_linear.py +27 -0
- apron_auth-0.1.0/tests/providers/test_microsoft.py +60 -0
- apron_auth-0.1.0/tests/providers/test_notion.py +130 -0
- apron_auth-0.1.0/tests/providers/test_salesforce.py +83 -0
- apron_auth-0.1.0/tests/providers/test_scope_metadata_invariant.py +78 -0
- apron_auth-0.1.0/tests/providers/test_slack.py +189 -0
- apron_auth-0.1.0/tests/providers/test_typeform.py +26 -0
- apron_auth-0.1.0/tests/test_client.py +546 -0
- apron_auth-0.1.0/tests/test_end_to_end.py +204 -0
- apron_auth-0.1.0/tests/test_errors.py +49 -0
- apron_auth-0.1.0/tests/test_models.py +272 -0
- apron_auth-0.1.0/tests/test_pkce.py +41 -0
- apron_auth-0.1.0/tests/test_protocols.py +102 -0
- apron_auth-0.1.0/tests/test_scopes.py +43 -0
- apron_auth-0.1.0/tests/test_stores.py +87 -0
- apron_auth-0.1.0/uv.lock +738 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
lint:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v6
|
|
13
|
+
- uses: astral-sh/setup-uv@v7
|
|
14
|
+
with:
|
|
15
|
+
python-version: "3.13"
|
|
16
|
+
- run: uv sync --group lint
|
|
17
|
+
- run: uv run pre-commit run --all-files --verbose
|
|
18
|
+
|
|
19
|
+
test:
|
|
20
|
+
needs: lint
|
|
21
|
+
runs-on: ${{ matrix.os }}
|
|
22
|
+
strategy:
|
|
23
|
+
matrix:
|
|
24
|
+
os: [ubuntu-latest, macos-latest]
|
|
25
|
+
python-version: ["3.11", "3.12", "3.13"]
|
|
26
|
+
steps:
|
|
27
|
+
- uses: actions/checkout@v6
|
|
28
|
+
- uses: astral-sh/setup-uv@v7
|
|
29
|
+
with:
|
|
30
|
+
python-version: ${{ matrix.python-version }}
|
|
31
|
+
- run: uv sync --group tests
|
|
32
|
+
- run: uv run pytest tests/ -v
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [published]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
release:
|
|
10
|
+
environment: pypi
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
id-token: write
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- name: Check out the repository
|
|
17
|
+
uses: actions/checkout@v6
|
|
18
|
+
with:
|
|
19
|
+
fetch-depth: 0
|
|
20
|
+
|
|
21
|
+
- name: Set up Python
|
|
22
|
+
uses: actions/setup-python@v6
|
|
23
|
+
with:
|
|
24
|
+
python-version: "3.13"
|
|
25
|
+
|
|
26
|
+
- name: Upgrade pip
|
|
27
|
+
run: |
|
|
28
|
+
pip install --upgrade pip
|
|
29
|
+
pip --version
|
|
30
|
+
|
|
31
|
+
- name: Install build tools
|
|
32
|
+
run: python -m pip install build setuptools setuptools_scm
|
|
33
|
+
|
|
34
|
+
- name: Build package
|
|
35
|
+
run: python -m build
|
|
36
|
+
|
|
37
|
+
- name: Upload package
|
|
38
|
+
if: github.event_name == 'release'
|
|
39
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
3
|
+
rev: v6.0.0
|
|
4
|
+
hooks:
|
|
5
|
+
- id: check-merge-conflict
|
|
6
|
+
- id: trailing-whitespace
|
|
7
|
+
- id: end-of-file-fixer
|
|
8
|
+
|
|
9
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
10
|
+
rev: v0.15.12
|
|
11
|
+
hooks:
|
|
12
|
+
- id: ruff
|
|
13
|
+
args: [--fix]
|
|
14
|
+
- id: ruff-format
|
|
15
|
+
|
|
16
|
+
- repo: https://github.com/Yelp/detect-secrets
|
|
17
|
+
rev: v1.5.0
|
|
18
|
+
hooks:
|
|
19
|
+
- id: detect-secrets
|
|
20
|
+
|
|
21
|
+
- repo: local
|
|
22
|
+
hooks:
|
|
23
|
+
- id: ty-check
|
|
24
|
+
name: ty
|
|
25
|
+
entry: uvx ty check src/apron_auth --python .venv
|
|
26
|
+
language: system
|
|
27
|
+
pass_filenames: false
|
|
28
|
+
types: [python]
|
|
29
|
+
files: ^src/
|
|
30
|
+
|
|
31
|
+
- repo: https://github.com/astral-sh/uv-pre-commit
|
|
32
|
+
rev: 0.11.7
|
|
33
|
+
hooks:
|
|
34
|
+
- id: uv-lock
|
apron_auth-0.1.0/LICENSE
ADDED
|
@@ -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 2026 Mozilla.ai
|
|
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,19 @@
|
|
|
1
|
+
.PHONY: ensure-scripts-exec
|
|
2
|
+
ensure-scripts-exec:
|
|
3
|
+
@chmod +x scripts/* || true
|
|
4
|
+
|
|
5
|
+
.PHONY: setup
|
|
6
|
+
setup: ensure-scripts-exec
|
|
7
|
+
@scripts/setup_uv.sh
|
|
8
|
+
|
|
9
|
+
.PHONY: test
|
|
10
|
+
test:
|
|
11
|
+
@uv run -m pytest tests
|
|
12
|
+
|
|
13
|
+
.PHONY: test-integration
|
|
14
|
+
test-integration:
|
|
15
|
+
@APRON_AUTH_INTEGRATION_TESTS=1 uv run -m pytest tests -m integration -v
|
|
16
|
+
|
|
17
|
+
.PHONY: lint
|
|
18
|
+
lint:
|
|
19
|
+
@uv run pre-commit run --all-files
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: apron-auth
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Stateless OAuth 2.0 protocol library with PKCE, token refresh, and provider-specific revocation.
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Dist: authlib>=1.6.11
|
|
10
|
+
Requires-Dist: httpx>=0.27
|
|
11
|
+
Requires-Dist: pydantic>=2.0
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# apron-auth
|
|
15
|
+
|
|
16
|
+
Stateless OAuth 2.0 protocol library with PKCE, token refresh, and provider-specific revocation.
|
|
17
|
+
|
|
18
|
+
## What is apron-auth?
|
|
19
|
+
|
|
20
|
+
Provider-specific OAuth knowledge — endpoints, auth methods, PKCE quirks, error classification, and revocation — encoded as a library so your application doesn't have to maintain it.
|
|
21
|
+
|
|
22
|
+
| What | Why |
|
|
23
|
+
|----------------------|-------------------------------------------------------------------------------------------------------------------------------------------|
|
|
24
|
+
| Provider presets | Endpoints, auth methods, PKCE toggles, scope separators, and revocation for multiple providers out of the box. |
|
|
25
|
+
| Error classification | Distinguishes permanent failures (revoked token, invalid client) from transient ones so callers know whether to retry or re-authenticate. |
|
|
26
|
+
| Revocation support | Providers all revoke differently (POST, DELETE, GET, Basic auth, query params) — presets include the right handler when available. |
|
|
27
|
+
| Auth method handling | `client_secret_post` vs `client_secret_basic` — picked from your config and handled by authlib under the hood. |
|
|
28
|
+
| PKCE (S256) | Generated automatically when the provider supports it, no setup needed. |
|
|
29
|
+
|
|
30
|
+
apron-auth is stateless. It doesn't store tokens, manage sessions, or hold database connections — you bring your own storage, apron-auth handles the protocol.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# via uv
|
|
36
|
+
uv add apron-auth
|
|
37
|
+
|
|
38
|
+
# via pip
|
|
39
|
+
pip install apron-auth
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Requires Python 3.11+.
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
### With a provider preset
|
|
47
|
+
|
|
48
|
+
Presets bundle the endpoints, auth method, PKCE config, and revocation handler for a given provider into a single call.
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from apron_auth.providers import google
|
|
52
|
+
|
|
53
|
+
config, revocation_handler = google.preset(
|
|
54
|
+
client_id="your-client-id",
|
|
55
|
+
client_secret="your-client-secret", # pragma: allowlist secret
|
|
56
|
+
scopes=["openid", "email", "profile"],
|
|
57
|
+
)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
If you use [apron-tools](https://github.com/mozilla-ai/apron-tools), scopes come from capability groups instead of being hardcoded:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from apron_tools.providers.google.gmail.scopes import CAPABILITY_GROUP as GMAIL
|
|
64
|
+
|
|
65
|
+
config, revocation_handler = google.preset(
|
|
66
|
+
client_id="your-client-id",
|
|
67
|
+
client_secret="your-client-secret", # pragma: allowlist secret
|
|
68
|
+
scopes=GMAIL.scopes,
|
|
69
|
+
)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Manual configuration
|
|
73
|
+
|
|
74
|
+
If your provider doesn't have a preset, configure it directly.
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from pydantic import SecretStr
|
|
78
|
+
from apron_auth import ProviderConfig
|
|
79
|
+
|
|
80
|
+
config = ProviderConfig(
|
|
81
|
+
client_id="your-client-id",
|
|
82
|
+
client_secret=SecretStr("your-client-secret"), # pragma: allowlist secret
|
|
83
|
+
authorize_url="https://provider.com/oauth/authorize",
|
|
84
|
+
token_url="https://provider.com/oauth/token",
|
|
85
|
+
scopes=["read", "write"],
|
|
86
|
+
)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Authorization URL
|
|
90
|
+
|
|
91
|
+
Build the URL to redirect the user to. State and PKCE are included automatically.
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from apron_auth import OAuthClient
|
|
95
|
+
|
|
96
|
+
client = OAuthClient(config)
|
|
97
|
+
url, pending_state = await client.get_authorization_url(
|
|
98
|
+
redirect_uri="https://yourapp.com/callback",
|
|
99
|
+
)
|
|
100
|
+
# Redirect the user to `url`.
|
|
101
|
+
# Hold onto `pending_state` — you'll need it for the callback.
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Code exchange
|
|
105
|
+
|
|
106
|
+
When the user comes back with an authorization code, exchange it for tokens.
|
|
107
|
+
|
|
108
|
+
```python
|
|
109
|
+
tokens = await client.exchange_code(
|
|
110
|
+
code="authorization-code-from-callback",
|
|
111
|
+
redirect_uri="https://yourapp.com/callback",
|
|
112
|
+
code_verifier=pending_state.code_verifier,
|
|
113
|
+
)
|
|
114
|
+
print(tokens.access_token)
|
|
115
|
+
print(tokens.refresh_token)
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Token refresh
|
|
119
|
+
|
|
120
|
+
Refreshing can fail permanently (the user revoked access, the client was deregistered) or transiently (network blip, rate limit). apron-auth tells you which.
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from apron_auth import PermanentOAuthError
|
|
124
|
+
|
|
125
|
+
try:
|
|
126
|
+
tokens = await client.refresh_token(tokens.refresh_token)
|
|
127
|
+
except PermanentOAuthError:
|
|
128
|
+
# The token can't be recovered — delete it and re-authenticate the user.
|
|
129
|
+
pass
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
By default, `invalid_grant`, `unauthorized_client`, and `invalid_client` are treated as permanent. If your provider uses non-standard error codes for the same thing, you can extend the set:
|
|
133
|
+
|
|
134
|
+
```python
|
|
135
|
+
client = OAuthClient(
|
|
136
|
+
config,
|
|
137
|
+
permanent_error_codes={"token_revoked", "account_suspended"},
|
|
138
|
+
)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
These merge with the defaults — you can inspect them via `OAuthClient.DEFAULT_PERMANENT_ERROR_CODES`.
|
|
142
|
+
|
|
143
|
+
### Token revocation
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
client = OAuthClient(config, revocation_handler=revocation_handler)
|
|
147
|
+
await client.revoke_token(tokens.access_token)
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### State management
|
|
151
|
+
|
|
152
|
+
If you need to persist OAuth state across requests (e.g. between the redirect and the callback), implement the `StateStore` protocol.
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
from apron_auth import StateStore, OAuthPendingState
|
|
156
|
+
|
|
157
|
+
class MyStateStore:
|
|
158
|
+
async def save(self, state: OAuthPendingState) -> None:
|
|
159
|
+
# Persist state, keyed by state.state.
|
|
160
|
+
...
|
|
161
|
+
|
|
162
|
+
async def consume(self, state_key: str) -> OAuthPendingState | None:
|
|
163
|
+
# Look up and invalidate in one step. Return None if it's missing or expired.
|
|
164
|
+
...
|
|
165
|
+
|
|
166
|
+
client = OAuthClient(config, state_store=MyStateStore())
|
|
167
|
+
url, pending_state = await client.get_authorization_url(
|
|
168
|
+
redirect_uri="https://yourapp.com/callback",
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
# When the callback arrives, pass the state parameter and the code.
|
|
172
|
+
# The store is consumed automatically.
|
|
173
|
+
tokens = await client.exchange_code(code="...", state="state-from-callback")
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
#### Carrying context through the flow
|
|
177
|
+
|
|
178
|
+
If your application needs to carry context through the OAuth flow (e.g. which user or tenant initiated it), pass `metadata` when building the authorization URL. apron-auth carries it opaquely through the `StateStore` and surfaces it on `TokenSet.context` after auto-consume.
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
url, pending_state = await client.get_authorization_url(
|
|
182
|
+
redirect_uri="https://yourapp.com/callback",
|
|
183
|
+
metadata={"user_id": "U123", "tenant_id": "T456"},
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
# On callback, context comes back on the TokenSet.
|
|
187
|
+
tokens = await client.exchange_code(code="...", state="state-from-callback")
|
|
188
|
+
print(tokens.context["user_id"]) # "U123"
|
|
189
|
+
print(tokens.context["tenant_id"]) # "T456"
|
|
190
|
+
|
|
191
|
+
# Provider response extras (e.g. Slack's team_id) are separate.
|
|
192
|
+
print(tokens.metadata) # {"team_id": "T123", ...}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Provider presets
|
|
196
|
+
|
|
197
|
+
| Provider | Preset | Revocation | `disconnect_fully_revokes` |
|
|
198
|
+
|------------|--------------------------|------------------------|----------------------------|
|
|
199
|
+
| Google | `google.preset(...)` | POST with query param | `True` |
|
|
200
|
+
| GitHub | `github.preset(...)` | DELETE with Basic auth | `True` |
|
|
201
|
+
| Slack | `slack.preset(...)` | GET with query param | `False` |
|
|
202
|
+
| Notion | `notion.preset(...)` | POST with Basic auth | `False` |
|
|
203
|
+
| Microsoft | `microsoft.preset(...)` | — | `False` |
|
|
204
|
+
| Atlassian | `atlassian.preset(...)` | RFC 7009 POST | `False` |
|
|
205
|
+
| Linear | `linear.preset(...)` | RFC 7009 POST | `False` |
|
|
206
|
+
| Salesforce | `salesforce.preset(...)` | RFC 7009 POST | `False` |
|
|
207
|
+
| Typeform | `typeform.preset(...)` | — | `False` |
|
|
208
|
+
| HubSpot | `hubspot.preset(...)` | DELETE refresh-token | `False` |
|
|
209
|
+
|
|
210
|
+
## Scope reduction tiers
|
|
211
|
+
|
|
212
|
+
Some providers' revocation endpoints fully remove the user's portal-level OAuth grant; others only invalidate the current token while the grant lingers. apron-auth surfaces this difference as `ProviderConfig.disconnect_fully_revokes` so consumers can offer the right scope-reduction UX without rebuilding the per-provider truth table inline.
|
|
213
|
+
|
|
214
|
+
| Tier | Meaning | When |
|
|
215
|
+
|------|---------------------------------------------------------------------------------------------------------------------|-------------------------------------|
|
|
216
|
+
| 1 | Automatic scope reduction: revoke + re-auth presents a fresh consent screen, narrower scopes take effect. | `disconnect_fully_revokes is True` |
|
|
217
|
+
| 3 | Manual via provider settings: deep-link the user to the provider's app management page; revoke alone is not enough. | `disconnect_fully_revokes is False` |
|
|
218
|
+
|
|
219
|
+
```python
|
|
220
|
+
from apron_auth.providers import google, hubspot
|
|
221
|
+
|
|
222
|
+
google_config, _ = google.preset(...)
|
|
223
|
+
hubspot_config, _ = hubspot.preset(...)
|
|
224
|
+
|
|
225
|
+
if google_config.disconnect_fully_revokes:
|
|
226
|
+
... # tier 1: trigger revoke + re-auth in-app
|
|
227
|
+
else:
|
|
228
|
+
... # tier 3: open the provider's app-management page
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
The default for unconfigured `ProviderConfig` is `False` — under-claiming the capability harmlessly falls back to the manual deep-link path.
|
|
232
|
+
|
|
233
|
+
### Trello
|
|
234
|
+
|
|
235
|
+
Trello's API uses OAuth 1.0 exclusively — there is no OAuth 2.0 support yet. Atlassian has [announced plans](https://community.developer.atlassian.com/t/rfc-89-introducing-oauth2-to-trello/90359) to introduce OAuth 2.0 (3LO) for Trello, but no launch date has been committed.
|
|
236
|
+
|
|
237
|
+
Because apron-auth is an OAuth 2.0 library, Trello is not supported. If your application needs Trello, handle its OAuth 1.0 flow separately (e.g. with [authlib](https://docs.authlib.org/en/latest/client/oauth1.html)). [apron-tools](https://github.com/mozilla-ai/apron-tools) provides Trello tool definitions — you just need to bring your own token.
|
|
238
|
+
|
|
239
|
+
When Trello ships OAuth 2.0, a preset will be added here.
|
|
240
|
+
|
|
241
|
+
## Error hierarchy
|
|
242
|
+
|
|
243
|
+
All exceptions inherit from `OAuthError`.
|
|
244
|
+
|
|
245
|
+
| Exception | When it's raised |
|
|
246
|
+
|-----------------------|-----------------------------------------------------------------------------------------------------------------|
|
|
247
|
+
| `TokenExchangeError` | Code exchange failed at the token endpoint. |
|
|
248
|
+
| `TokenRefreshError` | Refresh failed, but it might work if you try again (transient). |
|
|
249
|
+
| `PermanentOAuthError` | The token is gone — `invalid_grant`, `unauthorized_client`, or `invalid_client`. Delete it and re-authenticate. |
|
|
250
|
+
| `RevocationError` | The provider rejected the revocation request. |
|
|
251
|
+
| `StateError` | OAuth state was invalid, expired, or already used. |
|
|
252
|
+
| `ConfigurationError` | Something's wrong with the provider config (e.g. missing `redirect_uri`). |
|
|
253
|
+
|
|
254
|
+
## Development
|
|
255
|
+
|
|
256
|
+
Requires [uv](https://docs.astral.sh/uv/).
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
make setup # Install uv, create venv, sync deps, install pre-commit hooks
|
|
260
|
+
make test # Run unit tests
|
|
261
|
+
make lint # Run pre-commit hooks (ruff, ty, detect-secrets)
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Or using uv directly:
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
uv sync --group dev
|
|
268
|
+
uv run pytest tests
|
|
269
|
+
uv run pre-commit run --all-files
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
## License
|
|
273
|
+
|
|
274
|
+
[Apache-2.0](LICENSE)
|