I'm having an ASP.NET Core application hosted on a linux container in the SAP Cloud environment (Cloud-Foundry).
I am implementing Azure AD authentication using the Microsoft.AspNetCore.Authentication.AzureAD.UI
libraries.
The authentication fails because no matter what protocol I initially access the web application, it generates the redirect_uri
with the http
protocol.
This fails because it does not match the https url defined in the app-registration in Azure.
AADSTS50011: The reply url specified in the request does not match the reply urls configured for the application
In the options, you can pass in the CallbackPath
, but this only accepts a relative path (must start with /).
Otherwise it's coming from the redirect_url
which is automatically generated based on the scheme, host, port and path extracted from the current request.
What I don't understand is that even when I access the application directly in the browser with https
, it still uses http in the redirect_uri.
I guess the underlying problem is that the application hosted in Cloud Foundry accepts http requests.
Here's the code parts of how I implemented the Azure AD Authentication.
services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
.AddAzureAD(options => Configuration.Bind("Authentication:AzureAD", options));
services.Configure<OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>
{
options.Authority = options.Authority + "/v2.0"; // Microsoft identity platform
options.TokenValidationParameters.ValidateIssuer = true;
});
app.UseHsts();
app.UseHttpsRedirection();
"Authentication": {
"AzureAD": {
"Instance": "https://login.microsoftonline.com/",
"ClientId": "{app-application-id}",
"TenantId": "{my-tenant-id}"
}
}