Shower thoughts and tech-mirages

On-Behalf-Of auth in Azure Container Apps with built-in Easy Auth

For a recent project I needed an easy-to-maintain and no-worries setup where an application running in an Azure Container App could, on behalf of the user, access Microsoft Graph (Sharepoint).

I realised that I could let the built-in auth-sidecar (Easy Auth) fix this for me by directly providing an access token, but I ran into problems with the setup. Quite a few hours later it works wonderfully, and I just wanted to share, in case a search crawler finds it, how I made it work and why I found it challenging.

On-behalf-of-auth (OBO)

Reading about OBO here: https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-on-behalf-of-flow,

and seeing how easy this could be setup here (this post summarises it all and gives some interesting references, worth a read!): https://davidrosevear.dev/blog/token-store-and-obo-auth-in-container-apps,

I believed that this would be easy-peasy. All I need to do is to request a scope in the Azure Entra ID App Registration and my application which necessitates an access token to e.g. Graph (like ‘https://graph.microsoft.com/Sites.Read.All’). Then the token will be given to me in the HTTP headers by the auth sidecar, and I’m good to go!

Turned out to be quite a headache to make this work due to some finicky details in command syntax, broken/missing documentation and more..

A quick recipe to make it work

Instead of going through everything that didn’t work, let me simply summarise what does work.

Problem

When using Azure Container Apps with built-in authentication, by default:

Solution Overview

You need to:

  1. Configure authentication to request Microsoft Graph scopes (and offline scope to get refresh token) (I don’t go through this here)
  2. Ensure App Registration has proper API permissions (I don’t go through this here)
  3. Configure EasyAuth (Container App Auth) so that the relevant tokens are actually fetched and exposed (CAN NOT be done (I believe) using Azure Portal click-ops as of 01.01.2026)
  4. Access (and refresh) tokens will then be available via X-MS-TOKEN-AAD-ACCESS-TOKEN header

Step-by-Step Configuration

Enable authentication on your existing Container App, either using Azure Portal or CLI:

# Set your variables
APP_NAME="your-container-app-name"
RESOURCE_GROUP="your-resource-group"
CLIENT_ID="your-client-id"
CLIENT_SECRET="your-client-secret"
TENANT_ID="your-tenant-id"
ISSUER_URL="<https://login.microsoftonline.com/${TENANT_ID}/v2.0>"

# Configure Microsoft authentication with Graph API scopes
az containerapp auth microsoft update \\
  --name $APP_NAME \\
  --resource-group $RESOURCE_GROUP \\
  --client-id $CLIENT_ID \\
  --client-secret $CLIENT_SECRET \\
  --issuer $ISSUER_URL \\
  --tenant-id $TENANT_ID \\
  --yes

We now have to activate the token store, since it is NOT activated by default like for App Service.

In the following, the SAS URL should point to a Blob Storage container with appropriate permissions (not storage account SAS! This SAS should be read/write/create/delete for the container only.)

# CRITICAL: WE MUST ACTIVATE TOKEN STORE MANUALLY when using Container Apps (as of 2025)
az containerapp secret set \\
  --name $APP_NAME \\
  --resource-group $RESOURCE_GROUP \\
  --secrets 'tokenstore-sas-url=CONTAINER_APP_SAS_URL_HERE'

az containerapp auth update \\
  --name $APP_NAME \\
  --resource-group $RESOURCE_GROUP \\
  --sas-url-secret-name tokenstore-sas-url \\
  --token-store true

Now we need to update the authentication configuration to request Microsoft Graph scopes:

# CRITICAL: Update to request Microsoft Graph scopes
# This tells Container Apps to request access tokens with Graph permissions
# NBNBNB: CRITICAL: The below syntax is correct and works. Most sources get the syntax wrong! (loginParameters[0]=scope...) Argh!! -Hetland/25
az containerapp auth update \\
  --name $APP_NAME \\
  --resource-group $RESOURCE_GROUP \\
  --set 'identityProviders.azureActiveDirectory.login.loginParameters=[scope=openid profile email <https://graph.microsoft.com/User.Read> <https://graph.microsoft.com/Sites.Read.All> <https://graph.microsoft.com/Files.Read.All> offline_access]'

Hot tip: In Azure Portal or CLI, you can stream the logs also from the auth-sidecar. This can identify if the authentication is working or not, and some really finicky errors.

# Now, to debug and verify the auth config total
az containerapp auth show \\
  --name $APP_NAME \\
  --resource-group $RESOURCE_GROUP

… And in general - some of these changes will correctly and automatically restart the auth-sidecar.. But sometimes this fails, and/or the app itself also needs a restart.. And I’ve experienced the auth-sidecar needing some minutes to manage to find the token-store container.. All this makes debugging issues challenging ;)

Wrap-up

Hope that helped someone! I struggled with the Azure CLI not accepting commands found online, not allowing me to update the scopes using JSON upload, SAS-token being the wrong type.. Pair this with the slow debugging cycle of always waiting for changes and redeploys, and errors easily take a few days to fix.

I now have this working in multiple apps, where different types of Python backends can use the access token for delegated access to e.g. Sharepoint. And when the token expires it can automatically fetch a new one using the refresh token.

Good luck!