Skip to content

Instantly share code, notes, and snippets.

@ricardochaves
Created February 2, 2019 17:31
Show Gist options
  • Save ricardochaves/ec73606ca9d46dcff214474befe37d0b to your computer and use it in GitHub Desktop.
Save ricardochaves/ec73606ca9d46dcff214474befe37d0b to your computer and use it in GitHub Desktop.
@app.route("/getAToken")
def main_logic():
code = flask.request.args["code"]
state = flask.request.args["state"]
if state != flask.session["state"]:
raise ValueError("State does not match")
auth_context = adal.AuthenticationContext(AUTHORITY_URL)
token_response = auth_context.acquire_token_with_authorization_code(
code, REDIRECT_URI, config.RESOURCE, config.CLIENT_ID, config.CLIENT_SECRET
)
# It is recommended to save this to a database when using a production app.
flask.session["access_token"] = token_response["accessToken"]
return flask.redirect("/privateurl")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment