axiam-sdk 1.0.0a1__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.
- axiam_sdk-1.0.0a1/LICENSE +201 -0
- axiam_sdk-1.0.0a1/PKG-INFO +255 -0
- axiam_sdk-1.0.0a1/README.md +215 -0
- axiam_sdk-1.0.0a1/pyproject.toml +145 -0
- axiam_sdk-1.0.0a1/setup.cfg +4 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/__init__.py +37 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/_async_client.py +202 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/_client.py +499 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/_errors.py +264 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/_jwks.py +136 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/_models.py +74 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/_session.py +240 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/amqp/__init__.py +30 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/amqp/_consumer.py +234 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/amqp/_hmac.py +71 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/amqp/_replay.py +164 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/django/__init__.py +8 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/django/middleware.py +325 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/fastapi/__init__.py +220 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/grpc/__init__.py +9 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/grpc/_interceptor.py +126 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/grpc/_tls.py +33 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/grpc/client.py +252 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/grpc/gen/__init__.py +0 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/grpc/gen/authorization_pb2.py +45 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/grpc/gen/authorization_pb2.pyi +41 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/grpc/gen/authorization_pb2_grpc.py +145 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/py.typed +0 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/token/__init__.py +12 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk/token/refresh_guard.py +188 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk.egg-info/PKG-INFO +255 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk.egg-info/SOURCES.txt +52 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk.egg-info/dependency_links.txt +1 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk.egg-info/requires.txt +23 -0
- axiam_sdk-1.0.0a1/src/axiam_sdk.egg-info/top_level.txt +1 -0
- axiam_sdk-1.0.0a1/tests/test_amqp_consume.py +172 -0
- axiam_sdk-1.0.0a1/tests/test_amqp_consumer.py +266 -0
- axiam_sdk-1.0.0a1/tests/test_amqp_hmac.py +76 -0
- axiam_sdk-1.0.0a1/tests/test_amqp_v2_replay.py +283 -0
- axiam_sdk-1.0.0a1/tests/test_async_client_extra.py +250 -0
- axiam_sdk-1.0.0a1/tests/test_client_extra.py +259 -0
- axiam_sdk-1.0.0a1/tests/test_client_login.py +657 -0
- axiam_sdk-1.0.0a1/tests/test_django_middleware.py +430 -0
- axiam_sdk-1.0.0a1/tests/test_error_redaction.py +291 -0
- axiam_sdk-1.0.0a1/tests/test_errors_extra.py +65 -0
- axiam_sdk-1.0.0a1/tests/test_fastapi_dependency.py +382 -0
- axiam_sdk-1.0.0a1/tests/test_grpc_client.py +380 -0
- axiam_sdk-1.0.0a1/tests/test_grpc_interceptor.py +126 -0
- axiam_sdk-1.0.0a1/tests/test_jwks.py +266 -0
- axiam_sdk-1.0.0a1/tests/test_middleware_tenant.py +190 -0
- axiam_sdk-1.0.0a1/tests/test_refresh_guard_extra.py +53 -0
- axiam_sdk-1.0.0a1/tests/test_replay_unit.py +128 -0
- axiam_sdk-1.0.0a1/tests/test_session_cookies.py +371 -0
- axiam_sdk-1.0.0a1/tests/test_single_flight.py +260 -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 [yyyy] [name of copyright owner]
|
|
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,255 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: axiam-sdk
|
|
3
|
+
Version: 1.0.0a1
|
|
4
|
+
Summary: Official Python client SDK for AXIAM IAM
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Repository, https://github.com/ilpanich/axiam-python-sdk
|
|
7
|
+
Project-URL: Documentation, https://ilpanich.github.io/axiam-python-sdk/
|
|
8
|
+
Keywords: axiam,iam,auth,authentication,authorization
|
|
9
|
+
Classifier: Development Status :: 2 - Pre-Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Requires-Python: >=3.10
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: httpx<0.29,>=0.27
|
|
20
|
+
Requires-Dist: grpcio<1.83,>=1.78
|
|
21
|
+
Requires-Dist: aio-pika==9.6.*
|
|
22
|
+
Requires-Dist: pydantic>=2
|
|
23
|
+
Requires-Dist: PyJWT>=2.13
|
|
24
|
+
Provides-Extra: fastapi
|
|
25
|
+
Requires-Dist: fastapi; extra == "fastapi"
|
|
26
|
+
Provides-Extra: django
|
|
27
|
+
Requires-Dist: django; extra == "django"
|
|
28
|
+
Provides-Extra: dev
|
|
29
|
+
Requires-Dist: grpcio-tools<1.83,>=1.78; extra == "dev"
|
|
30
|
+
Requires-Dist: mypy; extra == "dev"
|
|
31
|
+
Requires-Dist: ruff; extra == "dev"
|
|
32
|
+
Requires-Dist: interrogate; extra == "dev"
|
|
33
|
+
Requires-Dist: build; extra == "dev"
|
|
34
|
+
Requires-Dist: twine; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest; extra == "dev"
|
|
36
|
+
Requires-Dist: pytest-asyncio; extra == "dev"
|
|
37
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
38
|
+
Requires-Dist: respx; extra == "dev"
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
|
|
41
|
+
# axiam-sdk (Python)
|
|
42
|
+
|
|
43
|
+
Official Python client SDK for [AXIAM](https://github.com/ilpanich/axiam) — Access eXtended Identity and Authorization Management.
|
|
44
|
+
|
|
45
|
+
## Package identity
|
|
46
|
+
|
|
47
|
+
- **Repository:** [github.com/ilpanich/axiam-python-sdk](https://github.com/ilpanich/axiam-python-sdk)
|
|
48
|
+
- **PyPI package:** `axiam-sdk`
|
|
49
|
+
- **Registry:** [pypi.org/project/axiam-sdk](https://pypi.org/project/axiam-sdk/) _(reserved, not yet published)_
|
|
50
|
+
- **Version tags:** `vX.Y.Z`
|
|
51
|
+
- **API docs:** [ilpanich.github.io/axiam-python-sdk](https://ilpanich.github.io/axiam-python-sdk/)
|
|
52
|
+
- **License:** Apache-2.0
|
|
53
|
+
- **Python:** `>=3.10` (D-11)
|
|
54
|
+
|
|
55
|
+
## Contract conformance
|
|
56
|
+
|
|
57
|
+
This SDK conforms to CONTRACT.md §1–§10.
|
|
58
|
+
|
|
59
|
+
See [`CONTRACT.md`](./CONTRACT.md) for the full cross-language behavioral contract.
|
|
60
|
+
|
|
61
|
+
## Status
|
|
62
|
+
|
|
63
|
+
Implemented (Phase 19). `AxiamClient` (sync) and the dedicated
|
|
64
|
+
`AsyncAxiamClient` (async, SDK-Q08) each expose the same canonical operation
|
|
65
|
+
names — `login`, `verify_mfa`, `refresh`, `logout`, `check_access`, `can`,
|
|
66
|
+
`batch_check` — as sync or `async def` methods respectively (never an
|
|
67
|
+
`async_*`-prefixed twin on the sync class). Each client owns its own session,
|
|
68
|
+
cookie jar, and single-flight refresh guard. gRPC (sync `grpcio` + async
|
|
69
|
+
`grpc.aio`), AMQP (async-only `aio-pika`), a FastAPI dependency, and a Django
|
|
70
|
+
middleware are all available. Six runnable examples live under
|
|
71
|
+
[`examples/`](./examples).
|
|
72
|
+
|
|
73
|
+
## Installation
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pip install axiam-sdk
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
The FastAPI dependency and Django middleware are optional extras — install
|
|
80
|
+
only what you need, since a pure REST/gRPC/AMQP consumer should not be
|
|
81
|
+
forced to pull in FastAPI or Django:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pip install "axiam-sdk[fastapi]"
|
|
85
|
+
pip install "axiam-sdk[django]"
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
from axiam_sdk import AxiamClient
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Quickstart
|
|
93
|
+
|
|
94
|
+
### Login + MFA (§1, §5) — sync `AxiamClient` or async `AsyncAxiamClient`
|
|
95
|
+
|
|
96
|
+
`AxiamClient` (sync) and `AsyncAxiamClient` (async, SDK-Q08) are separate
|
|
97
|
+
classes, each with their own session — pick the one that matches your call
|
|
98
|
+
site's paradigm.
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
from axiam_sdk import AxiamClient
|
|
102
|
+
|
|
103
|
+
# tenant_slug is required — AXIAM is multi-tenant and there is no default
|
|
104
|
+
# tenant (§5). TLS is always verify=True (§6); the only escape hatch is an
|
|
105
|
+
# explicit custom_ca parameter, never a boolean bypass.
|
|
106
|
+
with AxiamClient(base_url="https://localhost:8443", tenant_slug="acme") as client:
|
|
107
|
+
result = client.login(email, password)
|
|
108
|
+
if result.mfa_required:
|
|
109
|
+
result = client.verify_mfa(result.mfa_token, totp_code)
|
|
110
|
+
print(result.session_id, result.expires_in)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
import asyncio
|
|
115
|
+
from axiam_sdk import AsyncAxiamClient
|
|
116
|
+
|
|
117
|
+
async def main() -> None:
|
|
118
|
+
async with AsyncAxiamClient(base_url="https://localhost:8443", tenant_slug="acme") as client:
|
|
119
|
+
result = await client.login(email, password)
|
|
120
|
+
if result.mfa_required:
|
|
121
|
+
result = await client.verify_mfa(result.mfa_token, totp_code)
|
|
122
|
+
print(result.session_id, result.expires_in)
|
|
123
|
+
|
|
124
|
+
asyncio.run(main())
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
See [`examples/login_mfa.py`](./examples/login_mfa.py).
|
|
128
|
+
|
|
129
|
+
### REST authorization checks — check_access / can / batch_check (§1)
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
result = client.check_access("resource:read", resource_id)
|
|
133
|
+
can_write = client.can("resource:write", resource_id)
|
|
134
|
+
|
|
135
|
+
from axiam_sdk import AccessCheck
|
|
136
|
+
results = client.batch_check([
|
|
137
|
+
AccessCheck(action="resource:read", resource_id=resource_id),
|
|
138
|
+
AccessCheck(action="resource:delete", resource_id=resource_id, scope="admin"),
|
|
139
|
+
])
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
`AsyncAxiamClient` exposes the same `check_access`/`can`/`batch_check` names
|
|
143
|
+
as `async def` methods, each backed by that client's own session and
|
|
144
|
+
single-flight refresh guard (§9). See
|
|
145
|
+
[`examples/rest_authz.py`](./examples/rest_authz.py).
|
|
146
|
+
|
|
147
|
+
### gRPC authorization checks (§1, §5, §9, §6)
|
|
148
|
+
|
|
149
|
+
`AuthzGrpcClient` (sync, `grpcio`) and `AsyncAuthzGrpcClient` (async,
|
|
150
|
+
`grpc.aio`) are both first-class transports — the async client is not a
|
|
151
|
+
thread-pool bridge over the sync one.
|
|
152
|
+
|
|
153
|
+
```python
|
|
154
|
+
from axiam_sdk.grpc import AuthzGrpcClient
|
|
155
|
+
|
|
156
|
+
client = AuthzGrpcClient(
|
|
157
|
+
"localhost:9443",
|
|
158
|
+
token_fn=lambda: current_access_token, # non-blocking cache read
|
|
159
|
+
tenant_id=tenant_id,
|
|
160
|
+
refresh_fn=refresh_fn, # invoked exactly once on UNAUTHENTICATED, then one retry (§9.3)
|
|
161
|
+
)
|
|
162
|
+
decision = client.check_access(subject_id, "resource:read", resource_id)
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
See [`examples/grpc_checkaccess.py`](./examples/grpc_checkaccess.py).
|
|
166
|
+
|
|
167
|
+
### AMQP event consumer (§8)
|
|
168
|
+
|
|
169
|
+
```python
|
|
170
|
+
from axiam_sdk.amqp import ErrDrop, consume
|
|
171
|
+
|
|
172
|
+
async def handler(event: dict) -> None:
|
|
173
|
+
if "action" not in event:
|
|
174
|
+
raise ErrDrop("poison message") # nack without requeue
|
|
175
|
+
... # None return -> ack; any other exception -> nack with requeue
|
|
176
|
+
|
|
177
|
+
await consume(channel, "axiam.authz.request", signing_key, handler, prefetch=10)
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Every delivery's HMAC-SHA256 signature is verified BEFORE the handler is
|
|
181
|
+
ever invoked — an unverified message never reaches your code. See
|
|
182
|
+
[`examples/amqp_consumer.py`](./examples/amqp_consumer.py).
|
|
183
|
+
|
|
184
|
+
### FastAPI dependency (§10) — `axiam-sdk[fastapi]`
|
|
185
|
+
|
|
186
|
+
```python
|
|
187
|
+
from fastapi import Depends, FastAPI
|
|
188
|
+
from axiam_sdk.fastapi import AxiamUser, JwksVerifier, require_authenticated_user
|
|
189
|
+
|
|
190
|
+
verifier = JwksVerifier(base_url)
|
|
191
|
+
authenticated_user = require_authenticated_user(verifier, "acme")
|
|
192
|
+
|
|
193
|
+
app = FastAPI()
|
|
194
|
+
|
|
195
|
+
@app.get("/protected")
|
|
196
|
+
async def protected(user: AxiamUser = Depends(authenticated_user)):
|
|
197
|
+
return {"user_id": user.user_id, "tenant_id": user.tenant_id, "roles": user.roles}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
See [`examples/fastapi_dependency.py`](./examples/fastapi_dependency.py).
|
|
201
|
+
|
|
202
|
+
### Django middleware (§10) — `axiam-sdk[django]`
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
# settings.py
|
|
206
|
+
MIDDLEWARE = [..., "axiam_sdk.django.middleware.AxiamAuthMiddleware"]
|
|
207
|
+
AXIAM_JWKS_BASE_URL = "https://localhost:8443"
|
|
208
|
+
AXIAM_TENANT_SLUG = "acme"
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
```python
|
|
212
|
+
# views.py
|
|
213
|
+
def protected_view(request):
|
|
214
|
+
user = request.axiam_user
|
|
215
|
+
return JsonResponse({"user_id": user.user_id, "roles": user.roles})
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
See [`examples/django_middleware.py`](./examples/django_middleware.py).
|
|
219
|
+
|
|
220
|
+
## gRPC stub generation (D-04)
|
|
221
|
+
|
|
222
|
+
`pip install`-ing this package does not require `buf`/`protoc` — the
|
|
223
|
+
generated gRPC stubs (`src/axiam_sdk/grpc/gen/`) are committed and shipped
|
|
224
|
+
in both the wheel and the sdist. Contributors regenerating them locally run:
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
bash scripts/gen_grpc.sh
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
CI regenerates the same way and fails the build on any drift
|
|
231
|
+
(`git diff --exit-code`) between the committed stubs and a fresh
|
|
232
|
+
regeneration from `proto/axiam/v1/`.
|
|
233
|
+
|
|
234
|
+
## TLS policy (§6)
|
|
235
|
+
|
|
236
|
+
`httpx` clients are constructed with `verify=True` hardcoded; the only
|
|
237
|
+
escape hatch is an explicit `custom_ca` parameter (a CA bundle path or
|
|
238
|
+
`ssl.SSLContext`) — there is no boolean bypass anywhere in this SDK,
|
|
239
|
+
including the examples. CI enforces this with a dedicated grep gate.
|
|
240
|
+
|
|
241
|
+
## Development
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
pip install -e ".[dev,fastapi,django]"
|
|
245
|
+
pytest tests
|
|
246
|
+
mypy --strict src
|
|
247
|
+
ruff check .
|
|
248
|
+
ruff format --check .
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
Coverage (as CI runs it, reported to Coveralls):
|
|
252
|
+
|
|
253
|
+
```bash
|
|
254
|
+
pytest --cov=axiam_sdk --cov-report=lcov
|
|
255
|
+
```
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
# axiam-sdk (Python)
|
|
2
|
+
|
|
3
|
+
Official Python client SDK for [AXIAM](https://github.com/ilpanich/axiam) — Access eXtended Identity and Authorization Management.
|
|
4
|
+
|
|
5
|
+
## Package identity
|
|
6
|
+
|
|
7
|
+
- **Repository:** [github.com/ilpanich/axiam-python-sdk](https://github.com/ilpanich/axiam-python-sdk)
|
|
8
|
+
- **PyPI package:** `axiam-sdk`
|
|
9
|
+
- **Registry:** [pypi.org/project/axiam-sdk](https://pypi.org/project/axiam-sdk/) _(reserved, not yet published)_
|
|
10
|
+
- **Version tags:** `vX.Y.Z`
|
|
11
|
+
- **API docs:** [ilpanich.github.io/axiam-python-sdk](https://ilpanich.github.io/axiam-python-sdk/)
|
|
12
|
+
- **License:** Apache-2.0
|
|
13
|
+
- **Python:** `>=3.10` (D-11)
|
|
14
|
+
|
|
15
|
+
## Contract conformance
|
|
16
|
+
|
|
17
|
+
This SDK conforms to CONTRACT.md §1–§10.
|
|
18
|
+
|
|
19
|
+
See [`CONTRACT.md`](./CONTRACT.md) for the full cross-language behavioral contract.
|
|
20
|
+
|
|
21
|
+
## Status
|
|
22
|
+
|
|
23
|
+
Implemented (Phase 19). `AxiamClient` (sync) and the dedicated
|
|
24
|
+
`AsyncAxiamClient` (async, SDK-Q08) each expose the same canonical operation
|
|
25
|
+
names — `login`, `verify_mfa`, `refresh`, `logout`, `check_access`, `can`,
|
|
26
|
+
`batch_check` — as sync or `async def` methods respectively (never an
|
|
27
|
+
`async_*`-prefixed twin on the sync class). Each client owns its own session,
|
|
28
|
+
cookie jar, and single-flight refresh guard. gRPC (sync `grpcio` + async
|
|
29
|
+
`grpc.aio`), AMQP (async-only `aio-pika`), a FastAPI dependency, and a Django
|
|
30
|
+
middleware are all available. Six runnable examples live under
|
|
31
|
+
[`examples/`](./examples).
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install axiam-sdk
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The FastAPI dependency and Django middleware are optional extras — install
|
|
40
|
+
only what you need, since a pure REST/gRPC/AMQP consumer should not be
|
|
41
|
+
forced to pull in FastAPI or Django:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install "axiam-sdk[fastapi]"
|
|
45
|
+
pip install "axiam-sdk[django]"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from axiam_sdk import AxiamClient
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Quickstart
|
|
53
|
+
|
|
54
|
+
### Login + MFA (§1, §5) — sync `AxiamClient` or async `AsyncAxiamClient`
|
|
55
|
+
|
|
56
|
+
`AxiamClient` (sync) and `AsyncAxiamClient` (async, SDK-Q08) are separate
|
|
57
|
+
classes, each with their own session — pick the one that matches your call
|
|
58
|
+
site's paradigm.
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from axiam_sdk import AxiamClient
|
|
62
|
+
|
|
63
|
+
# tenant_slug is required — AXIAM is multi-tenant and there is no default
|
|
64
|
+
# tenant (§5). TLS is always verify=True (§6); the only escape hatch is an
|
|
65
|
+
# explicit custom_ca parameter, never a boolean bypass.
|
|
66
|
+
with AxiamClient(base_url="https://localhost:8443", tenant_slug="acme") as client:
|
|
67
|
+
result = client.login(email, password)
|
|
68
|
+
if result.mfa_required:
|
|
69
|
+
result = client.verify_mfa(result.mfa_token, totp_code)
|
|
70
|
+
print(result.session_id, result.expires_in)
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import asyncio
|
|
75
|
+
from axiam_sdk import AsyncAxiamClient
|
|
76
|
+
|
|
77
|
+
async def main() -> None:
|
|
78
|
+
async with AsyncAxiamClient(base_url="https://localhost:8443", tenant_slug="acme") as client:
|
|
79
|
+
result = await client.login(email, password)
|
|
80
|
+
if result.mfa_required:
|
|
81
|
+
result = await client.verify_mfa(result.mfa_token, totp_code)
|
|
82
|
+
print(result.session_id, result.expires_in)
|
|
83
|
+
|
|
84
|
+
asyncio.run(main())
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
See [`examples/login_mfa.py`](./examples/login_mfa.py).
|
|
88
|
+
|
|
89
|
+
### REST authorization checks — check_access / can / batch_check (§1)
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
result = client.check_access("resource:read", resource_id)
|
|
93
|
+
can_write = client.can("resource:write", resource_id)
|
|
94
|
+
|
|
95
|
+
from axiam_sdk import AccessCheck
|
|
96
|
+
results = client.batch_check([
|
|
97
|
+
AccessCheck(action="resource:read", resource_id=resource_id),
|
|
98
|
+
AccessCheck(action="resource:delete", resource_id=resource_id, scope="admin"),
|
|
99
|
+
])
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
`AsyncAxiamClient` exposes the same `check_access`/`can`/`batch_check` names
|
|
103
|
+
as `async def` methods, each backed by that client's own session and
|
|
104
|
+
single-flight refresh guard (§9). See
|
|
105
|
+
[`examples/rest_authz.py`](./examples/rest_authz.py).
|
|
106
|
+
|
|
107
|
+
### gRPC authorization checks (§1, §5, §9, §6)
|
|
108
|
+
|
|
109
|
+
`AuthzGrpcClient` (sync, `grpcio`) and `AsyncAuthzGrpcClient` (async,
|
|
110
|
+
`grpc.aio`) are both first-class transports — the async client is not a
|
|
111
|
+
thread-pool bridge over the sync one.
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
from axiam_sdk.grpc import AuthzGrpcClient
|
|
115
|
+
|
|
116
|
+
client = AuthzGrpcClient(
|
|
117
|
+
"localhost:9443",
|
|
118
|
+
token_fn=lambda: current_access_token, # non-blocking cache read
|
|
119
|
+
tenant_id=tenant_id,
|
|
120
|
+
refresh_fn=refresh_fn, # invoked exactly once on UNAUTHENTICATED, then one retry (§9.3)
|
|
121
|
+
)
|
|
122
|
+
decision = client.check_access(subject_id, "resource:read", resource_id)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
See [`examples/grpc_checkaccess.py`](./examples/grpc_checkaccess.py).
|
|
126
|
+
|
|
127
|
+
### AMQP event consumer (§8)
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
from axiam_sdk.amqp import ErrDrop, consume
|
|
131
|
+
|
|
132
|
+
async def handler(event: dict) -> None:
|
|
133
|
+
if "action" not in event:
|
|
134
|
+
raise ErrDrop("poison message") # nack without requeue
|
|
135
|
+
... # None return -> ack; any other exception -> nack with requeue
|
|
136
|
+
|
|
137
|
+
await consume(channel, "axiam.authz.request", signing_key, handler, prefetch=10)
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Every delivery's HMAC-SHA256 signature is verified BEFORE the handler is
|
|
141
|
+
ever invoked — an unverified message never reaches your code. See
|
|
142
|
+
[`examples/amqp_consumer.py`](./examples/amqp_consumer.py).
|
|
143
|
+
|
|
144
|
+
### FastAPI dependency (§10) — `axiam-sdk[fastapi]`
|
|
145
|
+
|
|
146
|
+
```python
|
|
147
|
+
from fastapi import Depends, FastAPI
|
|
148
|
+
from axiam_sdk.fastapi import AxiamUser, JwksVerifier, require_authenticated_user
|
|
149
|
+
|
|
150
|
+
verifier = JwksVerifier(base_url)
|
|
151
|
+
authenticated_user = require_authenticated_user(verifier, "acme")
|
|
152
|
+
|
|
153
|
+
app = FastAPI()
|
|
154
|
+
|
|
155
|
+
@app.get("/protected")
|
|
156
|
+
async def protected(user: AxiamUser = Depends(authenticated_user)):
|
|
157
|
+
return {"user_id": user.user_id, "tenant_id": user.tenant_id, "roles": user.roles}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
See [`examples/fastapi_dependency.py`](./examples/fastapi_dependency.py).
|
|
161
|
+
|
|
162
|
+
### Django middleware (§10) — `axiam-sdk[django]`
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
# settings.py
|
|
166
|
+
MIDDLEWARE = [..., "axiam_sdk.django.middleware.AxiamAuthMiddleware"]
|
|
167
|
+
AXIAM_JWKS_BASE_URL = "https://localhost:8443"
|
|
168
|
+
AXIAM_TENANT_SLUG = "acme"
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
# views.py
|
|
173
|
+
def protected_view(request):
|
|
174
|
+
user = request.axiam_user
|
|
175
|
+
return JsonResponse({"user_id": user.user_id, "roles": user.roles})
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
See [`examples/django_middleware.py`](./examples/django_middleware.py).
|
|
179
|
+
|
|
180
|
+
## gRPC stub generation (D-04)
|
|
181
|
+
|
|
182
|
+
`pip install`-ing this package does not require `buf`/`protoc` — the
|
|
183
|
+
generated gRPC stubs (`src/axiam_sdk/grpc/gen/`) are committed and shipped
|
|
184
|
+
in both the wheel and the sdist. Contributors regenerating them locally run:
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
bash scripts/gen_grpc.sh
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
CI regenerates the same way and fails the build on any drift
|
|
191
|
+
(`git diff --exit-code`) between the committed stubs and a fresh
|
|
192
|
+
regeneration from `proto/axiam/v1/`.
|
|
193
|
+
|
|
194
|
+
## TLS policy (§6)
|
|
195
|
+
|
|
196
|
+
`httpx` clients are constructed with `verify=True` hardcoded; the only
|
|
197
|
+
escape hatch is an explicit `custom_ca` parameter (a CA bundle path or
|
|
198
|
+
`ssl.SSLContext`) — there is no boolean bypass anywhere in this SDK,
|
|
199
|
+
including the examples. CI enforces this with a dedicated grep gate.
|
|
200
|
+
|
|
201
|
+
## Development
|
|
202
|
+
|
|
203
|
+
```bash
|
|
204
|
+
pip install -e ".[dev,fastapi,django]"
|
|
205
|
+
pytest tests
|
|
206
|
+
mypy --strict src
|
|
207
|
+
ruff check .
|
|
208
|
+
ruff format --check .
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Coverage (as CI runs it, reported to Coveralls):
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
pytest --cov=axiam_sdk --cov-report=lcov
|
|
215
|
+
```
|