Skip to content

Commit 42308d0

Browse files
committed
GH-4: Move the demo app to examples dir
1 parent 1f3248a commit 42308d0

File tree

7 files changed

+50
-139
lines changed

7 files changed

+50
-139
lines changed

demo/dependencies.py

Lines changed: 0 additions & 39 deletions
This file was deleted.

demo/router.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

.env renamed to examples/demonstration/.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
OAUTH2_CLIENT_ID=eccd08d6736b7999a32a
22
OAUTH2_CLIENT_SECRET=642999c1c5f2b3df8b877afdc78252ef5b594d31
3-
OAUTH2_CALLBACK_URL=http://127.0.0.1:8000/oauth2/token
43

54
JWT_SECRET=secret
65
JWT_ALGORITHM=HS256

examples/demonstration/main.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from fastapi import FastAPI, APIRouter
2+
3+
from config import oauth2_config
4+
from fastapi_oauth2.middleware import OAuth2Middleware
5+
from fastapi_oauth2.router import router as oauth2_router
6+
from router import router as app_router
7+
8+
router = APIRouter()
9+
10+
app = FastAPI()
11+
app.include_router(app_router)
12+
app.include_router(oauth2_router)
13+
app.add_middleware(OAuth2Middleware, config=oauth2_config)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport"
6+
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<title>OAuth2 Demo</title>
9+
</head>
10+
<body style="margin: 0; display: flex; flex-direction: column; background: #1e1e20; color: #dfdfd6; font-family: sans-serif;">
11+
<header style="display: flex; background: #161618; height: 70px; width: 100%;">
12+
<div style="display: flex; align-items: center; margin: auto 50px auto auto;">
13+
{% if request.user.is_authenticated %}
14+
<a href="/oauth2/logout" style="text-decoration: none; color: #dfdfd6; margin-right: 20px;">Sign out</a>
15+
<img style="height: 50px; width: 50px;" src="{{ request.user.avatar_url }}" alt="Pic">
16+
{% else %}
17+
<a href="/oauth2/github/auth" style="display: flex; align-items: center;">
18+
<svg style="height: 50px; width: 50px;" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
19+
<path fill="#dfdfd6" d="M7.499,1C3.91,1,1,3.906,1,7.49c0,2.867,1.862,5.299,4.445,6.158C5.77,13.707,6,13.375,6,13.125 c0-0.154,0.003-0.334,0-0.875c-1.808,0.392-2.375-0.875-2.375-0.875c-0.296-0.75-0.656-0.963-0.656-0.963 c-0.59-0.403,0.044-0.394,0.044-0.394C3.666,10.064,4,10.625,4,10.625c0.5,0.875,1.63,0.791,2,0.625 c0-0.397,0.044-0.688,0.154-0.873C4.111,10.02,2.997,8.84,3,7.208c0.002-0.964,0.335-1.715,0.876-2.269 C3.639,4.641,3.479,3.625,3.961,3c1.206,0,1.927,0.873,1.927,0.873s0.565-0.248,1.61-0.248c1.045,0,1.608,0.234,1.608,0.234 S9.829,3,11.035,3c0.482,0.625,0.322,1.641,0.132,1.918C11.684,5.461,12,6.21,12,7.208c0,1.631-1.11,2.81-3.148,3.168 C8.982,10.572,9,10.842,9,11.25c0,0.867,0,1.662,0,1.875c0,0.25,0.228,0.585,0.558,0.522C12.139,12.787,14,10.356,14,7.49 C14,3.906,11.09,1,7.499,1z"></path>
20+
</svg>
21+
</a>
22+
{% endif %}
23+
</div>
24+
</header>
25+
<section
26+
style="display: flex; flex-direction: column; align-items: center; justify-content: center; height: calc(100vh - 70px);">
27+
{% if request.user.is_authenticated %}
28+
<h1>Hi, {{ request.user.name }}</h1>
29+
<p>This is what your JWT contains currently</p>
30+
<pre>{{ json.dumps(request.user, indent=4) }}</pre>
31+
{% else %}
32+
<h1>You are not authenticated</h1>
33+
<p>You should sign in by clicking the GitHub's icon</p>
34+
{% endif %}
35+
</section>
36+
</body>
37+
</html>

main.py

Lines changed: 0 additions & 43 deletions
This file was deleted.

templates/index.html

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)