-
Notifications
You must be signed in to change notification settings - Fork 218
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
The provided ConfidentialClientApplicationOptions.RedirectUri is not honored when Web App requests access token for the downstream API #784
Comments
@vh-vahan : you need to add the redirect URI corresponding to your deployed app to the app registration in the portal. |
Thanks @jmprieur for prompt response. I added this and it is being honored during the sign in flow msIdentityOptions.Events.OnRedirectToIdentityProvider = context => and I expected to get similar experience when configuring the token acquisition part as well so OnAuthorizationCodeReceived event it could successfully get the token and cache. .EnableTokenAcquisitionToCallDownstreamApi( |
@jmprieur so wondering how can I configure or make it to take into account the provided RedirectURI. Instead I register in the portal the cluster's load balanced URI and configure the same URI in application code to be used as redirectURI. Though it fails and i see here BuildConfidentialClientApplicationAsync() it does not check for the provided redirectURI and constructs it from the current request. What do you think? Any recommendation for this scenario. |
@vh-vahan : Let me rephrase if I understand the scenario.
|
@jennyf19 : proposing to do the following:
If ConfidentialClientApplication.RedirectUri is not null and is absolute, then we use it |
Thanks @jmprieur, yes, that is the scenario I have, and thanks for including that work in 1.4.0 version. |
Included in 1.4 Release. |
Which version of Microsoft Identity Web are you using?
Note that to get help, you need to run the latest version.
Microsoft Identity Web 1.3.0
Where is the issue?
Is this a new or an existing app?
This is a new app in development
Repro
Expected behavior
confidentialClientApplicationOptions.RedirectUri is used when provided.
Actual behavior
I have an ASP.NET Core web app that calls a downstream web API, and being deployed into Service Fabric cluster. The Web App's redirect URI in app registration portal is configured to be the load balanced URI of the cluster and also localhost.
It works on local environment when the app is deployed locally.
But I get exception when it runs on the cluster -
Exception occurred while processing the request.
System.Exception: An error was encountered while handling the remote login.
---> MSAL.NetCore.4.18.0.0.MsalServiceException:
ErrorCode: invalid_client
Microsoft.Identity.Client.MsalServiceException: A configuration issue is preventing authentication - check the error message from the server for details.You can modify the configuration in the application registration portal.
Original exception: AADSTS50011: The reply URL specified in the request does not match the reply URLs configured for the application: "my app id".
at Microsoft.Identity.Client.OAuth2.OAuth2Client.ThrowServerException(HttpResponse response, RequestContext requestContext)
at Microsoft.Identity.Client.OAuth2.OAuth2Client.CreateResponse[T](HttpResponse response, RequestContext requestContext)
at Microsoft.Identity.Client.OAuth2.OAuth2Client.ExecuteRequestAsync[T](Uri endPoint, HttpMethod method, RequestContext requestContext, Boolean expectErrorsOn200OK, Boolean addCommonHeaders)
at Microsoft.Identity.Client.OAuth2.OAuth2Client.GetTokenAsync(Uri endPoint, RequestContext requestContext, Boolean addCommonHeaders)
at Microsoft.Identity.Client.OAuth2.TokenClient.SendHttpAndClearTelemetryAsync(String tokenEndpoint)
at Microsoft.Identity.Client.OAuth2.TokenClient.SendHttpAndClearTelemetryAsync(String tokenEndpoint)
at Microsoft.Identity.Client.OAuth2.TokenClient.SendTokenRequestAsync(IDictionary
2 additionalBodyParameters, String scopeOverride, String tokenEndpointOverride, CancellationToken cancellationToken) at Microsoft.Identity.Client.Internal.Requests.RequestBase.SendTokenRequestAsync(String tokenEndpoint, IDictionary
2 additionalBodyParameters, CancellationToken cancellationToken)at Microsoft.Identity.Client.Internal.Requests.ConfidentialAuthCodeRequest.ExecuteAsync(CancellationToken cancellationToken)
at Microsoft.Identity.Client.Internal.Requests.RequestBase.RunAsync(CancellationToken cancellationToken)
at Microsoft.Identity.Client.ApiConfig.Executors.ConfidentialClientExecutor.ExecuteAsync(AcquireTokenCommonParameters commonParameters, AcquireTokenByAuthorizationCodeParameters authorizationCodeParameters, CancellationToken cancellationToken)
at Microsoft.Identity.Web.TokenAcquisition.AddAccountToCacheFromAuthorizationCodeAsync(AuthorizationCodeReceivedContext context, IEnumerable`1 scopes)
at Microsoft.Identity.Web.MicrosoftIdentityWebAppAuthenticationBuilder.<>c__DisplayClass10_1.<b__1>d.MoveNext()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.RunAuthorizationCodeReceivedEventAsync(OpenIdConnectMessage authorizationResponse, ClaimsPrincipal user, AuthenticationProperties properties, JwtSecurityToken jwt)
at Microsoft.AspNetCore.Authentication.OpenIdConnect.OpenIdConnectHandler.HandleRemoteAuthenticateAsync()
StatusCode: 400
ResponseBody: {"error":"invalid_client","error_description":"AADSTS50011: The reply URL specified in the request does not match the reply URLs configured for the application: 'my app id'.}
--- End of inner exception stack trace ---
at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.HandleRequestAsync()
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)
I think confidentialClientApplicationOptions.RedirectUri is not being honored and instead it uses the redirect uri constructed from the cluster node's IP.
Possible solution
https://github.com/AzureAD/microsoft-identity-web/blob/9bdf816d2f0e8fd029328ad11cf33217da963ba9/src/Microsoft.Identity.Web/TokenAcquisition.cs#L470
TokenAcquisition. BuildConfidentialClientApplicationAsync method checks for the configured redirectUri.
Additional context / logs / screenshots
Add any other context about the problem here, such as logs and screenshots.
The text was updated successfully, but these errors were encountered: