Skip to content

Instantly share code, notes, and snippets.

@srgrn
Created December 31, 2025 06:22
Show Gist options
  • Select an option

  • Save srgrn/607670f1de79e5faa4efb85ec1d5b612 to your computer and use it in GitHub Desktop.

Select an option

Save srgrn/607670f1de79e5faa4efb85ec1d5b612 to your computer and use it in GitHub Desktop.
Flask App Builder Oauth Config for azure entra with roles
import os
from flask_appbuilder.security.manager import AUTH_OAUTH
basedir = os.path.abspath(os.path.dirname(__file__))
SECRET_KEY = "thisismyscretkey"
SQLALCHEMY_DATABASE_URI = "sqlite:///" + os.path.join(basedir, "app.db")
# Flask-WTF flag for CSRF
CSRF_ENABLED = True
# ------------------------------
# GLOBALS FOR APP Builder
# ------------------------------
APP_NAME = "OAUTH Roles Example"
# ----------------------------------------------------
# AUTHENTICATION CONFIG
# ----------------------------------------------------
# The authentication type
# AUTH_OID : Is for OpenID
# AUTH_DB : Is for database (username/password()
# AUTH_LDAP : Is for LDAP
# AUTH_REMOTE_USER : Is for using REMOTE_USER from web server
# AUTH_OAUTH : Is for OAuth
AUTH_TYPE = AUTH_OAUTH
# Will allow user self registration
AUTH_USER_REGISTRATION = True
# The default user self registration role
AUTH_USER_REGISTRATION_ROLE = "Public"
AUTH_ROLES_SYNC_AT_LOGIN = True
AUTH_USER_REGISTRATION_ROLE_JMESPATH = "(role_keys && role_keys[0]) || 'Public'"
OAUTH_PROVIDERS = [
{
"name": "azure",
"icon": "fa-windows",
"token_key": "access_token",
"remote_app": {
"client_id": os.environ.get("AZURE_APPLICATION_ID"),
"client_secret": os.environ.get("AZURE_SECRET"),
"api_base_url": f"https://login.microsoftonline.com/{os.environ.get('AZURE_TENANT_ID')}/oauth2",
"client_kwargs": {
"scope": "User.read name preferred_username email profile upn",
"resource": os.environ.get("AZURE_APPLICATION_ID"),
},
"access_token_url": f"https://login.microsoftonline.com/{os.environ.get('AZURE_TENANT_ID')}/oauth2/token",
"authorize_url": f"https://login.microsoftonline.com/{os.environ.get('AZURE_TENANT_ID')}/oauth2/authorize",
},
}
]
@srgrn
Copy link
Author

srgrn commented Dec 31, 2025

This is a simple example of using Entra ID App registration with roles enabled using the JMESPATH capabilties to allow consuming the roles from the app registration.
Steps:

  1. Create app registration in entra
  2. Create roles in the app in entra
  3. Create roles in the fab app (either through ui or through other means) matching the value you gave to the roles in the app in entra
  4. assign users or groups to the relevant roles.
  5. when users login they will be moved to the roles as coming from entra.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment