2

Is it possible to use a single Redirect URI for multiple tenants and multiple web applications using a single Azure AD App Registration?

I have reached the limit of 256 URIs in my Azure multi tenant App Registration where each registered tenant have their own set of redirect URIs.

The redirect URIs follow this pattern

After reading Use a state parameter I had the idea to create a new web app that only authenticates and then redirects the user to the originally requested URI. But it is not possible to configure the OpenId CallbackPath to the new auth/authorize/redirect app.

How should I solve this?

ASP.NET Core
authenticationBuilder.Services.AddSingleton<IConfigureOptions<OpenIdConnectOptions>, ConfigureAzureOptions>();
authenticationBuilder.AddOpenIdConnect();

private class ConfigureAzureOptions : IConfigureNamedOptions<OpenIdConnectOptions>
{
   public void Configure( string name, OpenIdConnectOptions options )
   {
      options.ClientId     = "555-xxx";
      options.Authority    = "https://login.microsoftonline.com/common";
      options.CallbackPath = "https://mydomain/myauth-redir-app/signin-iodc" // this is not allowed
      options.Events       = new OpenIdConnectEvents
      {
         OnRedirectToIdentityProvider = ctx => 
         {
             // remember the URL the user requested, to be picked upp later after AAD auth
             ctx.ProtocolMessage.SetParameter("state", "set_org_url"); 
         }
         OnTokenValidated = ctx =>
         {
            // this code should run in myauth-redir-app and pick up the state 
            // and redirect the user to the originally requested URL
            var stateValue = ctx.ProtocolMessage.GetParameter("state");
         }
      }
   }
}

Rejected solutions

  1. Using wildcards in the URI is no longer supported
  2. Creating an App Registration for each Web Application still limits me to 256 tenants, which is too few.
  3. Creating new App Registrations for each tenant is too cumbersome to maintain and configure.
  4. I do not want to register the Redirect URI in the tenants Service Principal, I must be able to add and remove URIs without the customer having to take action.
MatiasK
  • 636
  • 6
  • 18
  • 1
    Hey MatiasK, I find myself in a very similar situation, did you have any solution to this problem? – Ovenkoek Apr 07 '21 at 14:02
  • @Ovenkoek I ended up making the web apps multitenant and thereby the redirect uris were reduced to one per web app instead of a multiple of customer and web app. I use the tenant id claim to identify the customer after they are authenticated. – MatiasK Apr 09 '21 at 05:53

2 Answers2

0

It's the protocol limitation not an Azure AD issue, please check: https://stackoverflow.com/a/812962/1384539

To solve this, you need to redirect to an intermediate page which will handle the right place to redirect your user. As far as I know, there's no other way.

Thiago Custodio
  • 15,655
  • 6
  • 41
  • 81
  • In Azure I can define 256 different _Redirect_ _URI_ per App Registration. And I only specify one of these URIs as the OpenId callback path. So I do not think this is a browser/web server limitation. I want the `OpenIdConnectOptions.Callbackpath` to accept an URI that points to a web app common to all tenants. Which should mean that I only need a single _Redirect_ _URI_ for all tenants and their web apps. – MatiasK Nov 12 '19 at 07:55
0

Did that make your registration multi-tenant by finding the Supported account types switch on the Authentication pane of your application registration in the Azure portal and setting it to Accounts in any organizational directory ?

With multi-tenant application you just need one redirect url( the original one) . For a multi-tenant application, the initial registration for the application lives in the Azure AD tenant used by the developer. When a user from a different tenant signs in to the application for the first time, Azure AD asks them to consent to the permissions requested by the application. If they consent, then a representation of the application called a service principal is created in the user’s tenant, and sign-in can continue. A delegation is also created in the directory that records the user’s consent to the application.

See document : https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-convert-app-to-be-multi-tenant#update-registration-to-be-multi-tenant

Nan Yu
  • 23,741
  • 6
  • 55
  • 129
  • Yes the registration is multi tenant and currently serves multiple web apps and multiple consumer tenants. The problem is that I can only define 265 redirect urls and I need 7 urls per consuming tenant (protocol://a.com/consumer[1..x]/webapp[1..7]/signin-oidc). I am limited to 36 consuming tenants. – MatiasK Nov 13 '19 at 09:46
  • That is AAD's limit , you can consider add another AAD . – Nan Yu Nov 14 '19 at 01:23