使用OpenId时如何使用AuthenticationManager登录

使用OpenId时如何使用AuthenticationManager登录,authentication,cookies,model-view-controller,openid,owin,Authentication,Cookies,Model View Controller,Openid,Owin,我们需要提供混合模式身份验证,我们花了数周的时间寻找样本和细节,最终我们正确构建了我们的索赔实体,我们只需要找到一种方法让OWIN将我们的索赔实体识别为登录用户 到目前为止,我们找到的所有内容都是在Startup.Auth.ConfigureAuth()中定义app.UseCookieAutentication。设置AuthenticationType=“Cookies”,然后设置登录路径 但是,我们使用Identity Server 3的自定义版本,除了UseCookieAuthenticat

我们需要提供混合模式身份验证,我们花了数周的时间寻找样本和细节,最终我们正确构建了我们的索赔实体,我们只需要找到一种方法让OWIN将我们的索赔实体识别为登录用户

到目前为止,我们找到的所有内容都是在Startup.Auth.ConfigureAuth()中定义app.UseCookieAutentication。设置AuthenticationType=“Cookies”,然后设置登录路径

但是,我们使用Identity Server 3的自定义版本,除了UseCookieAuthentication之外,我们还使用app.UseOpenIdConnectAuthentication

我们在设置UseCookieAuthenticationLoginPath时遇到问题。我们试着把东西放进去,然后让它空着

我们用来登录Windows用户、调用IdentityServer、获取令牌和声明的代码

然后我们使用UserManager.CreateIdentityAsync,如下所示

var_identity=wait_userManager.CreateIdentityAsync(_slUser,DefaultAuthenticationTypes.applicationOkie)

这里一切都很好

然后,我们将该标识与以下代码一起使用:

var_ctx=HttpContext.Current.GetOwinContext()

var\u authenticationManager=\u ctx.Authentication; _SignIn(新的AuthenticationProperties(){IsPersistent=false},_identity)

代码运行,但当我们检查_ctx.Authentication.User时,我们创建的标识仍然没有显示,这导致用户被重定向到标识服务器上的登录页面


总之,我们正在试图找出如何获取我们在代码中验证和构建的索赔实体,并使其成为OwinContexts Authentication.User.identifications的一部分,以便在整个应用程序中都可用。

在这篇文章之后,我找到了一篇关于如何创建您自己的AuthenticationHandler的文章。在aspx文件中,我们正在为windows用户手动验证和生成ClaimsPrincipal,只是为了测试,我们正在将ClaimsPrincipal分配给会话。然后在AuthenticateCoreAsync()中,我们使用该ClaimsPrincipal生成并返回AuthenticationTicket。此时,将填充OwinContext用户,但当用户到达需要授权的主页时,OwinContext用户标识将返回到通用主体