Open Closed

Active language synchronisation between UI and auth-server. #6253


User avatar
0
mgurer created
  • ABP Framework version: v7.4.1
  • UI Type: Blazor
  • Database System: PostgreSQL
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes
  • Exception message and full stack trace:
  • Steps to reproduce the issue: Hello, I have a vue client app and I use authserver with authorization_code flow to authenticate my users. I want to synchronise active language between these apps. I want to pass the active language code to authserver and set the current language and also when I switch the active language on authserver side, I want to transfer the new language to vue app after authentication completes. Maybe I may add an extra parameter to redirect url, but I could not figure out how to do that. Can you help for that? This synchronisation issue also exists between built in blozor ui app and auth-server too. Thanks.

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

    hi

    You can use the culture parameter on the query string.

    http://authserver:5000/?culture=es-MX&ui-culture=es-MX

    https://account.abp.io/Account/Login?culture=tr&ui-culture=tr https://account.abp.io/Account/Login?culture=zh&ui-culture=zh

  • User Avatar
    0
    mgurer created

    Hi,

    Thanks. This resolves half of my problem. Now I can control the language of Auth-Server.

    The second part of my question still needs to be answered?

    When I change the UI language on Auth-Server, how can I transfer this info back to the original calling UI. The login process completes by redirecting back to redirect_url parameter passed to auth-server from calling ui app. I need to manipulate this redirect_url before actualy redirecting it.

    Here is an example;

    • https://authserverul/connect/authorize?response_type=code&client_id=psp_swagger_client&redirect_uri=https%3A%2F%2Fmyuiapp%2Fswagger%2Foauth2-redirect.html&scope=AccountService&state=V2VkIE5vdiAyOSAyMDIzIDA5OjM5OjA1IEdNVCswMzAwIChHTVQrMDM6MDAp&culture=en-EN&ui-culture=en-EN This opens authserverurl and has a redirect_uri in it. authserver redirects back to this redirect_uri. I need to add ui-culture info into this redirect_uri so that calling ui app can detect the ui-language selection change occured in auth-server site.
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    I remember the authserver will change the returnUrl when changing the language.

    https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Localization/AbpLanguagesController.cs#L47

  • User Avatar
    0
    mgurer created

    well, I have checked the code. the value of the context.returnurl is url encoded so related regex expressions never works as expected. there is an issue there.

    furthermore if regex gets fixed, it will not work either, at least for my case. because, returnurl contains the original return_uri(double-encoded) and when we alter the return_uri by replacing culture params, there is an inner security check that expects return_uri not to be altered which throws error indicating that uri is altered. this check is part of authorization code flow, and makes sense. otherwise some one in the middle could alter the returl_url and take control.

    so, i guess i need to alter return_uri just before the redirection so that return_uri security checks passes.

    public virtual Task ReplaceAsync(QueryStringCultureReplacementContext context) { if (!string.IsNullOrWhiteSpace(context.ReturnUrl)) { if (context.ReturnUrl.Contains("culture=", StringComparison.OrdinalIgnoreCase) && context.ReturnUrl.Contains("ui-Culture=", StringComparison.OrdinalIgnoreCase)) { context.ReturnUrl = Regex.Replace( context.ReturnUrl, "culture=[A-Za-z-]+", $"culture={context.RequestCulture.Culture}", RegexOptions.Compiled | RegexOptions.IgnoreCase);

                context.ReturnUrl = Regex.Replace(
                    context.ReturnUrl,
                    "ui-culture=[A-Za-z-]+",
                    $"ui-culture={context.RequestCulture.UICulture}",
                    RegexOptions.Compiled | RegexOptions.IgnoreCase);
            }
        }
    
        return Task.CompletedTask;
    }
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    so, i guess i need to alter return_uri just before the redirection so that return_uri security checks passes.

    We override some validate services. You can add yours.

    https://github.com/abpframework/abp/tree/dev/modules/openiddict/src/Volo.Abp.OpenIddict.AspNetCore/Volo/Abp/OpenIddict/WildcardDomains

  • User Avatar
    0
    mgurer created

    thanks.. it helps..

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09