代码之家  ›  专栏  ›  技术社区  ›  LP13

如何在identity server 3中为Sustainsys外部提供程序设置acr值

  •  1
  • LP13  · 技术社区  · 7 年前

    我有 Idsvr3 https://github.com/Sustainsys/Saml2 我跟着 sample here

    现在,当用户访问客户机应用程序时,他将被重定向到login页面,该页面显示用于本地登录的userid/password文本框以及重定向到外部提供程序的按钮。

    我想改变这种行为。我希望用户直接转到外部登录基于某些条件。我已经 read that 我可以将所需的登录提供程序传递给 acr_values IdSvr3将直接转到外部提供商。

    以下是我如何注册外部提供商 IdSvr3 (注意为了简洁起见,删除了一些代码)

    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.Map("/identity", idsrvApp =>
            {
                var identityServerOptions = new IdentityServerOptions
                {
                    AuthenticationOptions = new AuthenticationOptions()
                    {                        
                    }
                    .Configure(ConfigureIdentityProviders),                    
                };
    
                idsrvApp.UseIdentityServer(identityServerOptions);
            });            
        }
    
        private void ConfigureIdentityProviders(IAppBuilder app, string signInAsType)
        {                           
                // SAML2
                var options = new Saml2AuthenticationOptions(false)
                {
                    SPOptions = new SPOptions
                    {
                        EntityId = new EntityId("https://localhost:44300/IdSrv3/Saml2"),
                    },
                    SignInAsAuthenticationType = signInAsType,
                    Caption = "SAML2p"
                };
    
                UseIdSrv3LogoutOnFederatedLogout(app, options);
    
                options.SPOptions.ServiceCertificates.Add(new X509Certificate2(
                    AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "/App_Data/Sustainsys.Saml2.Tests.pfx"));
    
                options.IdentityProviders.Add(new IdentityProvider(
                    new EntityId("https://stubidp.sustainsys.com/Metadata"),
                    options.SPOptions)
                {
                    LoadMetadata = true
                });
    
                app.UseSaml2Authentication(options);            
        }
    }
    

    这里是客户端应用程序启动

     public class Startup
        {
            public void Configuration(IAppBuilder app)
            {            
                app.UseCookieAuthentication(CK);
    
                app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
                {
                    Authority = "https://localhost:44300/identity",
                    Scope = "openid profile email",
                    ClientId = "XXXXXXXXXXXXXXX",
                    RedirectUri = "http://localhost:36102/",
                    ResponseType = "id_token",
                    SignInAsAuthenticationType = "Cookies",               
    
                    Notifications = new OpenIdConnectAuthenticationNotifications
                    {                    
                        RedirectToIdentityProvider = (n) =>
                        {
                            if (n.ProtocolMessage.RequestType == OpenIdConnectRequestType.AuthenticationRequest)
                            {
                               if(SomeCondition == true)
                               {
                                  n.ProtocolMessage.AcrValues = "idp:saml2";
                               }
                            }
    
                            return Task.FromResult(0);
                        }
                    }                
                });
            }        
        }
    

    但是,identity server抛出错误 External login error: provider requested saml2 is not a configured external provider

    有效名称是什么 Sustainsys/Saml2 提供程序及其配置位置?

    1 回复  |  直到 7 年前
        1
  •  1
  •   LP13    7 年前

    我想我找到了。这个 idp 实际上是 AuthenticationType 财产。 在IdentityServer3中设置外部提供程序时 Saml2AuthenticationOptions 默认情况下,将authenticationtype设置为 Saml2 所以在客户端应用程序中,我必须使用与 acr-values s 而不是资本 S . 当我换成 二甲胺 成功了。

    我还可以将authenticationtype重写为任何我想要的字符串,这很好,因为现在我可以设置多个支持SAML2协议的外部IdP,并通过它们的authenticationtype来区分它们

    我还发现这个文档很有用 https://media.readthedocs.org/pdf/saml2/latest/saml2.pdf

    看看okta是如何配置的 IdentityServer3 分段 2.5.4 Step 3: Configure your identity server with the new identity provider

    同样来自IdentityServer documentation

    AuthenticationType必须是唯一的值才能标识外部 生成的标记。此外,相同的值可用于 在授权/身份验证期间预先选择身份提供程序 使用acr_values参数的请求(有关更多信息,请参阅此 信息)。此值还用于限制允许的标识 客户端配置上的提供程序。

    推荐文章