-
Notifications
You must be signed in to change notification settings - Fork 144
/
app.py
44 lines (39 loc) · 1.52 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import requests
from flask import Flask, render_template
from identity.flask import Auth
import app_config
__version__ = "0.9.0" # The version of this sample, for troubleshooting purpose
app = Flask(__name__)
app.config.from_object(app_config)
auth = Auth(
app,
authority=os.getenv("AUTHORITY"),
client_id=os.getenv("CLIENT_ID"),
client_credential=os.getenv("CLIENT_SECRET"),
redirect_uri=os.getenv("REDIRECT_URI"),
oidc_authority=os.getenv("OIDC_AUTHORITY"),
b2c_tenant_name=os.getenv('B2C_TENANT_NAME'),
b2c_signup_signin_user_flow=os.getenv('SIGNUPSIGNIN_USER_FLOW'),
b2c_edit_profile_user_flow=os.getenv('EDITPROFILE_USER_FLOW'),
b2c_reset_password_user_flow=os.getenv('RESETPASSWORD_USER_FLOW'),
)
@app.route("/")
@auth.login_required
def index(*, context):
return render_template(
'index.html',
user=context['user'],
edit_profile_url=auth.get_edit_profile_url(),
api_endpoint=os.getenv("ENDPOINT"),
title=f"Flask Web App Sample v{__version__}",
)
@app.route("/call_api")
@auth.login_required(scopes=os.getenv("SCOPE", "").split())
def call_downstream_api(*, context):
api_result = requests.get( # Use access token to call a web api
os.getenv("ENDPOINT"),
headers={'Authorization': 'Bearer ' + context['access_token']},
timeout=30,
).json() if context.get('access_token') else "Did you forget to set the SCOPE environment variable?"
return render_template('display.html', title="API Response", result=api_result)