Open Closed

Account Pro OpenIddict: language switch on login does not update when ReturnUrl has only ui-culture #10960


User avatar
0
yuxianglong created

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
Markdown supported.
Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)

3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Hi,

    When the authorize request only has ui-culture, OpenIddictReturnUrlRequestCultureProvider reads the missing culture as an empty string and doesn't use the ui-culture value 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. The ui-culture in 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 ConfigureServices of the module that depends on AbpAccountPublicWebOpenIddictModule:

    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)
  • User Avatar
    0
    yuxianglong created

    Ok Thanks

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    : )

    Markdown supported.
    Copy, paste, or drag & drop images and files (max 100 MB per file, 100 MB total per post)
Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.8.0-preview. Updated on November 16, 2026, 06:26
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.