abp icon indicating copy to clipboard operation
abp copied to clipboard

DomainTenantResolver sample with OpenIddict and Angular throws redirect_uri on login.

Open dkaczor97 opened this issue 3 years ago • 5 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Description

I want to implement Domain tenant resolving in my ABP Commercial app. As advised, I tried running the sample created by your team. Unfortunately it does not work. I see redirect_uri error when trying to log in as a tenant. Below are steps I took to run the sample.

Reproduction Steps

  • Clone https://github.com/abpframework/abp-samples/tree/master/DomainTenantResolver/OpenIddict/NG
  • Run DbMigrator
  • Run HttpApi.Host Project
  • Run Angular app
  • Open https://ng.getabp.net:4200/
  • Click Login button
  • Login as Host
  • Create new tenant named "newtenant"
  • Logout
  • Open https://newtenant.ng.getabp.net:4200/
  • Click Login button
  • I get redirected to https://newtenant.api.getabp.net:44301/connect/authorize?response_type=code&client_id=BookStore_App&state=TERuOEYuRUhLc0h0dy4tdFlOeTJaZ1Q2bDMuSTNRMHV-Qk56a0RZNjloek9v&redirect_uri=https%3A%2F%2Fnewtenant.ng.getabp.net%3A4200&scope=openid%20BookStore&code_challenge=Fo8F86Abb96sWVNpp2NDrMHLYXQN0t7pywFl_yMQn9Q&code_challenge_method=S256&nonce=TERuOEYuRUhLc0h0dy4tdFlOeTJaZ1Q2bDMuSTNRMHV-Qk56a0RZNjloek9v&culture=en&ui-culture=en
  • The following text is displayed:

error:invalid_request error_description:The specified 'redirect_uri' is not valid for this client application. error_uri:https://documentation.openiddict.com/errors/ID2043

Here are the logs:

