-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
30 lines (21 loc) · 734 Bytes
/
Copy pathmain.py
File metadata and controls
30 lines (21 loc) · 734 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
import os
from fastapi import Depends, FastAPI, Request
from authdog.fastapi import Authdog
public_key = os.environ.get("PK_AUTHDOG")
if not public_key:
raise SystemExit("Set PK_AUTHDOG to your environment public key (pk_...)")
authdog = Authdog(public_key=public_key)
app = FastAPI()
@app.get("/")
async def index(ctx=Depends(authdog.session)):
return {
"sample": "authdog authn on python",
"authenticated": ctx.is_authenticated,
"hint": "GET /me with an authdog-session cookie or Authorization: Bearer <token>",
}
@app.get("/me")
async def me(user=Depends(authdog.require_auth)):
return user
@app.get("/logout")
async def logout(request: Request):
return authdog.logout(request)