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 11import json
2+ import os
23
4+ from dotenv import load_dotenv
35from fastapi import FastAPI , Request , APIRouter
46from fastapi .responses import HTMLResponse
57from fastapi .templating import Jinja2Templates
1012from fastapi_oauth2 .middleware import OAuth2Middleware
1113from fastapi_oauth2 .router import router as oauth2_router
1214
15+ load_dotenv ()
1316router = APIRouter ()
1417templates = Jinja2Templates (directory = "templates" )
1518
@@ -25,12 +28,15 @@ async def root(request: Request):
2528app .include_router (oauth2_router )
2629app .add_middleware (OAuth2Middleware , config = {
2730 "allow_http" : True ,
31+ "jwt_secret" : os .getenv ("JWT_SECRET" ),
32+ "jwt_expires" : os .getenv ("JWT_EXPIRES" ),
33+ "jwt_algorithm" : os .getenv ("JWT_ALGORITHM" ),
2834 "clients" : [
2935 OAuth2Client (
3036 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/",
3440 scope = ["user:email" ],
3541 ),
3642 ]
Original file line number Diff line number Diff line change 11import os
22from typing import List
33
4- from dotenv import load_dotenv
5-
64from .client import OAuth2Client
75
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-
186
197class OAuth2Config :
208 allow_http : bool
@@ -32,8 +20,10 @@ def __init__(
3220 jwt_algorithm : str = "HS256" ,
3321 clients : List [OAuth2Client ] = None ,
3422 ):
23+ if allow_http :
24+ os .environ ["OAUTHLIB_INSECURE_TRANSPORT" ] = "1"
3525 self .allow_http = allow_http
3626 self .jwt_secret = jwt_secret
37- self .jwt_expires = jwt_expires
27+ self .jwt_expires = int ( jwt_expires )
3828 self .jwt_algorithm = jwt_algorithm
3929 self .clients = clients or []
You can’t perform that action at this time.
0 commit comments