Microsoft Owin Security - Claims Constructor Value

2019-08-09 06:32发布

I am a bit new to Owin security. I have a legacy application with a user table and a specific role defined in it for each user.

I am trying to implement a custom user manager and user store to look at that table and authorize users for my MVC application using the OOTB [Authorize(Roles = "Contributor")] attributes.

I had a piece of code working that did this in a very basic way using the standard Account controller with the customer user store below.

My problem is that the GetRolesAsync either isn't firing anymore or its getting an exception before it gets there from the Claims constructor:

Parameter name:

value
   at System.Security.Claims.Claim..ctor(String type, String value, String valueType, String issuer, String originalIssuer, ClaimsIdentity subject, String propertyKey, String propertyValue)
   at System.Security.Claims.Claim..ctor(String type, String value, String valueType)
   at Microsoft.AspNet.Identity.ClaimsIdentityFactory`1.<CreateAsync>d__0.MoveNext()

Any ideas why I would suddenly be seeing this exception since I am not really interested in Claims for the identity. Has there been some change in my examples thats working that has moved this from Roles based to Claims based security?

1条回答
我想做一个坏孩纸
2楼-- · 2019-08-09 07:24

I finally figured it out.

My ApplicationUser class had changed to set the Id to be PersonId recently. OOTB MVC and Owin use the Id value which was not being set properly. Ensuring that this was set fixed this behaviour.

Thanks

查看更多
登录 后发表回答