File tree Expand file tree Collapse file tree 2 files changed +12
-16
lines changed Expand file tree Collapse file tree 2 files changed +12
-16
lines changed Original file line number Diff line number Diff line change 1
1
import json
2
+ import os
2
3
4
+ from dotenv import load_dotenv
3
5
from fastapi import FastAPI , Request , APIRouter
4
6
from fastapi .responses import HTMLResponse
5
7
from fastapi .templating import Jinja2Templates
10
12
from fastapi_oauth2 .middleware import OAuth2Middleware
11
13
from fastapi_oauth2 .router import router as oauth2_router
12
14
15
+ load_dotenv ()
13
16
router = APIRouter ()
14
17
templates = Jinja2Templates (directory = "templates" )
15
18
@@ -25,12 +28,15 @@ async def root(request: Request):
25
28
app .include_router (oauth2_router )
26
29
app .add_middleware (OAuth2Middleware , config = {
27
30
"allow_http" : True ,
31
+ "jwt_secret" : os .getenv ("JWT_SECRET" ),
32
+ "jwt_expires" : os .getenv ("JWT_EXPIRES" ),
33
+ "jwt_algorithm" : os .getenv ("JWT_ALGORITHM" ),
28
34
"clients" : [
29
35
OAuth2Client (
30
36
backend = GithubOAuth2 ,
31
- client_id = "eccd08d6736b7999a32a" ,
32
- client_secret = "642999c1c5f2b3df8b877afdc78252ef5b594d31" ,
33
- redirect_uri = "http://127.0.0.1:8000/" ,
37
+ client_id = os . getenv ( "OAUTH2_CLIENT_ID" ) ,
38
+ client_secret = os . getenv ( "OAUTH2_CLIENT_SECRET" ) ,
39
+ # redirect_uri="http://127.0.0.1:8000/",
34
40
scope = ["user:email" ],
35
41
),
36
42
]
Original file line number Diff line number Diff line change 1
1
import os
2
2
from typing import List
3
3
4
- from dotenv import load_dotenv
5
-
6
4
from .client import OAuth2Client
7
5
8
- load_dotenv ()
9
-
10
- OAUTH2_CLIENT_ID = os .getenv ("OAUTH2_CLIENT_ID" )
11
- OAUTH2_CLIENT_SECRET = os .getenv ("OAUTH2_CLIENT_SECRET" )
12
- OAUTH2_CALLBACK_URL = os .getenv ("OAUTH2_CALLBACK_URL" )
13
-
14
- JWT_SECRET = os .getenv ("JWT_SECRET" )
15
- JWT_ALGORITHM = os .getenv ("JWT_ALGORITHM" )
16
- JWT_EXPIRES = int (os .getenv ("JWT_EXPIRES" , "15" ))
17
-
18
6
19
7
class OAuth2Config :
20
8
allow_http : bool
@@ -32,8 +20,10 @@ def __init__(
32
20
jwt_algorithm : str = "HS256" ,
33
21
clients : List [OAuth2Client ] = None ,
34
22
):
23
+ if allow_http :
24
+ os .environ ["OAUTHLIB_INSECURE_TRANSPORT" ] = "1"
35
25
self .allow_http = allow_http
36
26
self .jwt_secret = jwt_secret
37
- self .jwt_expires = jwt_expires
27
+ self .jwt_expires = int ( jwt_expires )
38
28
self .jwt_algorithm = jwt_algorithm
39
29
self .clients = clients or []
You can’t perform that action at this time.
0 commit comments