1

I have an app hosted on Azure PaaS using Open ID Connect for auth.

The app URL is like: https://env.app.entity.my.domain
The Azure ASE is: https://entity-app-env-web.webenvase.my.domain

As long as I configure a redirect URI for https://entity-app-env-web.webenvase.my.domain/signin-oidc in Azure, it works. That's because it's ignoring the redirect URI in my settings. But that's not what I want. I will obviously want to return the user to the app's URL.

No matter what values I put for my RedirectUri or CallbackPath, it defaults to the ASE URL. How can I fix that?

appsettings.json:

"AzureAd": {
  "Instance": "https://login.microsoftonline.com/",
  "Issuer": "https://sts.windows.net/<tenant id>/",
  "Domain": "my.azure.domain",
  "TenantId": "<tenant id>",
  "ClientId": "<client id>",
  "RedirectUri": "https://env.app.entity.my.domain/signin-oidc"
}

Startup.cs (auth config):

services.AddMicrosoftIdentityWebAppAuthentication(Configuration);
services.AddControllersWithViews(options =>
{
    var policy = new AuthorizationPolicyBuilder()
        .RequireAuthenticatedUser()
        .RequireRole(Role.Administrator)
        .Build();
    options.Filters.Add(new AuthorizeFilter(policy));
})
.AddMicrosoftIdentityUI();
ChiefTwoPencils
  • 13,548
  • 8
  • 49
  • 75

1 Answers1

1

I found from this answer and elsewhere that the redirect uri is automatically calculated not using the value from the configs. The one in the configs will be used in some cases but not for the auth call to Azure.

After monkeying around with it for some time our server team started removing rules on the f5 and we found that the header rewrite rule that is typical for our other apps was the issue. Specifically, it was causing the auth cookie to be rejected and stripped at the browser during redirection.

We removed the rule and all is well again.

ChiefTwoPencils
  • 13,548
  • 8
  • 49
  • 75
  • Hey @ChiefTwoPencils I'm in the same situation, where we use a Reverse Proxy to have a different URL than the one provided by Azure. Can you elaborate a bit more on what changes were done? And you did not need to change any .NET code? – Depechie Jun 30 '22 at 07:04
  • 1
    @Depechie, there was no code changes necessary. The f5 is managed by another team so unfortunately I don't know the specifics of it. I do believe we had to register a custom domain in azure that matched the public URL. I can try to see if I can get some more info for you. – ChiefTwoPencils Jun 30 '22 at 21:53