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

后端 未结 6 1828
别那么骄傲
别那么骄傲 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:54

    Your claim identity does not have ClaimTypes.NameIdentifier, you should add more into claim array:

    var claims = new List
    {
        new Claim(ClaimTypes.Name, "username"),
        new Claim(ClaimTypes.Email, "user@gmail.com"),
        new Claim(ClaimTypes.NameIdentifier, "userId"), //should be userid
    };
    

    To map the information to Claim for more corrective:

    ClaimTypes.Name => map to username
    ClaimTypes.NameIdentifier => map to user_id
    

    Since username is unique also, so you are able to use username for anti-forgery token support.

提交回复
热议问题