![](/img/trans.png)
[英]Shared authentication based on Identity Server 4 between MVC and SPA applications
[英]Identity Shared between Applications - Identity Framework C#.NET
我有2个应用程序,一个MVC 5主站点(A)和一个Web Api 2从属端点(B)托管在访问1个数据库的两台不同计算机上。
这些应用程序应基于表单身份验证共享身份验证和授权。 在(A)上通过身份验证后,推荐的实现方式是:
我尝试使用身份验证Cookie,如下所示:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
CookieName = "DefaultCookie",
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString("/auth/login"),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, User>(
validateInterval:TimeSpan.FromMinutes(20),
regenerateIdentity: (manager,user) => user.GenerateUserIdentityAsync(manager))
}
});
但是我还没有完全成功。
您可以自己动手,但IdentityServer4可以执行此类操作。 粗放1)MVC认证; 2)MVC获取ID令牌; 3)将请求传递给具有ID令牌的Web API; 4)Web API检查令牌是否有效并获得声明; 5)如果用户被授权,请执行操作; 6)只要令牌有效,重复3-5。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.