brockallen / BrockAllen.MembershipReboot

MembershipReboot is a user identity management and authentication library.
Other
742 stars 238 forks source link

IsInRole not work in membershipreboot #562

Closed amirhp closed 8 years ago

amirhp commented 9 years ago

Hi I add role from memberhip identity manager and seems roles add as claim in databasbe but User.IsInRole(rolename) ClaimsPrincipal.Current.IsInRole(rolename) always return false.

brockallen commented 9 years ago

This tells me you don't understand how IsInRole works. The user needs to logout and login again, since IsInRole works off of the identity produced from the cookie.

amirhp commented 9 years ago

I know always return false. is it something i missed?

pmbanugo commented 9 years ago

@amirhp there is a difference between role based authorization and claims based authorization. Your application is claims aware. In claims-aware applications, the role is expressed by a role claim type. check this https://msdn.microsoft.com/en-us/library/hh545448(v=vs.110).aspx to see if it clears your misunderstanding.

brockallen commented 9 years ago

Also, when you call IsInRole it's checking for a claim in the claims collection. That claim type depends on how the ClaimsIdentity was created.

amirhp commented 9 years ago

the role calim record seems fine so how can i check this claim exist for a user or not?

brockallen commented 9 years ago

How are you creating the ClaimsIdentity -- what are you using to authenticate the user? OWIN cookie authentication or WIF's SAM?

amirhp commented 9 years ago

Im using your groups sample. https://github.com/brockallen/BrockAllen.MembershipReboot/tree/master/samples/Groups

brockallen commented 9 years ago

I don't think the groups samples even does a user login, does it?

amirhp commented 9 years ago

yeah

amirhp commented 9 years ago

It does userAccountService.AuthenticateWithUsernameOrEmail(model.Username, model.Password, out account)

amirhp commented 9 years ago

so it use SamAuthenticationService

brockallen commented 9 years ago

That uses the ClaimTypes.Role claim type for IsInRole. If you're using IdentityManager, then it's adding the role with claim type "role".