【发布时间】:2017-05-07 16:29:18
【问题描述】:
我使用 Identityserver3 作为 MVC 应用程序的授权服务器。因此,我的Startup 类是这样的:
public void Configuration(IAppBuilder app)
{
app.UseExternalSignInCookie();
JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies"
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
Authority = "http://localhost:5000/",
ClientId = "mvc",
RedirectUri = "http://localhost:12262/",
ResponseType = "id_token",
UseTokenLifetime = false,
SignInAsAuthenticationType = "Cookies"
});
}
这是我的IdentityUser 子类:
public class ApplicationUser : IdentityUser
{
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager)
{
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
userIdentity.AddClaim(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", this.Email));
userIdentity.AddClaim(
new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider",
this.Email));
return userIdentity;
}
public UserType UserType { get; set; }
....
}
这是我的Global.asax.cs:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.NameIdentifier;
}
但在我的Account/Register 视图中包含@Html.AntiForgeryToken() 的行中,我收到此错误:
类型的声明
'http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier' 提供的 ClaimsIdentity 中不存在。
我在 SO 上看到了一些类似问题的问题(可能没有在任何地方使用 Identityserver3),但他们的解决方案似乎不起作用,至少我使用它们的方式是这样。
【问题讨论】:
标签: c# asp.net-mvc identityserver3