在 SSO 情况下在哪里处理应用程序初始化?

Where to handle app initialization in SSO situation?

我有 App1 和 App2,使用 IdentityServer3 和 Active Directory 进行 SSO。

每个应用程序都有自己的用户和角色。我创建了一个 ClaimsTransformation OWIN 中间件,获取 user/roles,序列化到 cookie 中,然后返回后续调用。效果不错。

但是我在哪里处理初始用户注册?我不能在身份验证中这样做,因为如果 App1 用户登录,然后以新身份转到 App2,他将跳过身份验证。

如果我在中间件中这样做,当我尝试将用户重定向到 enroll/profile 页面时,该重定向再次被中间件命中,导致重定向循环。

有什么建议吗?谢谢。

算了,做错了。对于使用 Owin.Security.OpenIdConnect 的 .NET,应在 SecurityTokenValidated 中完成应用程序初始化。跳过身份验证问题是因为我没有设置cookie名称。

app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOption
  {
     SignInAsAuthenticationType = "Cookies",
     Notifications = new OpenIdConnectAuthenticationNotification 
     {
         SecurityTokenValidated = n => { ... }