【问题标题】:Identity Server 4 Passing acr_values but not redirecting to external provider身份服务器 4 传递 acr_values 但不重定向到外部提供者
【发布时间】:2020-11-17 22:17:19
【问题描述】:

我们有 Idsrv 4 和另一个外部身份验证提供程序。这两个系统之间的集成很好,我们可以登录/重定向一切正常。

但它涉及到用户操作,他们仍然需要单击按钮来定义他们想要使用哪个外部提供程序。对于特定的用户组,我们希望跳过此步骤,并自动将用户重定向到直接登录到外部提供程序。

我了解到这种自动重定向可以通过使用与客户端的授权请求一起传递的acr_values 来实现。我尝试使用它,但仍然没有重定向到外部提供程序。

身份服务器设置: 我们设置了AuthenticationScheme -> demoidsrv 作为我们的外部提供者

services.AddAuthentication()
                        .AddOpenIdConnect("demoidsrv", "IdentityServer", options =>
                        {
                            options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
                            options.SignOutScheme = IdentityServerConstants.SignoutScheme;

                            options.Authority = "https://demo.identityserver.io/";
                            options.ClientId = "login";
                            options.ResponseType = "id_token";
                            options.SaveTokens = true;

                            options.Scope.Add(IdentityServerConstants.StandardScopes.OpenId);
                            options.Scope.Add(IdentityServerConstants.StandardScopes.Profile);
                            options.Scope.Add(IdentityServerConstants.StandardScopes.Email);

                            options.CallbackPath = "/signin-idsrv";
                            options.SignedOutCallbackPath = "/signout-callback-idsrv";
                            options.RemoteSignOutPath = "/signout-idsrv";
                        })

我们在OnRedirectToIdentityProvider 事件中通过了acr_values -> idp:demoidsrv。 Client Mvc App Startup.cs:

services.AddAuthentication(options =>
                {
                    options.DefaultScheme = "Cookies";
                    options.DefaultChallengeScheme = "oidc";
                })
                .AddCookie("Cookies", options =>
                {
                    options.AccessDeniedPath = "/AccessDenied";
                })
                .AddOpenIdConnect("oidc", options =>
                {
                    options.SignInScheme = "Cookies";
                    options.ClientId = "test.web.app1.hybrid";
                    options.ResponseType = "code id_token";
                    options.RequireHttpsMetadata = false; // to host it without Https
                    options.SaveTokens = true;
                    options.ClientSecret = "secret";

                    options.GetClaimsFromUserInfoEndpoint = true;
                    options.Scope.Add("openid");

                    //T1 Identity Server
                    options.Authority = Configuration.GetSection("MySettings").GetSection("IdentityServerUrl").Value;


                    options.Events = new OpenIdConnectEvents()
                    {
                        OnRedirectToIdentityProvider = ctx =>
                        {
                            ctx.ProtocolMessage.UiLocales = Thread.CurrentThread.CurrentUICulture.Name;
                            ctx.ProtocolMessage.AcrValues = "idp:demoidsrv";
                            return Task.CompletedTask;
                        }
                    };
                });

我检查了 redirect_uri,它确实在 AuthoriseRequest 中正确附加了 acr_values

http://localhost:5847/identityserver/connect/authorize?client_id=test.web.app1.hybrid&redirect_uri=http%3A%2F%2Flocalhost%3A64177%2Fsignin-oidc&response_type=code%20id_token&scope=openid%20offline_access&response_mode=form_post&nonce =637315373849113603&ui_locales=en-US&state=testStatewH&acr_values=idp%3Ademoidsrv&x-client-SKU=ID_NETSTANDARD2_0&x-client-ver=5.3.0.0

我想知道我是否需要通过检查此值来手动实现重定向,或者我是否缺少一些设置以使重定向自动发生?

【问题讨论】:

    标签: .net-core identityserver4


    【解决方案1】:

    据我所知,它不会自动重定向。我们必须手动检测发布的值并重定向到外部提供商。

    如果您提供acr_values,则可以在AuthorizationContextIdp 属性中检索它们。然后重定向到ChallengeExternalController的Action来模拟重定向。

    var context = await _interaction.GetAuthorizationContextAsync(returnUrl);
    
    // redirect to external Identity provider automatically, if requested
    if (string.IsNullOrWhiteSpace(context.IdP) == false)
    {
        var idp = context.IdP;
        return RedirectToAction("Challenge", "ExternalAuthentication",
            new
            {
                provider = idp,
                returnUrl
            });
    }   
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-10
      • 1970-01-01
      • 2013-06-07
      • 1970-01-01
      • 2017-08-12
      • 2018-09-23
      • 1970-01-01
      相关资源
      最近更新 更多