Problem
During an OpenIddict authorize challenge, changing language on /Account/Login does not stick. After reload, the dropdown still shows the culture from the first landing.
Example:
/Account/Login?ReturnUrl=/connect/authorize?...&ui-culture=zh-Hans
First load correctly becomes zh-Hans. After switching to another language, LanguageSwitchViewComponent still sees zh-Hans.
What we found
OpenIddictReturnUrlRequestCultureProvider reads culture / ui-culture from ReturnUrl and runs before the culture cookie.
On switch, AbpLanguagesController.Switch writes the cookie, then calls OpenIddictReturnUrlQueryStringCultureReplacement. That class only rewrites ReturnUrl when both culture and ui-culture already exist. If authorize has only ui-culture, ReturnUrl is left unchanged, so the next request reads the old value again and overrides the cookie.
IdentityServerReturnUrlQueryStringCultureReplacement looks the same.
Also in OpenIddictReturnUrlRequestCultureProvider:
var queryCulture = openIddictRequest.GetParameter(QueryStringKey).ToString();
var queryUICulture = openIddictRequest.GetParameter(UIQueryStringKey).ToString();
Missing parameters become "", not null, so the current == null / != null fallback between culture and ui-culture does not work as intended. string.IsNullOrEmpty / IsNullOrWhiteSpace would be safer here. That alone does not fix the switch issue though.
Feedback
I understand the client URL is incomplete if it only sends ui-culture without culture, and ideally the client should send both.
Still, the current behavior feels brittle: language switch updates the cookie, but an incomplete ReturnUrl silently wins afterward. Not sure what you prefer as the final design, just wanted to report this. Handling partial ReturnUrl on switch (upsert culture / ui-culture: replace if present, append if missing) would make this more resilient.
Environment
- ABP Account Pro + OpenIddict
- Reproduced on 10.7.0
3 Answer(s)
-
0
Hi,
When the authorize request only has
ui-culture,OpenIddictReturnUrlRequestCultureProviderreads the missingcultureas an empty string and doesn't use theui-culturevalue for it. So the login page gets the selected UI culture, but the culture falls back to your default culture, and the language dropdown is matched by that culture. Theui-culturein the ReturnUrl does get updated when you switch.You can replace the provider for now. Add this class to the project that hosts the login page:
using System; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Localization; using Volo.Abp.Account.Web.Pages.Account; public class MyOpenIddictReturnUrlRequestCultureProvider : OpenIddictReturnUrlRequestCultureProvider { public override async Task<ProviderCultureResult?> DetermineProviderCultureResult(HttpContext httpContext) { var result = await base.DetermineProviderCultureResult(httpContext); if (result == null) { return null; } var culture = result.Cultures.FirstOrDefault().Value; var uiCulture = result.UICultures.FirstOrDefault().Value; if (culture.IsNullOrWhiteSpace() && uiCulture.IsNullOrWhiteSpace()) { return null; } if (culture.IsNullOrWhiteSpace()) { culture = uiCulture; } else if (uiCulture.IsNullOrWhiteSpace()) { uiCulture = culture; } return new ProviderCultureResult(culture, uiCulture); } }Then register it in
ConfigureServicesof the module that depends onAbpAccountPublicWebOpenIddictModule:using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.RequestLocalization; using Volo.Abp.Account.Web.Pages.Account; Configure<AbpRequestLocalizationOptions>(options => { options.RequestLocalizationOptionConfigurators.Add((serviceProvider, localizationOptions) => { localizationOptions.RequestCultureProviders.ReplaceOne( x => x.GetType() == typeof(OpenIddictReturnUrlRequestCultureProvider), new MyOpenIddictReturnUrlRequestCultureProvider()); return Task.CompletedTask; }); });We'll fix this in an upcoming release. The fix also covers a ReturnUrl that only has
culture.Thanks
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post) -
0
Ok Thanks
Markdown supported.Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)