首页 > 解决方案 > Thinktecture Identity Server 4 和 SSO

问题描述

我正在做一个概念验证,将 OpenId Connect 引入我们的产品套件。经过多次讨论,我们决定为每个产品提供一个单独的、谨慎的 Javascript 应用程序 (Vuejs) 可能会更好,而不是将它们全部包含在一个单一的 SPA 中。

为此,我们实际上需要 Single Sign-On ("SSO")。我一直使用 IdentityServer 4 作为我们的 IDP。

RedirectUris通过为Idp 的相关客户端配置的属性提供多个 uri,我似乎取得了一些合理的成功。因此,这两个应用程序实际上是相同的 Client

这感觉不对,我想验证我是否正确地这样做。

这是涵盖 2 个 SPA(将涵盖所有 SPA)的客户端配置的配置。

new Client
{
    ClientName = "Some App",
    ClientId = "appsuiteid",

    AccessTokenLifetime = 330,// 330 seconds, default 60 minutes
    IdentityTokenLifetime = 300,
    AllowOfflineAccess = true,
    RefreshTokenUsage = TokenUsage.ReUse,
    RefreshTokenExpiration = TokenExpiration.Sliding,
    UpdateAccessTokenClaimsOnRefresh = true,
    RequireClientSecret = false,
    AllowedGrantTypes = GrantTypes.Code,
    
    AllowAccessTokensViaBrowser = true, 
    RedirectUris = new List<string>
    {
        "http://localhost:8080/authcallback.html",    <-- first 2 Uris for first SPA
        "http://localhost:8080/silent-refresh.html",
        "http://localhost:8090/authcallback.html",    <-- second 2 Uris for second SPA
        "http://localhost:8090/silent-refresh.html",
    },
    PostLogoutRedirectUris = new List<string>
    {
        "http://localhost:8080/signout-callback-oidc",
        "http://localhost:8090/signout-callback-oidc",
    },
    AllowedCorsOrigins = new List<string>
    {
        $"http://localhost:8080",
        $"http://localhost:8090",
    },
    AllowedScopes = new List<string>
    {       
        IdentityServer4.IdentityServerConstants.StandardScopes.OpenId,
        IdentityServer4.IdentityServerConstants.StandardScopes.Profile, 
    },
    ClientSecrets = { new Secret("somepwd".Sha256())}
}

请注意,如果我为每个 SPA 配置单独的客户端,则它不起作用,因为每个 SPA 都被重定向到该客户端的不同同意页面 - 从而失去了我们需要的 SSO 特征。

对此的任何指导都会很棒。

谢谢

标签: identityserver4

解决方案


推荐阅读