MVC 5 OWIN login with claims and AntiforgeryToken. Do I miss a ClaimsIdentity provider?

后端 未结 6 1831
别那么骄傲
别那么骄傲 2021-02-01 23:43

I\'m trying to learn Claims for MVC 5 OWIN login. I try\'ed to keep it as simple as possible. I started with the MVC template and inserted my claims code (see below). I get an e

6条回答
  •  生来不讨喜
    2021-02-01 23:58

    AntiForgeryConfig

    One way to solve it is to set AntiForgeryConfig to use other ClaimType.

    protected void Application_Start()
    {
        AreaRegistration.RegisterAllAreas();
    
        WebApiConfig.Register(GlobalConfiguration.Configuration);
        FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
        RouteConfig.RegisterRoutes(RouteTable.Routes);
        BundleConfig.RegisterBundles(BundleTable.Bundles);
    
        AntiForgeryConfig.UniqueClaimTypeIdentifier = ClaimTypes.Email;
    }
    

    Add NameIdentifier and IdentityProvider ClaimTypes

    Alternatively, you can add NameIdentifier and IdentityProvider ClaimTypes to your claims.

    List _claims = new List();
    _claims.AddRange(new List
    {
        new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", _user.Email)),
        new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider", _user.Email)
    })
    

    See: https://stack247.wordpress.com/2013/02/22/antiforgerytoken-a-claim-of-type-nameidentifier-or-identityprovider-was-not-present-on-provided-claimsidentity/

提交回复
热议问题