2023-03-30 15:28:13.841 +02:00 [INF] Request starting HTTP/2 GET https://newtenant.api.getabp.net:44301/connect/authorize?response_type=code&client_id=BookStore_App&state=dzNETGhVck1GTX5lWTlPN2dualBLRWEzMkNFanVrU0p6bEoyeVE1dlN2VTJq&redirect_uri=https%3A%2F%2Fnewtenant.ng.getabp.net%3A4200&scope=openid%20BookStore&code_challenge=eniwwCG0YpcsO8_-qkxlwam-9YTiChcUYZ0lvGDy8Xg&code_challenge_method=S256&nonce=dzNETGhVck1GTX5lWTlPN2dualBLRWEzMkNFanVrU0p6bEoyeVE1dlN2VTJq&culture=en&ui-culture=en - - 2023-03-30 15:28:13.843 +02:00 [DBG] The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessRequestContext was successfully processed by OpenIddict.Validation.AspNetCore.OpenIddictValidationAspNetCoreHandlers+ResolveRequestUri. 2023-03-30 15:28:13.843 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ProcessRequestContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+ResolveRequestUri. 2023-03-30 15:28:13.843 +02:00 [INF] The request URI matched a server endpoint: "Authorization". 2023-03-30 15:28:13.843 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ProcessRequestContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+InferEndpointType. 2023-03-30 15:28:13.843 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ProcessRequestContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+ValidateTransportSecurityRequirement. 2023-03-30 15:28:13.843 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ProcessRequestContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+ValidateHostHeader. 2023-03-30 15:28:13.843 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ExtractAuthorizationRequestContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+ExtractGetOrPostRequest1[[OpenIddict.Server.OpenIddictServerEvents+ExtractAuthorizationRequestContext, OpenIddict.Server, Version=4.0.0.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]]. 2023-03-30 15:28:13.843 +02:00 [INF] The authorization request was successfully extracted: { "response_type": "code", "client_id": "BookStore_App", "state": "dzNETGhVck1GTX5lWTlPN2dualBLRWEzMkNFanVrU0p6bEoyeVE1dlN2VTJq", "redirect_uri": "https://newtenant.ng.getabp.net:4200", "scope": "openid BookStore", "code_challenge": "eniwwCG0YpcsO8_-qkxlwam-9YTiChcUYZ0lvGDy8Xg", "code_challenge_method": "S256", "nonce": "dzNETGhVck1GTX5lWTlPN2dualBLRWEzMkNFanVrU0p6bEoyeVE1dlN2VTJq", "culture": "en", "ui-culture": "en" }. 2023-03-30 15:28:13.843 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ProcessRequestContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Authentication+ExtractAuthorizationRequest. 2023-03-30 15:28:13.843 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ValidateAuthorizationRequestContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Authentication+ValidateRequestParameter. 2023-03-30 15:28:13.843 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ValidateAuthorizationRequestContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Authentication+ValidateRequestUriParameter. 2023-03-30 15:28:13.843 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ValidateAuthorizationRequestContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Authentication+ValidateClientIdParameter. 2023-03-30 15:28:13.843 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ValidateAuthorizationRequestContext was successfully processed by Volo.Abp.OpenIddict.WildcardDomains.AbpValidateRedirectUriParameter. 2023-03-30 15:28:13.843 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ValidateAuthorizationRequestContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Authentication+ValidateResponseTypeParameter. 2023-03-30 15:28:13.843 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ValidateAuthorizationRequestContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Authentication+ValidateResponseModeParameter. 2023-03-30 15:28:13.843 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ValidateAuthorizationRequestContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Authentication+ValidateScopeParameter. 2023-03-30 15:28:13.843 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ValidateAuthorizationRequestContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Authentication+ValidateNonceParameter. 2023-03-30 15:28:13.843 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ValidateAuthorizationRequestContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Authentication+ValidatePromptParameter. 2023-03-30 15:28:13.843 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ValidateAuthorizationRequestContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Authentication+ValidateProofKeyForCodeExchangeParameters. 2023-03-30 15:28:13.844 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ValidateAuthorizationRequestContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Authentication+ValidateClientId. 2023-03-30 15:28:13.844 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ValidateAuthorizationRequestContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Authentication+ValidateClientType. 2023-03-30 15:28:13.844 +02:00 [INF] Client validation failed because 'https://newtenant.ng.getabp.net:4200' was not a valid redirect_uri for BookStore_App. 2023-03-30 15:28:13.844 +02:00 [INF] The authorization request was rejected because the redirect_uri was invalid: 'https://newtenant.ng.getabp.net:4200'. 2023-03-30 15:28:13.845 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ValidateAuthorizationRequestContext was successfully processed by Volo.Abp.OpenIddict.WildcardDomains.AbpValidateClientRedirectUri. 2023-03-30 15:28:13.845 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ValidateAuthorizationRequestContext was marked as rejected by Volo.Abp.OpenIddict.WildcardDomains.AbpValidateClientRedirectUri. 2023-03-30 15:28:13.845 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ProcessRequestContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Authentication+ValidateAuthorizationRequest. 2023-03-30 15:28:13.845 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ProcessRequestContext was marked as rejected by OpenIddict.Server.OpenIddictServerHandlers+Authentication+ValidateAuthorizationRequest. 2023-03-30 15:28:13.845 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ProcessErrorContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+AttachErrorParameters. 2023-03-30 15:28:13.845 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ProcessErrorContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+AttachCustomErrorParameters. 2023-03-30 15:28:13.845 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ApplyAuthorizationResponseContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Authentication+AttachRedirectUri. 2023-03-30 15:28:13.845 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ApplyAuthorizationResponseContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Authentication+InferResponseMode. 2023-03-30 15:28:13.845 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ApplyAuthorizationResponseContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Authentication+AttachResponseState. 2023-03-30 15:28:13.845 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ApplyAuthorizationResponseContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Authentication+AttachIssuer. 2023-03-30 15:28:13.845 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ApplyAuthorizationResponseContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+Authentication+ProcessFormPostResponse. 2023-03-30 15:28:13.845 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ApplyAuthorizationResponseContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+Authentication+ProcessQueryResponse. 2023-03-30 15:28:13.845 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ApplyAuthorizationResponseContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+Authentication+ProcessFragmentResponse. 2023-03-30 15:28:13.845 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ApplyAuthorizationResponseContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+AttachHttpResponseCode1[[OpenIddict.Server.OpenIddictServerEvents+ApplyAuthorizationResponseContext, OpenIddict.Server, Version=4.0.0.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]]. 2023-03-30 15:28:13.845 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ApplyAuthorizationResponseContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+AttachCacheControlHeader1[[OpenIddict.Server.OpenIddictServerEvents+ApplyAuthorizationResponseContext, OpenIddict.Server, Version=4.0.0.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]]. 2023-03-30 15:28:13.845 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ApplyAuthorizationResponseContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+ProcessStatusCodePagesErrorResponse1[[OpenIddict.Server.OpenIddictServerEvents+ApplyAuthorizationResponseContext, OpenIddict.Server, Version=4.0.0.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]]. 2023-03-30 15:28:13.845 +02:00 [INF] The response was successfully returned as a plain-text document: { "error": "invalid_request", "error_description": "The specified 'redirect_uri' is not valid for this client application.", "error_uri": "https://documentation.openiddict.com/errors/ID2043" }. 2023-03-30 15:28:13.845 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ApplyAuthorizationResponseContext was successfully processed by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+ProcessLocalErrorResponse1[[OpenIddict.Server.OpenIddictServerEvents+ApplyAuthorizationResponseContext, OpenIddict.Server, Version=4.0.0.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]]. 2023-03-30 15:28:13.845 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ApplyAuthorizationResponseContext was marked as handled by OpenIddict.Server.AspNetCore.OpenIddictServerAspNetCoreHandlers+ProcessLocalErrorResponse1[[OpenIddict.Server.OpenIddictServerEvents+ApplyAuthorizationResponseContext, OpenIddict.Server, Version=4.0.0.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]]. 2023-03-30 15:28:13.845 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ProcessErrorContext was successfully processed by OpenIddict.Server.OpenIddictServerHandlers+Authentication+ApplyAuthorizationResponse1[[OpenIddict.Server.OpenIddictServerEvents+ProcessErrorContext, OpenIddict.Server, Version=4.0.0.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]]. 2023-03-30 15:28:13.845 +02:00 [DBG] The event OpenIddict.Server.OpenIddictServerEvents+ProcessErrorContext was marked as handled by OpenIddict.Server.OpenIddictServerHandlers+Authentication+ApplyAuthorizationResponse1[[OpenIddict.Server.OpenIddictServerEvents+ProcessErrorContext, OpenIddict.Server, Version=4.0.0.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]]. 2023-03-30 15:28:13.845 +02:00 [INF] Request finished HTTP/2 GET https://newtenant.api.getabp.net:44301/connect/authorize?response_type=code&client_id=BookStore_App&state=dzNETGhVck1GTX5lWTlPN2dualBLRWEzMkNFanVrU0p6bEoyeVE1dlN2VTJq&redirect_uri=https%3A%2F%2Fnewtenant.ng.getabp.net%3A4200&scope=openid%20BookStore&code_challenge=eniwwCG0YpcsO8_-qkxlwam-9YTiChcUYZ0lvGDy8Xg&code_challenge_method=S256&nonce=dzNETGhVck1GTX5lWTlPN2dualBLRWEzMkNFanVrU0p6bEoyeVE1dlN2VTJq&culture=en&ui-culture=en - - - 400 175 text/plain;charset=UTF-8 3.9318ms

