forked from frontegg/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-fast-api.py
53 lines (41 loc) · 1.15 KB
/
test-fast-api.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import uvicorn
from fastapi import FastAPI, Depends
from fastapi.middleware.cors import CORSMiddleware
from frontegg.fastapi import frontegg
from frontegg.fastapi.secure_access import FronteggSecurity, User
app = FastAPI()
origins = [
"http://localhost:3000",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
client_id = 'my-client-id'
api_key = 'my-api-key'
# options = {
# "access_tokens_options": {
# "cache": {
# "type": "redis",
# "options": {
# "host": "localhost",
# "port": 6379,
# "password": "",
# "db": 10,
# },
# },
# }
# }
@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
async def startup_event():
await frontegg.init_app(client_id=client_id, api_key=api_key)
app.add_event_handler("startup", startup_event)
uvicorn.run(app, port=8080)