2525AUTH0_CLIENT_ID = env .get (constants .AUTH0_CLIENT_ID )
2626AUTH0_CLIENT_SECRET = env .get (constants .AUTH0_CLIENT_SECRET )
2727AUTH0_DOMAIN = env .get (constants .AUTH0_DOMAIN )
28- AUTH0_BASE_URL = ' https://' + AUTH0_DOMAIN
28+ AUTH0_BASE_URL = " https://" + AUTH0_DOMAIN
2929AUTH0_AUDIENCE = env .get (constants .AUTH0_AUDIENCE )
3030
31- app = Flask (__name__ , static_url_path = ' /public' , static_folder = ' ./public' )
31+ app = Flask (__name__ , static_url_path = " /public" , static_folder = " ./public" )
3232app .secret_key = constants .SECRET_KEY
3333app .debug = True
3434
3535
3636@app .errorhandler (Exception )
3737def handle_auth_error (ex ):
3838 response = jsonify (message = str (ex ))
39- response .status_code = ( ex .code if isinstance (ex , HTTPException ) else 500 )
39+ response .status_code = ex .code if isinstance (ex , HTTPException ) else 500
4040 return response
4141
4242
4343oauth = OAuth (app )
4444
4545auth0 = oauth .register (
46- ' auth0' ,
46+ " auth0" ,
4747 client_id = AUTH0_CLIENT_ID ,
4848 client_secret = AUTH0_CLIENT_SECRET ,
4949 api_base_url = AUTH0_BASE_URL ,
50- access_token_url = AUTH0_BASE_URL + ' /oauth/token' ,
51- authorize_url = AUTH0_BASE_URL + ' /authorize' ,
50+ access_token_url = AUTH0_BASE_URL + " /oauth/token" ,
51+ authorize_url = AUTH0_BASE_URL + " /authorize" ,
5252 client_kwargs = {
53- ' scope' : ' openid profile email' ,
53+ " scope" : " openid profile email" ,
5454 },
5555)
5656
@@ -59,52 +59,56 @@ def requires_auth(f):
5959 @wraps (f )
6060 def decorated (* args , ** kwargs ):
6161 if constants .PROFILE_KEY not in session :
62- return redirect (' /login' )
62+ return redirect (" /login" )
6363 return f (* args , ** kwargs )
6464
6565 return decorated
6666
6767
6868# Controllers API
69- @app .route ('/' )
69+ @app .route ("/" )
7070def home ():
71- return render_template (' home.html' )
71+ return render_template (" home.html" )
7272
7373
74- @app .route (' /callback' )
74+ @app .route (" /callback" )
7575def callback_handling ():
7676 auth0 .authorize_access_token ()
77- resp = auth0 .get (' userinfo' )
77+ resp = auth0 .get (" userinfo" )
7878 userinfo = resp .json ()
7979
8080 session [constants .JWT_PAYLOAD ] = userinfo
8181 session [constants .PROFILE_KEY ] = {
82- ' user_id' : userinfo [' sub' ],
83- ' name' : userinfo [' name' ],
84- ' picture' : userinfo [' picture' ]
82+ " user_id" : userinfo [" sub" ],
83+ " name" : userinfo [" name" ],
84+ " picture" : userinfo [" picture" ],
8585 }
86- return redirect (' /dashboard' )
86+ return redirect (" /dashboard" )
8787
8888
89- @app .route (' /login' )
89+ @app .route (" /login" )
9090def login ():
91- return auth0 .authorize_redirect (redirect_uri = AUTH0_CALLBACK_URL , audience = AUTH0_AUDIENCE )
91+ return auth0 .authorize_redirect (
92+ redirect_uri = AUTH0_CALLBACK_URL , audience = AUTH0_AUDIENCE
93+ )
9294
9395
94- @app .route (' /logout' )
96+ @app .route (" /logout" )
9597def logout ():
9698 session .clear ()
97- params = {' returnTo' : url_for (' home' , _external = True ), ' client_id' : AUTH0_CLIENT_ID }
98- return redirect (auth0 .api_base_url + ' /v2/logout?' + urlencode (params ))
99+ params = {" returnTo" : url_for (" home" , _external = True ), " client_id" : AUTH0_CLIENT_ID }
100+ return redirect (auth0 .api_base_url + " /v2/logout?" + urlencode (params ))
99101
100102
101- @app .route (' /dashboard' )
103+ @app .route (" /dashboard" )
102104@requires_auth
103105def dashboard ():
104- return render_template ('dashboard.html' ,
105- userinfo = session [constants .PROFILE_KEY ],
106- userinfo_pretty = json .dumps (session [constants .JWT_PAYLOAD ], indent = 4 ))
106+ return render_template (
107+ "dashboard.html" ,
108+ userinfo = session [constants .PROFILE_KEY ],
109+ userinfo_pretty = json .dumps (session [constants .JWT_PAYLOAD ], indent = 4 ),
110+ )
107111
108112
109113if __name__ == "__main__" :
110- app .run (host = ' 0.0.0.0' , port = env .get (' PORT' , 3000 ))
114+ app .run (host = " 0.0.0.0" , port = env .get (" PORT" , 3000 ))
0 commit comments