IdentityServer Facebook Auth 更改主题 id / 不是 facebook id

IdentityServer Facebook Auth changes subject id / is not the facebook id

我启用了 IdentityServer 以使用隐式流向 Facebook 进行身份验证。

现在,当我通过身份验证时,我得到一个 id 值作为主题。像 502967fe0125ce3ff75050ef7b83fd68 我用它作为用户 ID 来存储用户相关数据。但是有时候主题的内容好像变了,我得到了不同的id。

我是不是误解了主题的概念。估计是chagning?

subject id 不应该是常量吗? 我应该使用哪些信息来存储用户相关数据?

这是我在身份服务器中配置 facebook 提供商的方式:

 public static void Configure(IAppBuilder app, string signInAsType)
        {
            var fb = new FacebookAuthenticationOptions
            {
                AuthenticationType = "Facebook",
                Caption = "Facebook",
                SignInAsAuthenticationType = signInAsType,
                AppId = myAppId,
                AppSecret = mySecret 
            };
            app.UseFacebookAuthentication(fb);
        }

这是网站中的客户端配置

   JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();

        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = "cookies"
        });

        app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
        {
            AuthenticationType = "oidc",
            SignInAsAuthenticationType = "cookies",

            ClientId = "website",
            Authority = identServer,
            RedirectUri = "http://localhost/pluto/",
            ResponseType = "id_token token",
            Scope = "openid profile email warehouseapi"
        }

找到原因了。返回的 sub 中的 id 是身份服务器的用户 id 而不是 facebook id。当我使用内存实现时,每次重新启动身份服务器时,id 都会更改。

所以对我来说这已经结束了,但仍有疑问这是否是一种可取的行为。

是否应该更像是主题的 facebook id?

子声明表示用户在STS上下文中的唯一标识符。

这通常意味着在用户第一次登录时创建一个新的子。然后这个子与外部登录(发行者名称和外部子)相关联并重新使用。