We didn't yet end up using AD auth in production, though I did eventually have a rudimentary working version.
I ended up using the python msal library directly.
b2c_tenant = "some-uuid"
signupsignin_user_flow = "B2C_1_signupsignin1"
editprofile_user_flow = "B2C_1_profileediting1"
resetpassword_user_flow = "B2C_1_passwordreset1" # Note: Legacy setting.
CLIENT_ID = "some-uuid"
CLIENT_SECRET = "some-uuid"
AUTHORITY = authority_template.format(
tenant=b2c_tenant, user_flow=signupsignin_user_flow)
B2C_PROFILE_AUTHORITY = authority_template.format(
tenant=b2c_tenant, user_flow=editprofile_user_flow)
B2C_RESET_PASSWORD_AUTHORITY = authority_template.format(
tenant=b2c_tenant, user_flow=resetpassword_user_flow)
REDIRECT_PATH = "/getAToken" # Used for forming an absolute URL to your redirect URI.
ENDPOINT = '' # Application ID URI of app registration in Azure portal
SCOPE = [] # Example with two exposed scopes: ["demo.read", "demo.write"]
SESSION_TYPE = "filesystem" # Specifies the token cache should be stored in server-side session
def _load_cache():
cache = msal.SerializableTokenCache()
if session.get("token_cache"):
cache.deserialize(session["token_cache"])
return cache
def _save_cache(cache):
if cache.has_state_changed:
session["token_cache"] = cache.serialize()
def _build_msal_app(cache=None, authority=None):
return msal.ConfidentialClientApplication(
app_config.CLIENT_ID, authority=authority or app_config.AUTHORITY,
client_credential=app_config.CLIENT_SECRET, token_cache=cache)
def _build_msal_app(cache=None, authority=None):
return msal.ConfidentialClientApplication(
CLIENT_ID, authority=authority or AUTHORITY,
client_credential=CLIENT_SECRET, token_cache=cache)
def _build_auth_code_flow(authority=None, scopes=None):
return _build_msal_app(authority=authority).initiate_auth_code_flow(
scopes or [],
redirect_uri=redirect_url)
Then I use these functions on the login page.
Using the ad_login_url to redirect to with a button on the login page. Then there's the standard microsoft register/login form that redirects to the my "token" controller function referenced in the "redirect_url" at the top of the pasted code. This url needs to be configured where you register an azure app.
In the token controller you recieve the token which you an then use for authentication - login/registration
I don't know how clear this is, hopefully it's at least a little bit helpful, but I'm a bit fuzzy on the details.