in generators/frontend/templates/src/frontend/app.py [0:0]
def get_principal_display_name():
"""
Get the display name of the current user from the request headers.
Extracts user information from the 'x-ms-client-principal' header used in
Azure Container Apps authentication.
Returns:
str: The user's display name if available, otherwise 'Default User'
See https://learn.microsoft.com/en-us/azure/container-apps/authentication#access-user-claims-in-application-code for more information.
"""
default_user_name = "Default User"
principal = st.context.headers.get('x-ms-client-principal')
if principal:
principal = json.loads(base64.b64decode(principal).decode('utf-8'))
claims = principal.get("claims", [])
return next((claim["val"] for claim in claims if claim["typ"] == "name"), default_user_name)
else:
return default_user_name