propelauth-fastapi 4.2.3__tar.gz → 4.2.6__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.
- propelauth-fastapi-4.2.6/PKG-INFO +161 -0
- propelauth-fastapi-4.2.6/README.md +147 -0
- {propelauth-fastapi-4.2.3 → propelauth-fastapi-4.2.6}/propelauth_fastapi/__init__.py +38 -6
- propelauth-fastapi-4.2.6/propelauth_fastapi.egg-info/PKG-INFO +161 -0
- propelauth-fastapi-4.2.6/propelauth_fastapi.egg-info/requires.txt +2 -0
- {propelauth-fastapi-4.2.3 → propelauth-fastapi-4.2.6}/setup.py +2 -2
- propelauth-fastapi-4.2.3/PKG-INFO +0 -37
- propelauth-fastapi-4.2.3/README.md +0 -23
- propelauth-fastapi-4.2.3/propelauth_fastapi.egg-info/PKG-INFO +0 -37
- propelauth-fastapi-4.2.3/propelauth_fastapi.egg-info/requires.txt +0 -2
- {propelauth-fastapi-4.2.3 → propelauth-fastapi-4.2.6}/LICENSE +0 -0
- {propelauth-fastapi-4.2.3 → propelauth-fastapi-4.2.6}/propelauth_fastapi.egg-info/SOURCES.txt +0 -0
- {propelauth-fastapi-4.2.3 → propelauth-fastapi-4.2.6}/propelauth_fastapi.egg-info/dependency_links.txt +0 -0
- {propelauth-fastapi-4.2.3 → propelauth-fastapi-4.2.6}/propelauth_fastapi.egg-info/top_level.txt +0 -0
- {propelauth-fastapi-4.2.3 → propelauth-fastapi-4.2.6}/setup.cfg +0 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: propelauth-fastapi
|
|
3
|
+
Version: 4.2.6
|
|
4
|
+
Summary: A FastAPI library for managing authentication, backed by PropelAuth
|
|
5
|
+
Home-page: https://github.com/propelauth/propelauth-fastapi
|
|
6
|
+
Author: PropelAuth
|
|
7
|
+
Author-email: support@propelauth.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Platform: UNKNOWN
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="https://www.propelauth.com?ref=github" target="_blank" align="center">
|
|
15
|
+
<img src="https://www.propelauth.com/imgs/lockup.svg" width="200">
|
|
16
|
+
</a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
# PropelAuth FastAPI SDK
|
|
20
|
+
|
|
21
|
+
A FastAPI library for managing authentication, backed by [PropelAuth](https://www.propelauth.com/?utm_campaign=github-fastapi).
|
|
22
|
+
|
|
23
|
+
[PropelAuth](https://www.propelauth.com?ref=github) makes it easy to add authentication and authorization to your B2B/multi-tenant application.
|
|
24
|
+
|
|
25
|
+
Your frontend gets a beautiful, safe, and customizable login screen. Your backend gets easy authorization with just a few lines of code. You get an easy-to-use dashboard to config and manage everything.
|
|
26
|
+
|
|
27
|
+
## Documentation
|
|
28
|
+
|
|
29
|
+
- Full reference this library is [here](https://docs.propelauth.com/reference/backend-apis/fastapi)
|
|
30
|
+
- Getting started guides for PropelAuth are [here](https://docs.propelauth.com/)
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install propelauth_fastapi
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Initialize
|
|
39
|
+
|
|
40
|
+
`init_auth` performs a one-time initialization of the library.
|
|
41
|
+
It will verify your `api_key` is correct and fetch the metadata needed to verify access tokens in [require_user](#require-user) or [optional_user](#optional-user).
|
|
42
|
+
|
|
43
|
+
```py
|
|
44
|
+
from propelauth_fastapi import init_auth
|
|
45
|
+
|
|
46
|
+
auth = init_auth("YOUR_AUTH_URL", "YOUR_API_KEY")
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
# Protect API Routes
|
|
50
|
+
|
|
51
|
+
Protecting an API route is as simple as adding a [dependency](https://fastapi.tiangolo.com/tutorial/dependencies/) to your route.
|
|
52
|
+
|
|
53
|
+
None of the dependencies make a external request to PropelAuth.
|
|
54
|
+
They all are verified locally using the [access token](https://docs.propelauth.com/guides-and-examples/guides/access-tokens) provided in the request, making it very fast.
|
|
55
|
+
|
|
56
|
+
## require_user
|
|
57
|
+
|
|
58
|
+
A dependency that will verify the request was made by a valid user.
|
|
59
|
+
If a valid [access token](https://docs.propelauth.com/guides-and-examples/guides/access-tokens) is provided, it will return a [User](https://docs.propelauth.com/reference/backend-apis/fastapi#user) object.
|
|
60
|
+
If not, the request is rejected with a 401 status code.
|
|
61
|
+
|
|
62
|
+
```py
|
|
63
|
+
from fastapi import FastAPI, Depends
|
|
64
|
+
from propelauth_fastapi import init_auth, User
|
|
65
|
+
|
|
66
|
+
app = FastAPI()
|
|
67
|
+
auth = init_auth("AUTH_URL", "API_KEY")
|
|
68
|
+
|
|
69
|
+
@app.get("/")
|
|
70
|
+
async def root(current_user: User = Depends(auth.require_user)):
|
|
71
|
+
return {"message": f"Hello {current_user.user_id}"}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## optional_user
|
|
75
|
+
|
|
76
|
+
Similar to [require_user](#require-user), but will return `None` if no valid access token is provided.
|
|
77
|
+
|
|
78
|
+
```py
|
|
79
|
+
from typing import Optional
|
|
80
|
+
|
|
81
|
+
from fastapi import FastAPI, Depends
|
|
82
|
+
from propelauth_fastapi import init_auth, User
|
|
83
|
+
|
|
84
|
+
app = FastAPI()
|
|
85
|
+
auth = init_auth("AUTH_URL", "API_KEY")
|
|
86
|
+
|
|
87
|
+
@app.get("/api/whoami_optional")
|
|
88
|
+
async def whoami_optional(current_user: Optional[User] = Depends(auth.optional_user)):
|
|
89
|
+
if current_user:
|
|
90
|
+
return {"user_id": current_user.user_id}
|
|
91
|
+
return {}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
# Authorization / Organizations
|
|
95
|
+
|
|
96
|
+
You can also verify which organizations the user is in, and which roles and permissions they have in each organization all through the [User](https://docs.propelauth.com/reference/backend-apis/fastapi#user) or [OrgMemberInfo](https://docs.propelauth.com/reference/backend-apis/fastapi#org-member-info) objects.
|
|
97
|
+
|
|
98
|
+
## Check Org Membership
|
|
99
|
+
|
|
100
|
+
Verify that the request was made by a valid user **and** that the user is a member of the specified organization. This can be done using the [User](https://docs.propelauth.com/reference/backend-apis/fastapi#user) object.
|
|
101
|
+
|
|
102
|
+
```py
|
|
103
|
+
@app.get("/api/org/{org_id}")
|
|
104
|
+
async def org_membership(org_id: str, current_user: User = Depends(auth.require_user)):
|
|
105
|
+
org = current_user.get_org(org_id)
|
|
106
|
+
if org == None:
|
|
107
|
+
raise HTTPException(status_code=403, detail="Forbidden")
|
|
108
|
+
return f"You are in org {org.org_name}"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Check Org Membership and Role
|
|
112
|
+
|
|
113
|
+
Similar to checking org membership, but will also verify that the user has a specific Role in the organization. This can be done using either the [User](https://docs.propelauth.com/reference/backend-apis/fastapi#user) or [OrgMemberInfo](https://docs.propelauth.com/reference/backend-apis/fastapi#org-member-info) objects.
|
|
114
|
+
|
|
115
|
+
A user has a Role within an organization. By default, the available roles are Owner, Admin, or Member, but these can be configured. These roles are also hierarchical, so Owner > Admin > Member.
|
|
116
|
+
|
|
117
|
+
```py
|
|
118
|
+
## Assuming a Role structure of Owner => Admin => Member
|
|
119
|
+
|
|
120
|
+
@app.get("/api/org/{org_id}")
|
|
121
|
+
def org_owner(org_id: str, current_user: User = Depends(auth.require_user)):
|
|
122
|
+
org = current_user.get_org(org_id)
|
|
123
|
+
if (org == None) or (org.user_is_role("Owner") == False):
|
|
124
|
+
raise HTTPException(status_code=403, detail="Forbidden")
|
|
125
|
+
return f"You are an Owner in org {org.org_name}"
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Check Org Membership and Permission
|
|
129
|
+
|
|
130
|
+
Similar to checking org membership, but will also verify that the user has the specified permission in the organization. This can be done using either the [User](https://docs.propelauth.com/reference/backend-apis/fastapi#user) or [OrgMemberInfo](https://docs.propelauth.com/reference/backend-apis/fastapi#org-member-info) objects.
|
|
131
|
+
|
|
132
|
+
Permissions are arbitrary strings associated with a role. For example, `can_view_billing`, `ProductA::CanCreate`, and `ReadOnly` are all valid permissions.
|
|
133
|
+
You can create these permissions in the PropelAuth dashboard.
|
|
134
|
+
|
|
135
|
+
```py
|
|
136
|
+
@app.get("/api/org/{org_id}")
|
|
137
|
+
def org_billing(org_id: str, current_user: User = Depends(auth.require_user)):
|
|
138
|
+
org = current_user.get_org(org_id)
|
|
139
|
+
if (org == None) or (org.user_has_permission("can_view_billing") == False):
|
|
140
|
+
raise HTTPException(status_code=403, detail="Forbidden")
|
|
141
|
+
return Response(f"You can view billing information for org {org.org_name}")
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Calling Backend APIs
|
|
145
|
+
|
|
146
|
+
You can also use the library to call the PropelAuth APIs directly, allowing you to fetch users, create orgs, and a lot more.
|
|
147
|
+
See the [API Reference](https://docs.propelauth.com/reference) for more information.
|
|
148
|
+
|
|
149
|
+
```py
|
|
150
|
+
from propelauth_fastapi import init_auth
|
|
151
|
+
|
|
152
|
+
auth = init_auth("YOUR_AUTH_URL", "YOUR_API_KEY")
|
|
153
|
+
|
|
154
|
+
magic_link = auth.create_magic_link(email="test@example.com")
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Questions?
|
|
158
|
+
|
|
159
|
+
Feel free to reach out at support@propelauth.com
|
|
160
|
+
|
|
161
|
+
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://www.propelauth.com?ref=github" target="_blank" align="center">
|
|
3
|
+
<img src="https://www.propelauth.com/imgs/lockup.svg" width="200">
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
# PropelAuth FastAPI SDK
|
|
8
|
+
|
|
9
|
+
A FastAPI library for managing authentication, backed by [PropelAuth](https://www.propelauth.com/?utm_campaign=github-fastapi).
|
|
10
|
+
|
|
11
|
+
[PropelAuth](https://www.propelauth.com?ref=github) makes it easy to add authentication and authorization to your B2B/multi-tenant application.
|
|
12
|
+
|
|
13
|
+
Your frontend gets a beautiful, safe, and customizable login screen. Your backend gets easy authorization with just a few lines of code. You get an easy-to-use dashboard to config and manage everything.
|
|
14
|
+
|
|
15
|
+
## Documentation
|
|
16
|
+
|
|
17
|
+
- Full reference this library is [here](https://docs.propelauth.com/reference/backend-apis/fastapi)
|
|
18
|
+
- Getting started guides for PropelAuth are [here](https://docs.propelauth.com/)
|
|
19
|
+
|
|
20
|
+
## Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install propelauth_fastapi
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Initialize
|
|
27
|
+
|
|
28
|
+
`init_auth` performs a one-time initialization of the library.
|
|
29
|
+
It will verify your `api_key` is correct and fetch the metadata needed to verify access tokens in [require_user](#require-user) or [optional_user](#optional-user).
|
|
30
|
+
|
|
31
|
+
```py
|
|
32
|
+
from propelauth_fastapi import init_auth
|
|
33
|
+
|
|
34
|
+
auth = init_auth("YOUR_AUTH_URL", "YOUR_API_KEY")
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
# Protect API Routes
|
|
38
|
+
|
|
39
|
+
Protecting an API route is as simple as adding a [dependency](https://fastapi.tiangolo.com/tutorial/dependencies/) to your route.
|
|
40
|
+
|
|
41
|
+
None of the dependencies make a external request to PropelAuth.
|
|
42
|
+
They all are verified locally using the [access token](https://docs.propelauth.com/guides-and-examples/guides/access-tokens) provided in the request, making it very fast.
|
|
43
|
+
|
|
44
|
+
## require_user
|
|
45
|
+
|
|
46
|
+
A dependency that will verify the request was made by a valid user.
|
|
47
|
+
If a valid [access token](https://docs.propelauth.com/guides-and-examples/guides/access-tokens) is provided, it will return a [User](https://docs.propelauth.com/reference/backend-apis/fastapi#user) object.
|
|
48
|
+
If not, the request is rejected with a 401 status code.
|
|
49
|
+
|
|
50
|
+
```py
|
|
51
|
+
from fastapi import FastAPI, Depends
|
|
52
|
+
from propelauth_fastapi import init_auth, User
|
|
53
|
+
|
|
54
|
+
app = FastAPI()
|
|
55
|
+
auth = init_auth("AUTH_URL", "API_KEY")
|
|
56
|
+
|
|
57
|
+
@app.get("/")
|
|
58
|
+
async def root(current_user: User = Depends(auth.require_user)):
|
|
59
|
+
return {"message": f"Hello {current_user.user_id}"}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## optional_user
|
|
63
|
+
|
|
64
|
+
Similar to [require_user](#require-user), but will return `None` if no valid access token is provided.
|
|
65
|
+
|
|
66
|
+
```py
|
|
67
|
+
from typing import Optional
|
|
68
|
+
|
|
69
|
+
from fastapi import FastAPI, Depends
|
|
70
|
+
from propelauth_fastapi import init_auth, User
|
|
71
|
+
|
|
72
|
+
app = FastAPI()
|
|
73
|
+
auth = init_auth("AUTH_URL", "API_KEY")
|
|
74
|
+
|
|
75
|
+
@app.get("/api/whoami_optional")
|
|
76
|
+
async def whoami_optional(current_user: Optional[User] = Depends(auth.optional_user)):
|
|
77
|
+
if current_user:
|
|
78
|
+
return {"user_id": current_user.user_id}
|
|
79
|
+
return {}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
# Authorization / Organizations
|
|
83
|
+
|
|
84
|
+
You can also verify which organizations the user is in, and which roles and permissions they have in each organization all through the [User](https://docs.propelauth.com/reference/backend-apis/fastapi#user) or [OrgMemberInfo](https://docs.propelauth.com/reference/backend-apis/fastapi#org-member-info) objects.
|
|
85
|
+
|
|
86
|
+
## Check Org Membership
|
|
87
|
+
|
|
88
|
+
Verify that the request was made by a valid user **and** that the user is a member of the specified organization. This can be done using the [User](https://docs.propelauth.com/reference/backend-apis/fastapi#user) object.
|
|
89
|
+
|
|
90
|
+
```py
|
|
91
|
+
@app.get("/api/org/{org_id}")
|
|
92
|
+
async def org_membership(org_id: str, current_user: User = Depends(auth.require_user)):
|
|
93
|
+
org = current_user.get_org(org_id)
|
|
94
|
+
if org == None:
|
|
95
|
+
raise HTTPException(status_code=403, detail="Forbidden")
|
|
96
|
+
return f"You are in org {org.org_name}"
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Check Org Membership and Role
|
|
100
|
+
|
|
101
|
+
Similar to checking org membership, but will also verify that the user has a specific Role in the organization. This can be done using either the [User](https://docs.propelauth.com/reference/backend-apis/fastapi#user) or [OrgMemberInfo](https://docs.propelauth.com/reference/backend-apis/fastapi#org-member-info) objects.
|
|
102
|
+
|
|
103
|
+
A user has a Role within an organization. By default, the available roles are Owner, Admin, or Member, but these can be configured. These roles are also hierarchical, so Owner > Admin > Member.
|
|
104
|
+
|
|
105
|
+
```py
|
|
106
|
+
## Assuming a Role structure of Owner => Admin => Member
|
|
107
|
+
|
|
108
|
+
@app.get("/api/org/{org_id}")
|
|
109
|
+
def org_owner(org_id: str, current_user: User = Depends(auth.require_user)):
|
|
110
|
+
org = current_user.get_org(org_id)
|
|
111
|
+
if (org == None) or (org.user_is_role("Owner") == False):
|
|
112
|
+
raise HTTPException(status_code=403, detail="Forbidden")
|
|
113
|
+
return f"You are an Owner in org {org.org_name}"
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Check Org Membership and Permission
|
|
117
|
+
|
|
118
|
+
Similar to checking org membership, but will also verify that the user has the specified permission in the organization. This can be done using either the [User](https://docs.propelauth.com/reference/backend-apis/fastapi#user) or [OrgMemberInfo](https://docs.propelauth.com/reference/backend-apis/fastapi#org-member-info) objects.
|
|
119
|
+
|
|
120
|
+
Permissions are arbitrary strings associated with a role. For example, `can_view_billing`, `ProductA::CanCreate`, and `ReadOnly` are all valid permissions.
|
|
121
|
+
You can create these permissions in the PropelAuth dashboard.
|
|
122
|
+
|
|
123
|
+
```py
|
|
124
|
+
@app.get("/api/org/{org_id}")
|
|
125
|
+
def org_billing(org_id: str, current_user: User = Depends(auth.require_user)):
|
|
126
|
+
org = current_user.get_org(org_id)
|
|
127
|
+
if (org == None) or (org.user_has_permission("can_view_billing") == False):
|
|
128
|
+
raise HTTPException(status_code=403, detail="Forbidden")
|
|
129
|
+
return Response(f"You can view billing information for org {org.org_name}")
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Calling Backend APIs
|
|
133
|
+
|
|
134
|
+
You can also use the library to call the PropelAuth APIs directly, allowing you to fetch users, create orgs, and a lot more.
|
|
135
|
+
See the [API Reference](https://docs.propelauth.com/reference) for more information.
|
|
136
|
+
|
|
137
|
+
```py
|
|
138
|
+
from propelauth_fastapi import init_auth
|
|
139
|
+
|
|
140
|
+
auth = init_auth("YOUR_AUTH_URL", "YOUR_API_KEY")
|
|
141
|
+
|
|
142
|
+
magic_link = auth.create_magic_link(email="test@example.com")
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
## Questions?
|
|
146
|
+
|
|
147
|
+
Feel free to reach out at support@propelauth.com
|
|
@@ -2,7 +2,14 @@ from typing import Any, Dict, List, Optional
|
|
|
2
2
|
|
|
3
3
|
from fastapi import Depends, HTTPException, Header
|
|
4
4
|
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
|
5
|
-
from propelauth_py import
|
|
5
|
+
from propelauth_py import (
|
|
6
|
+
TokenVerificationMetadata,
|
|
7
|
+
init_base_auth,
|
|
8
|
+
Auth,
|
|
9
|
+
SamlIdpMetadata,
|
|
10
|
+
StepUpMfaGrantType,
|
|
11
|
+
StepUpMfaVerifyTotpResponse,
|
|
12
|
+
)
|
|
6
13
|
from propelauth_py.errors import ForbiddenException, UnauthorizedException
|
|
7
14
|
from propelauth_py.user import User
|
|
8
15
|
|
|
@@ -237,9 +244,10 @@ class FastAPIAuth:
|
|
|
237
244
|
properties: Optional[Dict[str, Any]] = None,
|
|
238
245
|
picture_url: Optional[str] = None,
|
|
239
246
|
update_password_required: Optional[bool] = None,
|
|
247
|
+
legacy_user_id: Optional[str] = None,
|
|
240
248
|
):
|
|
241
249
|
return self.auth.update_user_metadata(
|
|
242
|
-
user_id, username, first_name, last_name, metadata, properties, picture_url, update_password_required
|
|
250
|
+
user_id, username, first_name, last_name, metadata, properties, picture_url, update_password_required, legacy_user_id
|
|
243
251
|
)
|
|
244
252
|
|
|
245
253
|
def clear_user_password(self, user_id: str):
|
|
@@ -260,8 +268,8 @@ class FastAPIAuth:
|
|
|
260
268
|
email, redirect_to_url, expires_in_hours, create_new_user_if_one_doesnt_exist, user_signup_query_parameters
|
|
261
269
|
)
|
|
262
270
|
|
|
263
|
-
def create_access_token(self, user_id: str, duration_in_minutes: int):
|
|
264
|
-
return self.auth.create_access_token(user_id, duration_in_minutes)
|
|
271
|
+
def create_access_token(self, user_id: str, duration_in_minutes: int, active_org_id: Optional[str] = None):
|
|
272
|
+
return self.auth.create_access_token(user_id, duration_in_minutes, active_org_id)
|
|
265
273
|
|
|
266
274
|
def migrate_user_from_external_source(
|
|
267
275
|
self,
|
|
@@ -283,6 +291,13 @@ class FastAPIAuth:
|
|
|
283
291
|
existing_mfa_base32_encoded_secret, ask_user_to_update_password_on_login,
|
|
284
292
|
enabled, first_name, last_name, username, picture_url, properties
|
|
285
293
|
)
|
|
294
|
+
|
|
295
|
+
def migrate_user_password(
|
|
296
|
+
self,
|
|
297
|
+
user_id: str,
|
|
298
|
+
password_hash: str,
|
|
299
|
+
):
|
|
300
|
+
return self.auth.migrate_user_password(user_id, password_hash)
|
|
286
301
|
|
|
287
302
|
def create_org(
|
|
288
303
|
self,
|
|
@@ -309,10 +324,12 @@ class FastAPIAuth:
|
|
|
309
324
|
can_join_on_email_domain_match: Optional[bool] = None,
|
|
310
325
|
members_must_have_email_domain_match: Optional[bool] = None,
|
|
311
326
|
domain: Optional[str] = None,
|
|
327
|
+
require_2fa_by: Optional[str] = None,
|
|
328
|
+
extra_domains: Optional[List[str]] = None,
|
|
312
329
|
):
|
|
313
330
|
return self.auth.update_org_metadata(
|
|
314
331
|
org_id, name, can_setup_saml, metadata, max_users,
|
|
315
|
-
can_join_on_email_domain_match, members_must_have_email_domain_match, domain
|
|
332
|
+
can_join_on_email_domain_match, members_must_have_email_domain_match, domain, require_2fa_by, extra_domains
|
|
316
333
|
)
|
|
317
334
|
|
|
318
335
|
def subscribe_org_to_role_mapping(self, org_id: str, custom_role_mapping_name: str):
|
|
@@ -422,6 +439,21 @@ class FastAPIAuth:
|
|
|
422
439
|
def delete_saml_connection(self, org_id: str):
|
|
423
440
|
return self.auth.delete_saml_connection(org_id)
|
|
424
441
|
|
|
442
|
+
def verify_step_up_totp_challenge(
|
|
443
|
+
self,
|
|
444
|
+
action_type: str,
|
|
445
|
+
user_id: str,
|
|
446
|
+
code: str,
|
|
447
|
+
grant_type: StepUpMfaGrantType,
|
|
448
|
+
valid_for_seconds: int,
|
|
449
|
+
) -> StepUpMfaVerifyTotpResponse:
|
|
450
|
+
return self.auth.verify_step_up_totp_challenge(
|
|
451
|
+
action_type, user_id, code, grant_type, valid_for_seconds
|
|
452
|
+
)
|
|
453
|
+
|
|
454
|
+
def verify_step_up_grant(self, action_type: str, user_id: str, grant: str) -> bool:
|
|
455
|
+
return self.auth.verify_step_up_grant(action_type, user_id, grant)
|
|
456
|
+
|
|
425
457
|
def init_auth(
|
|
426
458
|
auth_url: str,
|
|
427
459
|
api_key: str,
|
|
@@ -430,4 +462,4 @@ def init_auth(
|
|
|
430
462
|
) -> FastAPIAuth:
|
|
431
463
|
"""Fetches metadata required to validate access tokens and returns auth decorators and utilities"""
|
|
432
464
|
return FastAPIAuth(auth_url=auth_url, integration_api_key=api_key, token_verification_metadata=token_verification_metadata, debug_mode=debug_mode)
|
|
433
|
-
|
|
465
|
+
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: propelauth-fastapi
|
|
3
|
+
Version: 4.2.6
|
|
4
|
+
Summary: A FastAPI library for managing authentication, backed by PropelAuth
|
|
5
|
+
Home-page: https://github.com/propelauth/propelauth-fastapi
|
|
6
|
+
Author: PropelAuth
|
|
7
|
+
Author-email: support@propelauth.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Platform: UNKNOWN
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="https://www.propelauth.com?ref=github" target="_blank" align="center">
|
|
15
|
+
<img src="https://www.propelauth.com/imgs/lockup.svg" width="200">
|
|
16
|
+
</a>
|
|
17
|
+
</p>
|
|
18
|
+
|
|
19
|
+
# PropelAuth FastAPI SDK
|
|
20
|
+
|
|
21
|
+
A FastAPI library for managing authentication, backed by [PropelAuth](https://www.propelauth.com/?utm_campaign=github-fastapi).
|
|
22
|
+
|
|
23
|
+
[PropelAuth](https://www.propelauth.com?ref=github) makes it easy to add authentication and authorization to your B2B/multi-tenant application.
|
|
24
|
+
|
|
25
|
+
Your frontend gets a beautiful, safe, and customizable login screen. Your backend gets easy authorization with just a few lines of code. You get an easy-to-use dashboard to config and manage everything.
|
|
26
|
+
|
|
27
|
+
## Documentation
|
|
28
|
+
|
|
29
|
+
- Full reference this library is [here](https://docs.propelauth.com/reference/backend-apis/fastapi)
|
|
30
|
+
- Getting started guides for PropelAuth are [here](https://docs.propelauth.com/)
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install propelauth_fastapi
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Initialize
|
|
39
|
+
|
|
40
|
+
`init_auth` performs a one-time initialization of the library.
|
|
41
|
+
It will verify your `api_key` is correct and fetch the metadata needed to verify access tokens in [require_user](#require-user) or [optional_user](#optional-user).
|
|
42
|
+
|
|
43
|
+
```py
|
|
44
|
+
from propelauth_fastapi import init_auth
|
|
45
|
+
|
|
46
|
+
auth = init_auth("YOUR_AUTH_URL", "YOUR_API_KEY")
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
# Protect API Routes
|
|
50
|
+
|
|
51
|
+
Protecting an API route is as simple as adding a [dependency](https://fastapi.tiangolo.com/tutorial/dependencies/) to your route.
|
|
52
|
+
|
|
53
|
+
None of the dependencies make a external request to PropelAuth.
|
|
54
|
+
They all are verified locally using the [access token](https://docs.propelauth.com/guides-and-examples/guides/access-tokens) provided in the request, making it very fast.
|
|
55
|
+
|
|
56
|
+
## require_user
|
|
57
|
+
|
|
58
|
+
A dependency that will verify the request was made by a valid user.
|
|
59
|
+
If a valid [access token](https://docs.propelauth.com/guides-and-examples/guides/access-tokens) is provided, it will return a [User](https://docs.propelauth.com/reference/backend-apis/fastapi#user) object.
|
|
60
|
+
If not, the request is rejected with a 401 status code.
|
|
61
|
+
|
|
62
|
+
```py
|
|
63
|
+
from fastapi import FastAPI, Depends
|
|
64
|
+
from propelauth_fastapi import init_auth, User
|
|
65
|
+
|
|
66
|
+
app = FastAPI()
|
|
67
|
+
auth = init_auth("AUTH_URL", "API_KEY")
|
|
68
|
+
|
|
69
|
+
@app.get("/")
|
|
70
|
+
async def root(current_user: User = Depends(auth.require_user)):
|
|
71
|
+
return {"message": f"Hello {current_user.user_id}"}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## optional_user
|
|
75
|
+
|
|
76
|
+
Similar to [require_user](#require-user), but will return `None` if no valid access token is provided.
|
|
77
|
+
|
|
78
|
+
```py
|
|
79
|
+
from typing import Optional
|
|
80
|
+
|
|
81
|
+
from fastapi import FastAPI, Depends
|
|
82
|
+
from propelauth_fastapi import init_auth, User
|
|
83
|
+
|
|
84
|
+
app = FastAPI()
|
|
85
|
+
auth = init_auth("AUTH_URL", "API_KEY")
|
|
86
|
+
|
|
87
|
+
@app.get("/api/whoami_optional")
|
|
88
|
+
async def whoami_optional(current_user: Optional[User] = Depends(auth.optional_user)):
|
|
89
|
+
if current_user:
|
|
90
|
+
return {"user_id": current_user.user_id}
|
|
91
|
+
return {}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
# Authorization / Organizations
|
|
95
|
+
|
|
96
|
+
You can also verify which organizations the user is in, and which roles and permissions they have in each organization all through the [User](https://docs.propelauth.com/reference/backend-apis/fastapi#user) or [OrgMemberInfo](https://docs.propelauth.com/reference/backend-apis/fastapi#org-member-info) objects.
|
|
97
|
+
|
|
98
|
+
## Check Org Membership
|
|
99
|
+
|
|
100
|
+
Verify that the request was made by a valid user **and** that the user is a member of the specified organization. This can be done using the [User](https://docs.propelauth.com/reference/backend-apis/fastapi#user) object.
|
|
101
|
+
|
|
102
|
+
```py
|
|
103
|
+
@app.get("/api/org/{org_id}")
|
|
104
|
+
async def org_membership(org_id: str, current_user: User = Depends(auth.require_user)):
|
|
105
|
+
org = current_user.get_org(org_id)
|
|
106
|
+
if org == None:
|
|
107
|
+
raise HTTPException(status_code=403, detail="Forbidden")
|
|
108
|
+
return f"You are in org {org.org_name}"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## Check Org Membership and Role
|
|
112
|
+
|
|
113
|
+
Similar to checking org membership, but will also verify that the user has a specific Role in the organization. This can be done using either the [User](https://docs.propelauth.com/reference/backend-apis/fastapi#user) or [OrgMemberInfo](https://docs.propelauth.com/reference/backend-apis/fastapi#org-member-info) objects.
|
|
114
|
+
|
|
115
|
+
A user has a Role within an organization. By default, the available roles are Owner, Admin, or Member, but these can be configured. These roles are also hierarchical, so Owner > Admin > Member.
|
|
116
|
+
|
|
117
|
+
```py
|
|
118
|
+
## Assuming a Role structure of Owner => Admin => Member
|
|
119
|
+
|
|
120
|
+
@app.get("/api/org/{org_id}")
|
|
121
|
+
def org_owner(org_id: str, current_user: User = Depends(auth.require_user)):
|
|
122
|
+
org = current_user.get_org(org_id)
|
|
123
|
+
if (org == None) or (org.user_is_role("Owner") == False):
|
|
124
|
+
raise HTTPException(status_code=403, detail="Forbidden")
|
|
125
|
+
return f"You are an Owner in org {org.org_name}"
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## Check Org Membership and Permission
|
|
129
|
+
|
|
130
|
+
Similar to checking org membership, but will also verify that the user has the specified permission in the organization. This can be done using either the [User](https://docs.propelauth.com/reference/backend-apis/fastapi#user) or [OrgMemberInfo](https://docs.propelauth.com/reference/backend-apis/fastapi#org-member-info) objects.
|
|
131
|
+
|
|
132
|
+
Permissions are arbitrary strings associated with a role. For example, `can_view_billing`, `ProductA::CanCreate`, and `ReadOnly` are all valid permissions.
|
|
133
|
+
You can create these permissions in the PropelAuth dashboard.
|
|
134
|
+
|
|
135
|
+
```py
|
|
136
|
+
@app.get("/api/org/{org_id}")
|
|
137
|
+
def org_billing(org_id: str, current_user: User = Depends(auth.require_user)):
|
|
138
|
+
org = current_user.get_org(org_id)
|
|
139
|
+
if (org == None) or (org.user_has_permission("can_view_billing") == False):
|
|
140
|
+
raise HTTPException(status_code=403, detail="Forbidden")
|
|
141
|
+
return Response(f"You can view billing information for org {org.org_name}")
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Calling Backend APIs
|
|
145
|
+
|
|
146
|
+
You can also use the library to call the PropelAuth APIs directly, allowing you to fetch users, create orgs, and a lot more.
|
|
147
|
+
See the [API Reference](https://docs.propelauth.com/reference) for more information.
|
|
148
|
+
|
|
149
|
+
```py
|
|
150
|
+
from propelauth_fastapi import init_auth
|
|
151
|
+
|
|
152
|
+
auth = init_auth("YOUR_AUTH_URL", "YOUR_API_KEY")
|
|
153
|
+
|
|
154
|
+
magic_link = auth.create_magic_link(email="test@example.com")
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
## Questions?
|
|
158
|
+
|
|
159
|
+
Feel free to reach out at support@propelauth.com
|
|
160
|
+
|
|
161
|
+
|
|
@@ -12,7 +12,7 @@ pytest_runner = ["pytest-runner"] if needs_pytest else []
|
|
|
12
12
|
|
|
13
13
|
setup(
|
|
14
14
|
name="propelauth-fastapi",
|
|
15
|
-
version="4.2.
|
|
15
|
+
version="4.2.6",
|
|
16
16
|
description="A FastAPI library for managing authentication, backed by PropelAuth",
|
|
17
17
|
long_description=README,
|
|
18
18
|
long_description_content_type="text/markdown",
|
|
@@ -21,7 +21,7 @@ setup(
|
|
|
21
21
|
author="PropelAuth",
|
|
22
22
|
author_email="support@propelauth.com",
|
|
23
23
|
license="MIT",
|
|
24
|
-
install_requires=["propelauth-py==4.2.
|
|
24
|
+
install_requires=["propelauth-py==4.2.6", "requests"],
|
|
25
25
|
setup_requires=pytest_runner,
|
|
26
26
|
tests_require=["pytest==4.4.1"],
|
|
27
27
|
test_suite="tests",
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: propelauth-fastapi
|
|
3
|
-
Version: 4.2.3
|
|
4
|
-
Summary: A FastAPI library for managing authentication, backed by PropelAuth
|
|
5
|
-
Home-page: https://github.com/propelauth/propelauth-fastapi
|
|
6
|
-
Author: PropelAuth
|
|
7
|
-
Author-email: support@propelauth.com
|
|
8
|
-
License: MIT
|
|
9
|
-
Platform: UNKNOWN
|
|
10
|
-
Description-Content-Type: text/markdown
|
|
11
|
-
License-File: LICENSE
|
|
12
|
-
|
|
13
|
-
# PropelAuth FastAPI SDK
|
|
14
|
-
|
|
15
|
-
<p align="center">
|
|
16
|
-
<a href="https://www.propelauth.com/?utm_campaign=github-fastapi" target="_blank" align="center">
|
|
17
|
-
<img src="https://propelauth-logos.s3.us-west-2.amazonaws.com/logo-only.png" width="100">
|
|
18
|
-
</a>
|
|
19
|
-
</p>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
A FastAPI library for managing authentication, backed by [PropelAuth](https://www.propelauth.com/?utm_campaign=github-fastapi).
|
|
23
|
-
|
|
24
|
-
[PropelAuth](https://www.propelauth.com?ref=github) makes it easy to add authentication and authorization to your B2B/multi-tenant application.
|
|
25
|
-
|
|
26
|
-
Your frontend gets a beautiful, safe, and customizable login screen. Your backend gets easy authorization with just a few lines of code. You get an easy-to-use dashboard to config and manage everything.
|
|
27
|
-
|
|
28
|
-
## Documentation
|
|
29
|
-
|
|
30
|
-
- Full reference this library is [here](https://docs.propelauth.com/reference/backend-apis/fastapi)
|
|
31
|
-
- Getting started guides for PropelAuth are [here](https://docs.propelauth.com/)
|
|
32
|
-
|
|
33
|
-
## Questions?
|
|
34
|
-
|
|
35
|
-
Feel free to reach out at support@propelauth.com
|
|
36
|
-
|
|
37
|
-
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
# PropelAuth FastAPI SDK
|
|
2
|
-
|
|
3
|
-
<p align="center">
|
|
4
|
-
<a href="https://www.propelauth.com/?utm_campaign=github-fastapi" target="_blank" align="center">
|
|
5
|
-
<img src="https://propelauth-logos.s3.us-west-2.amazonaws.com/logo-only.png" width="100">
|
|
6
|
-
</a>
|
|
7
|
-
</p>
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
A FastAPI library for managing authentication, backed by [PropelAuth](https://www.propelauth.com/?utm_campaign=github-fastapi).
|
|
11
|
-
|
|
12
|
-
[PropelAuth](https://www.propelauth.com?ref=github) makes it easy to add authentication and authorization to your B2B/multi-tenant application.
|
|
13
|
-
|
|
14
|
-
Your frontend gets a beautiful, safe, and customizable login screen. Your backend gets easy authorization with just a few lines of code. You get an easy-to-use dashboard to config and manage everything.
|
|
15
|
-
|
|
16
|
-
## Documentation
|
|
17
|
-
|
|
18
|
-
- Full reference this library is [here](https://docs.propelauth.com/reference/backend-apis/fastapi)
|
|
19
|
-
- Getting started guides for PropelAuth are [here](https://docs.propelauth.com/)
|
|
20
|
-
|
|
21
|
-
## Questions?
|
|
22
|
-
|
|
23
|
-
Feel free to reach out at support@propelauth.com
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: propelauth-fastapi
|
|
3
|
-
Version: 4.2.3
|
|
4
|
-
Summary: A FastAPI library for managing authentication, backed by PropelAuth
|
|
5
|
-
Home-page: https://github.com/propelauth/propelauth-fastapi
|
|
6
|
-
Author: PropelAuth
|
|
7
|
-
Author-email: support@propelauth.com
|
|
8
|
-
License: MIT
|
|
9
|
-
Platform: UNKNOWN
|
|
10
|
-
Description-Content-Type: text/markdown
|
|
11
|
-
License-File: LICENSE
|
|
12
|
-
|
|
13
|
-
# PropelAuth FastAPI SDK
|
|
14
|
-
|
|
15
|
-
<p align="center">
|
|
16
|
-
<a href="https://www.propelauth.com/?utm_campaign=github-fastapi" target="_blank" align="center">
|
|
17
|
-
<img src="https://propelauth-logos.s3.us-west-2.amazonaws.com/logo-only.png" width="100">
|
|
18
|
-
</a>
|
|
19
|
-
</p>
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
A FastAPI library for managing authentication, backed by [PropelAuth](https://www.propelauth.com/?utm_campaign=github-fastapi).
|
|
23
|
-
|
|
24
|
-
[PropelAuth](https://www.propelauth.com?ref=github) makes it easy to add authentication and authorization to your B2B/multi-tenant application.
|
|
25
|
-
|
|
26
|
-
Your frontend gets a beautiful, safe, and customizable login screen. Your backend gets easy authorization with just a few lines of code. You get an easy-to-use dashboard to config and manage everything.
|
|
27
|
-
|
|
28
|
-
## Documentation
|
|
29
|
-
|
|
30
|
-
- Full reference this library is [here](https://docs.propelauth.com/reference/backend-apis/fastapi)
|
|
31
|
-
- Getting started guides for PropelAuth are [here](https://docs.propelauth.com/)
|
|
32
|
-
|
|
33
|
-
## Questions?
|
|
34
|
-
|
|
35
|
-
Feel free to reach out at support@propelauth.com
|
|
36
|
-
|
|
37
|
-
|
|
File without changes
|
{propelauth-fastapi-4.2.3 → propelauth-fastapi-4.2.6}/propelauth_fastapi.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{propelauth-fastapi-4.2.3 → propelauth-fastapi-4.2.6}/propelauth_fastapi.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|