Expected behavior

No response

Actual behavior

No response

Regression?

No response

Known Workarounds

No response

Version

7.0.0

User Interface

Angular

Database Provider

EF Core (Default)

Tiered or separate authentication server

None (Default)

Operation System

Windows (Default)

Other information

No response

dkaczor97 avatar Mar 30 '23 13:03 dkaczor97

'https://newtenant.ng.getabp.net:4200' was not a valid redirect_uri for BookStore_App.

I remember I tested it, and I will confirm it again.

maliming avatar Mar 31 '23 00:03 maliming

@maliming I'm not sure if it's related but I also noticed that there are different abp versions in angular (~7.1.0-rc.1) and backend (7.0.0)

dkaczor97 avatar Mar 31 '23 08:03 dkaczor97

hi @dkaczor97

Try to add options.WildcardDomainsFormat.Add("https://{0}.ng.getabp.net:4200/"); to https://github.com/abpframework/abp-samples/blob/master/DomainTenantResolver/OpenIddict/NG/aspnet-core/src/BookStore.HttpApi.Host/BookStoreHttpApiHostModule.cs#L66

maliming avatar Apr 04 '23 06:04 maliming

Yeah, I figured it out already. It was missing said WildcardDomainsFormat. Also it threw error when I was logging out. I had to add the AbpValidateAuthorizedParty class you mentioned here: https://support.abp.io/QA/Questions/4730/Blank-page-after-log-out#answer-3a0a193d-fbb8-6671-5e4b-891dcdcea347

dkaczor97 avatar Apr 04 '23 07:04 dkaczor97

For me, it works only like this (no trailing slash at the end)

options.WildcardDomainsFormat.Add("https://{0}.ng.getabp.net:4200");

Logout doesn't work even when adding AbpValidateAuthorizedParty as mentioned by @dkaczor97, getting this error

error:invalid_request
error_description:The client application is not allowed to use the specified identity token hint.
error_uri:https://documentation.openiddict.com/errors/ID2141

I've seen that in v7.2.0 (which is only in RC at the moment) there will be some fixes related to this, will wait until it is released and try again.

7.2.0-rc.1

szilardd avatar Apr 19 '23 06:04 szilardd