1414if ENV_FILE :
1515 load_dotenv (ENV_FILE )
1616
17- app = Flask (__name__ , static_url_path = "/public" , static_folder = "./public" )
17+ app = Flask (__name__ )
1818app .secret_key = env .get ("APP_SECRET_KEY" )
19- app .debug = True
2019
2120
2221@app .errorhandler (Exception )
@@ -33,13 +32,9 @@ def fetch_token(name, request):
3332
3433oauth = OAuth (app )
3534
36- auth0 = oauth .register (
35+ oauth .register (
3736 "auth0" ,
3837 client_id = env .get ("AUTH0_CLIENT_ID" ),
39- client_secret = env .get ("AUTH0_CLIENT_SECRET" ),
40- api_base_url = "https://" + env .get ("AUTH0_DOMAIN" ),
41- access_token_url = "https://" + env .get ("AUTH0_DOMAIN" ) + "/oauth/token" ,
42- authorize_url = "https://" + env .get ("AUTH0_DOMAIN" ) + "/authorize" ,
4338 client_kwargs = {
4439 "scope" : "openid profile email" ,
4540 },
@@ -53,43 +48,28 @@ def fetch_token(name, request):
5348# Controllers API
5449@app .route ("/" )
5550def home ():
56- if "profile" in session :
57- return render_template (
58- "dashboard.html" ,
59- userinfo = session ["profile" ],
60- userinfo_pretty = json .dumps (session ["jwt_payload" ], indent = 4 ),
61- )
62-
63- return render_template ("home.html" )
64-
51+ return render_template ("home.html" , session = session .get ('user' ), pretty = json .dumps (session .get ('user' ), indent = 4 ))
6552
66- @app .route ("/callback" )
67- def callback_handling ():
68- auth0 .authorize_access_token ()
69- resp = auth0 .get ("userinfo" )
70- userinfo = resp .json ()
7153
72- session ["jwt_payload" ] = userinfo
73- session ["profile" ] = {
74- "user_id" : userinfo ["sub" ],
75- "name" : userinfo ["name" ],
76- "picture" : userinfo ["picture" ],
77- }
54+ @app .route ("/callback" , methods = ["GET" ,"POST" ])
55+ def callback ():
56+ token = oauth .auth0 .authorize_access_token ()
57+ session ["user" ] = token
7858 return redirect ("/" )
7959
8060
8161@app .route ("/login" )
8262def login ():
83- return auth0 .authorize_redirect (
84- redirect_uri = env . get ( "AUTH0_CALLBACK_URL" ), audience = env .get ("AUTH0_AUDIENCE" )
63+ return oauth . auth0 .authorize_redirect (
64+ redirect_uri = url_for ( "callback" , _external = True ), audience = env .get ("AUTH0_AUDIENCE" )
8565 )
8666
8767
8868@app .route ("/logout" )
8969def logout ():
9070 session .clear ()
9171 return redirect (
92- auth0 . api_base_url
72+ "https://" + env . get ( "AUTH0_DOMAIN" )
9373 + "/v2/logout?"
9474 + urlencode (
9575 {
0 commit comments