Azure B2C with dynamic redirect URI from staging Azure Static Webapp

Viewed 28

I have an Azure Static Web App that hosts a vue app, it uses Azure B2C to authenticate.

I'd like to use the functionality of Static Web Apps where on each pull request in Azure Devops, it deploys to a unique staging environment, but since B2C creates a new URL for each branch, the URL isn't in B2C's redirect list and login fails. B2C does not allow me to use a wildcard URI.

How do I get Azure B2C to work with a static app staging branches when the URL for each one is different?

1 Answers

You could use the Azure CLI to add the reply-uri to the app registration in B2C when you spin up the new Static web app. Although this will require a clean up exercise to make sure you keep under the maximum number of URIs.

Another option would be to use a state parameter. When you make the request to login you store the url to the static web app you wish to be directed to. Then you login in and B2C redirects to a page which then reads the state and then moves you on to the correct url with a 302 response. This is outlined here: https://docs.microsoft.com/en-us/azure/active-directory/develop/reply-url#use-a-state-parameter

Make sure to read up on the security issues with that approach.

Related