rampart-python 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: rampart-python
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python middleware adapter for Rampart IAM — JWT verification for FastAPI and Flask
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Requires-Dist: cryptography>=41.0.0
|
|
9
|
+
Requires-Dist: pyjwt>=2.8.0
|
|
10
|
+
Requires-Dist: requests>=2.31.0
|
|
11
|
+
Provides-Extra: dev
|
|
12
|
+
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
|
|
13
|
+
Requires-Dist: pytest>=7.0.0; extra == 'dev'
|
|
14
|
+
Requires-Dist: responses>=0.23.0; extra == 'dev'
|
|
15
|
+
Provides-Extra: fastapi
|
|
16
|
+
Requires-Dist: fastapi>=0.100.0; extra == 'fastapi'
|
|
17
|
+
Provides-Extra: flask
|
|
18
|
+
Requires-Dist: flask>=2.3.0; extra == 'flask'
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# Rampart Python Middleware
|
|
22
|
+
|
|
23
|
+
JWT verification middleware for [Rampart](https://github.com/manimovassagh/rampart) IAM server. Supports **FastAPI** and **Flask**.
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Core (PyJWT + cryptography)
|
|
29
|
+
pip install rampart-python
|
|
30
|
+
|
|
31
|
+
# With FastAPI support
|
|
32
|
+
pip install rampart-python[fastapi]
|
|
33
|
+
|
|
34
|
+
# With Flask support
|
|
35
|
+
pip install rampart-python[flask]
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## FastAPI
|
|
39
|
+
|
|
40
|
+
### Basic Authentication
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
from fastapi import Depends, FastAPI
|
|
44
|
+
from rampart import RampartClaims
|
|
45
|
+
from rampart.fastapi import rampart_auth
|
|
46
|
+
|
|
47
|
+
app = FastAPI()
|
|
48
|
+
auth = rampart_auth("https://auth.example.com")
|
|
49
|
+
|
|
50
|
+
@app.get("/me")
|
|
51
|
+
async def me(claims: RampartClaims = Depends(auth)):
|
|
52
|
+
return {
|
|
53
|
+
"user_id": claims.sub,
|
|
54
|
+
"email": claims.email,
|
|
55
|
+
"roles": claims.roles,
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Role-Based Access Control
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from rampart.fastapi import rampart_auth, require_roles_from_claims
|
|
63
|
+
|
|
64
|
+
auth = rampart_auth("https://auth.example.com")
|
|
65
|
+
check_admin = require_roles_from_claims("admin")
|
|
66
|
+
|
|
67
|
+
@app.get("/admin/users")
|
|
68
|
+
async def list_users(claims: RampartClaims = Depends(auth)):
|
|
69
|
+
check_admin(claims) # Raises 403 if "admin" role is missing
|
|
70
|
+
return {"users": ["..."]}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Flask
|
|
74
|
+
|
|
75
|
+
### Basic Authentication
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
from flask import Flask, g
|
|
79
|
+
from rampart.flask import rampart_auth
|
|
80
|
+
|
|
81
|
+
app = Flask(__name__)
|
|
82
|
+
|
|
83
|
+
@app.route("/me")
|
|
84
|
+
@rampart_auth("https://auth.example.com")
|
|
85
|
+
def me():
|
|
86
|
+
return {
|
|
87
|
+
"user_id": g.auth.sub,
|
|
88
|
+
"email": g.auth.email,
|
|
89
|
+
"roles": g.auth.roles,
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Role-Based Access Control
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from rampart.flask import rampart_auth, require_roles
|
|
97
|
+
|
|
98
|
+
@app.route("/admin/users")
|
|
99
|
+
@rampart_auth("https://auth.example.com")
|
|
100
|
+
@require_roles("admin")
|
|
101
|
+
def list_users():
|
|
102
|
+
return {"users": ["..."]}
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Direct Usage (No Framework)
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from rampart import RampartAuth
|
|
109
|
+
|
|
110
|
+
auth = RampartAuth(issuer="https://auth.example.com")
|
|
111
|
+
claims = auth.verify_token(raw_jwt_string)
|
|
112
|
+
|
|
113
|
+
print(claims.sub) # "user-123"
|
|
114
|
+
print(claims.email) # "user@example.com"
|
|
115
|
+
print(claims.roles) # ["admin", "user"]
|
|
116
|
+
print(claims.org_id) # "org-456"
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Claims
|
|
120
|
+
|
|
121
|
+
Verified tokens return a `RampartClaims` dataclass:
|
|
122
|
+
|
|
123
|
+
| Field | Type | Description |
|
|
124
|
+
|----------------------|----------------|--------------------------------|
|
|
125
|
+
| `sub` | `str` | Subject (user ID) |
|
|
126
|
+
| `iss` | `str` | Issuer URL |
|
|
127
|
+
| `iat` | `int` | Issued-at timestamp |
|
|
128
|
+
| `exp` | `int` | Expiration timestamp |
|
|
129
|
+
| `org_id` | `str | None` | Organization / tenant ID |
|
|
130
|
+
| `preferred_username` | `str | None` | Username |
|
|
131
|
+
| `email` | `str | None` | Email address |
|
|
132
|
+
| `email_verified` | `bool | None` | Whether email is verified |
|
|
133
|
+
| `given_name` | `str | None` | First name |
|
|
134
|
+
| `family_name` | `str | None` | Last name |
|
|
135
|
+
| `roles` | `list[str]` | Assigned roles |
|
|
136
|
+
|
|
137
|
+
## Configuration Options
|
|
138
|
+
|
|
139
|
+
```python
|
|
140
|
+
RampartAuth(
|
|
141
|
+
issuer="https://auth.example.com", # Required: Rampart server URL
|
|
142
|
+
audience="my-api", # Optional: expected audience claim
|
|
143
|
+
jwks_cache_ttl=300, # JWKS cache lifetime in seconds (default: 300)
|
|
144
|
+
algorithms=["RS256"], # Allowed JWT algorithms (default: ["RS256"])
|
|
145
|
+
)
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Running Tests
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
pip install -e ".[dev]"
|
|
152
|
+
pytest tests/
|
|
153
|
+
```
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
rampart_python-0.1.0.dist-info/METADATA,sha256=oqiEoEwm6fb9cPfV3eW80HrdHYJy3QT_u-KK1oiBqow,4234
|
|
2
|
+
rampart_python-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
3
|
+
rampart_python-0.1.0.dist-info/licenses/LICENSE,sha256=ospX5J2d_YIjSp05hRLdhQJ6hp-EI__jPXY_c1b2ckU,1071
|
|
4
|
+
rampart_python-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mani Movassagh
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|