根据客户定制登录页面 [英] Login page customized depending on client

查看:58
本文介绍了根据客户定制登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让登录页面知道哪个客户端请求登录以显示一些特定于客户的品牌:否则,用户可能会对其为何被重定向到另一个域上的此外部登录页面感到困惑.客户徽标将使他放心,他仍然处在正确的轨道上.

I would like to make the login page know which client requested the login in order to display some client-specific branding: Otherwise the user may be confused as to why he's redirected to this foreign login page on a different domain. A client logo will help reassure him that he's still on the right track.

获取该信息的最合理方法是什么?

What would be the most reasonable approach to get at that information?

请注意,客户端"是指进行身份验证的客户端Web应用程序,而不是用户的浏览器.所有客户都在我的控制之下,因此我只使用隐式工作流程.

Note that by "client" I'm referring to the client web applications on whose behalf the authentication happens - not the user's browser. All clients are under my control and so I'm using only the implicit workflow.

为了更加清楚:我有客户端Web应用程序A和B,以及身份服务器I.当用户代表B来到I时,B徽标应该出现,因为我们不再位于B的域中并且可能至少在不显示B相关品牌的情况下令人困惑.

To make this even more clear: I have client web apps A and B, plus the identity server I. When the user comes to I on behalf of B, the B logo should appear as we're no longer on B's domain and that may be confusing without at least showing a B-related branding.

推荐答案

某些理论

IdSrv 4获取ClientId的最简单方法是通过名为IIdentityServerInteractionService的服务,该服务在帐户控制器中用于获取AuthorizationContext.然后使用IClientStore服务进行后续处理,该服务允许您根据ClientId获取客户端详细信息.在获得这些详细信息之后,仅需将该信息发送到视图进行布局即可. IdSrv 4中的客户端模型具有LogoUri属性,您可以使用该属性在每个客户端登录时显示图像.

Some Theory

The easiest way to get the ClientId from IdSrv 4 is through a service called IIdentityServerInteractionService which is used in the Account Controller to get the AuthorizationContext. And then follow that up with the IClientStore service that allows you to get the client details given the ClientId. After you get these details then its only a matter of sending that info to the view for layout. The client model in IdSrv 4 has a LogoUri property that you can utilize to show an image at login per client.

    // GET: /Account/Login
    [HttpGet]
    [AllowAnonymous]
    public async Task<IActionResult> Login(string returnUrl = null)
    {
        var context = await _interaction.GetAuthorizationContextAsync(returnUrl);
        
        if (context?.IdP != null)
            // if IdP is passed, then bypass showing the login screen
            return ExternalLogin(context.IdP, returnUrl);

        if(context != null)
        {
            var currentClient = await _clientStore.FindClientByIdAsync(context.ClientId);

            if (currentClient != null)
            {
                ViewData["ClientName"] = currentClient.ClientName;
                ViewData["LogoUri"] = currentClient.LogoUri;
            }
        }

        ViewData["ReturnUrl"] = returnUrl;
        return View();
    }

这篇关于根据客户定制登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