-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement PKCE support and API compatibility (GH-21)
- Loading branch information
Showing
25 changed files
with
425 additions
and
227 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from fastapi import APIRouter | ||
from fastapi import Request | ||
from fastapi.templating import Jinja2Templates | ||
from starlette.responses import RedirectResponse | ||
|
||
from fastapi_oauth2.security import OAuth2 | ||
|
||
oauth2 = OAuth2() | ||
router_api = APIRouter() | ||
templates = Jinja2Templates(directory="templates") | ||
|
||
|
||
@router_api.get("/auth") | ||
def sim_auth(request: Request): | ||
access_token = request.auth.jwt_create({ | ||
"id": 1, | ||
"identity": "demo:1", | ||
"image": None, | ||
"display_name": "John Doe", | ||
"email": "[email protected]", | ||
"username": "JohnDoe", | ||
"exp": 3689609839, | ||
}) | ||
response = RedirectResponse("/") | ||
response.set_cookie( | ||
"Authorization", | ||
value=f"Bearer {access_token}", | ||
max_age=request.auth.expires, | ||
expires=request.auth.expires, | ||
httponly=request.auth.http, | ||
) | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import json | ||
|
||
from fastapi import APIRouter | ||
from fastapi import Depends | ||
from fastapi import Request | ||
from fastapi.responses import HTMLResponse | ||
from fastapi.templating import Jinja2Templates | ||
from sqlalchemy.orm import Session | ||
|
||
from database import get_db | ||
from fastapi_oauth2.security import OAuth2 | ||
from models import User | ||
|
||
oauth2 = OAuth2() | ||
router_ssr = APIRouter() | ||
templates = Jinja2Templates(directory="templates") | ||
|
||
|
||
@router_ssr.get("/", response_class=HTMLResponse) | ||
async def root(request: Request): | ||
return templates.TemplateResponse("index.html", { | ||
"json": json, | ||
"request": request, | ||
}) | ||
|
||
|
||
@router_ssr.get("/users", response_class=HTMLResponse) | ||
async def users(request: Request, db: Session = Depends(get_db), _: str = Depends(oauth2)): | ||
return templates.TemplateResponse("users.html", { | ||
"json": json, | ||
"request": request, | ||
"users": [ | ||
dict([(k, v) for k, v in user.__dict__.items() if not k.startswith("_")]) for user in db.query(User).all() | ||
], | ||
}) |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{% extends "base.html" %} | ||
|
||
{% block content %} | ||
<p>This is the current list of all users. See <a style="color: #009486;" href="/">JWT</a> content.</p> | ||
<div style="padding: 8px 16px; background: #161618; border-radius: 6px;"> | ||
<pre style="max-width: 500px; white-space: pre-wrap;">{{ json.dumps(users, indent=4) }}</pre> | ||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "1.0.0-beta" | ||
__version__ = "1.0.0-beta.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.