-
Notifications
You must be signed in to change notification settings - Fork 219
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]Azure AD Application Gateway redirect to /signin-oidc which return 404 #1199
Comments
@NewbieDev123 ar initialScopes = configuration.GetValue<string>("DownstreamApi:Scopes")?.Split(' ');
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme).
.AddMicrosoftIdentityWebApp(configuration.GetSection("AzureAd"))
.EnableTokenAcquisitionToCallDownstreamApi(initialScopes)
.AddDownstreamWebApi("DownstreamApi", configuration.GetSection("DownstreamApi"))
.AddInMemoryTokenCaches();
services.Configure<MicrosoftIdentityOptions>(OpenIdConnectDefaults.AuthenticationScheme,
options =>
{
Task RedirectToIdentityProvider(RedirectContext ctx)
{
ctx.ProtocolMessage.RedirectUri = "https://{AzureAppGatewayUrl}/signin-oidc";
return Task.FromResult(0);
}
var previousEvent = options.Events.OnRedirectToIndentityProvider;
options.Events.OnRedirectToIdentityProvider = context => { previousEvent(context); RedirectToIdentityProvider(ctx};
}); However, I think that the right way to achieve what you want is by following the guidance in this article: https://github.com/AzureAD/microsoft-identity-web/wiki/Deploying-Web-apps-to-App-services-as-Linux-containers |
@jmprieur , thanks for your reply. |
@jmprieur ,pardon my limited knowledge in Azure Application gateway, but is it a linux container?
|
@jmprieur I tried adding the ASPNETCORE_FORWARDEDHEADERS_ENABLED key in the appsettings of the appservice. But that too did not work. When I launch the App Gateway URL, it tries to login and then gets redirected to {internalurl}/signin-oidc, which returns a 404. I think it is correct because that is set as the reply url. But doesn't that happens internally. I mean when I launch the internal url, I have never seen it redirecting to the /signin-oidc, so I thought it might be happening internally. And in this case it goes directly to the home page. I believe after login the authentication server might be sending some information(tokens) to the /sigin-oidc and gets redirected to homepage.Is that right? I cannot understand why that does not happen when the appservice is registered in the App Gateway. |
@NewbieDev123 did you add this in Configure: |
@jmprieur , yes I did. I removed it when I added the ASPNETCORE_FORWARDEDHEADERS_ENABLED appsetting parameter in the Azure Portal. |
@Tratcher can you help with this one? thanks. |
@NewbieDev123 I think your scenario requires ForwardedHeaders.XForwardedHost so it can generate urls using the external host.
You can check the troubleshooting output from here to make sure the gateway is sending you an X-Forwarded-Host header. |
@Tratcher I tried ForwardedHeaders.XForwardedHost, but that did not work. I will go through the troubleshooting document and let you know. Just one quick question. I was under the impression when we add ASPNETCORE_FORWARDEDHEADERS_ENABLED appsetting parameter in the Azure Portal the middleware will be automatically added and I will not have to add the header code in the StartUp.cs. Is that not the way it works? |
Yes it should, though that doesn't include X-Forwarded-Host by default. |
Where is UseForwardedHeaders in your Startup.Configure method? It should be near the top. What's the current |
@Tratcher
|
I set up a HealthCheck in a quick prototype project HttpContext.Request.Host that comes back from the HealthCheck endpoint is companyname.azurewebsites.net So
There is also
Not sure if this has any effect |
X-Forwarded-Host is the expected input, so why isn't it being applied. Try this so we can rule out issues with the IP:
Also enable server debug logs to see if there are any complaints on that end. |
@freemstr did Tratcher's advice solve your issues? |
@jmprieur @Tratcher |
Hi @jmprieur @Tratcher I tried the logging code and it gave me few details. One error that happen when trying to application gateway endpoint is the below.
Also in the logs I could see the following details. X-ORIGINAL-HOST: Application_Gateway_url I could not find X-Forwarded-Host or X-Forwarded-Proto in the logs. |
I had a similar issue. Eventually, I got the redirect uri problem fixed by using following code but get "Correlation failed" error as newbiedev123
any solution to fix "Correlation failed" error? ... |
@NewbieDev123 that usually indicates an issue with the temp cookies used for authentication. If you capture a network trace with a tool like you should see the cookie properties set on the challenge request. In this scenario I'd guess your cookies are either not marked with |
@smartsavage your case is probably the same. Follow the troubleshooting steps here to capture the request headers and figure out how to configure the forwarders. Try starting with this:
|
fixed Correlation failed" error with this code
|
@Tratcher
I can see in the logs that OpenId is challenged after every set of headers.
Also I am still getting the Correlation error. My application is not a B2C application, it is just an Azure Ad Authenticated application. I thought it was a token based authentication and not cookie based authentication. So what is this temporary cookie used for? Do you have any documentation links for the temporary cookie, please? I am just wondering if there could be a setting in the application gateway for cookie which is causing the issue?cookie based affinity? |
Note CookiePolicyOptions is ineffective without the matching UseCookiePolicy middleware. OpenIdConnectHandler stores temp state in cookies during the login and persists it's results in cookies after so the user remains logged in for future requests. What's written to the logs by this?
|
@Tratcher , I realised I missed the cookie policy after posting the comment. Adding it did not make any changes. But I forgot to update the comment.
When I launch the app gateway url, two requests get executed(shown in logs).
|
Ok, the request headers look fine. The only other thing you haven't shown yet is the response cookies where the .AspNetCore.Correlation.OpenIdConnect is set. We'd need to see all the attributes. Try this:
|
@Tratcher , the response headers are as below.
The reply url is set as the internal_ase_url/signin-oidc. It is strange that when launching the app_gateway_url it gets rediretced to the internal_ase_url/signin-oidc and comes back with 404. Isn't that suppose to happen internally? I mean isn't that handled by the microsoft.identity.web? |
The client is sending that initial request to app_gateway_url, right? Then the redirect_uri is your issue, it should use the public host visible to the client (app_gateway_url). That's what the client saves the cookies under. If |
@Tratcher thanks. I will try those and let you know. |
@Tratcher that worked. Thank you very much. |
For those like me out there following this great thread that provides a lot of insights, I'd like to add something on top of it while working with I initially followed the idea provided from the docs which consist of re-rewriting the Therefore, to get it fully working, it is still required to disable the cc/ @Tratcher |
We have a similar issue with a Blazor app, we tried everything that is mentioned in the site, what was the final solution? Fresher900 randomly said it worked! But how it worked is not mentioned in detail, can you please help? |
For anyone still struggling with this error or errors such as: |
Which version of Microsoft Identity Web are you using?
Microsoft Identity Web 1.10.0
Where is the issue?
Is this a new or an existing app?
c. This is a new app or an experiment.
behavior
I am working on a ASP.net core 3.1 application which works fine on localhost and on our private network. But we want to make it available to some people outside our network, so we are using Azure application gateway for that.
We registered the app on the Application Gateway, but when the link it tried it gets redirect to the [private-network-url]/signin-oidc , which returns a 404.
I expect that when we launch the Application Gateway address, it calls the correct appservice and which will do the authentication and take me to home page.
Possible solution
I read about a possible solution in StackOverflow.
https://stackoverflow.com/questions/48399699/azure-ad-redirect-url-using-application-gateway
I tried it,
But getting the error below,
![image](https://user-images.githubusercontent.com/81688354/118660149-d5f61480-b7e5-11eb-981d-db6e62818500.png)
Not sure how I would do it with the Microsoft.Identity.Web library?
Is getting 404 an expected behaviour?
The text was updated successfully, but these errors were encountered: