Azure B2C AD with thousand subdomains

Andrey Kuznetsov 65 Reputation points
2023-01-11T17:38:54.09+00:00

I have MS Azure B2C AD login setup in Blazor Server. The shared URL is https://login.subone.dev.mymaindomain.com. The redirect URL is https://login.subone.dev.mymaindomain.com/signin-oidc. It works perfectly. I have added another site: https://companyone.subone.dev.mymaindomain.com. The redirect URL is https://companyone.subone.dev.mymaindomain.com/signin-oidc. It works perfectly as well. I even can redirect (from my web app) between the "login" and "companyone" subdomains without login. Good!

The problem is that I have more than 1000 subdomains and the B2C redirect /signin-oidc has a limit on a number of redirect URLs. If I add https://companytwo.subone.dev.mymaindomain.com without corresponding https://companytwo.subone.dev.mymaindomain.com/signin-oidc and trying to access to "companytwo" from my app I am getting an error. From MS site https://learn.microsoft.com/en-us/azure/active-directory/develop/reply-url#maximum-number-of-redirect-uris: Use a state parameter If you have several subdomains and your scenario requires that, upon successful authentication, you redirect users to the same page from which they started, using a state parameter might be helpful. In this approach: Create a "shared" redirect URI per application to process the security tokens you receive from the authorization endpoint. Your application can send application-specific parameters (such as the subdomain URL where the user originated or anything like branding information) in the state parameter. When using a state parameter, guard against CSRF protection as specified in section 10.12 of RFC 6749). The application-specific parameters will include all the information needed for the application to render the correct experience for the user, that is, construct the appropriate application state. The Azure AD authorization endpoint strips HTML from the state parameter so make sure you are not passing HTML content in this parameter. When Azure AD sends a response to the "shared" redirect URI, it will send the state parameter back to the application. The application can then use the value in the state parameter to determine which URL to further send the user to. Make sure you validate for CSRF protection.

This is not working for me. The state parameter is a string that is not changing on the MS side. So I can send and get the redirect URL in this string. But I already know the redirect URL. And if I try to redirect then I get the error because there is no corresponding /signin-oidc. Could somebody point me in the right direction?

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,585 questions
Microsoft Entra External ID
Microsoft Entra External ID
A modern identity solution for securing access to customer, citizen and partner-facing apps and services. It is the converged platform of Azure AD External Identities B2B and B2C. Replaces Azure Active Directory External Identities.
2,892 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,907 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Washington 911 Reputation points MVP
    2023-01-12T00:57:01.6633333+00:00

    You can add more Azure B2C "App Registrations"

    User's image

    Basically, add as many as you need. Each can have a set of redirect URLs.

    Your application will just need to pass the proper ClientID associated with the redirect URL you need. But this will work for you.

    1 person found this answer helpful.

3 additional answers

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.