【发布时间】:2019-01-21 01:24:00
【问题描述】:
我有一个旧的 ASP.Net MVC 5 应用程序,它已经实现了身份框架以将用户登录到网站。我们已经开始转向微服务架构,现在需要对向 api 发出的请求进行身份验证(api 位于 .net 核心中)。
我已经成功地创建了一个身份服务器,并使用邮递员和 ResourceOwnerPasswordAndClientCredentials 流程创建了 jwt 令牌,并在 API 上对用户进行身份验证,同时还可以提取声明。
mvc 应用程序有一个类似于 airbnb 的登录页面(登录表单是主页上的弹出窗口),因此将网站重定向到身份服务器并不是一个真正的选择。
问题是我应该使用什么流程?
我的客户端在身份服务器中目前如下所示:
new Client
{
ClientId = "ClientWebsite",
ClientSecrets = new[] { new Secret("secret".Sha256()) },
AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials,
AllowedScopes = new[] {
"WebsiteAPI",
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Email
}
},
正如提到的在客户端网站已经设置为使用 Cookie Authentication 进行身份验证,启动看起来像这样:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
LoginPath = new PathString(Settings.FormsAuthPath),
Provider = new CookieAuthenticationProvider
{
OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
validateInterval: TimeSpan.FromMinutes(30),
regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
}
});
我知道我需要在此之后添加一些内容。任何帮助将不胜感激。
【问题讨论】:
标签: c# asp.net-mvc asp.net-identity identityserver4 identityserver3