forked from frontegg/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-fast-api.py
More file actions
36 lines (26 loc) · 786 Bytes
/
test-fast-api.py
File metadata and controls
36 lines (26 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from frontegg.fastapi import frontegg
from frontegg.fastapi.secure_access import FronteggSecurity, User
from fastapi import FastAPI, Depends
from fastapi.middleware.cors import CORSMiddleware
import uvicorn
app = FastAPI()
client_id = 'my-client-id'
api_key = 'my-api-key'
frontegg.init_app(client_id=client_id, api_key=api_key)
origins = [
"http://localhost:3000",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
def read_root(user: User = Depends(FronteggSecurity())) -> User:
return user
@app.get("/authorized")
def read_root(user: User = Depends(FronteggSecurity(permissions=['my-permission']))) -> User:
return user
uvicorn.run(app, port=8080)