I am using asp.net web api 2.0 with asp.net identity 2.0. In GrantResourceOwnerCredentials
, I have code like following to generate identity
var claimsIdentity = user.GenerateIdentityAsync(authType);
claimsIdentity
is in turn used to create tokens. what I want to do is to create a subclass of ClaimsIdentity
and create tokens from that subclass like
public class CustomClaimsIdentity: ClaimsIdentity{
public CustomClaimsIdentity(int companyId){
this.AddClaim('currentCompany', companyId.ToString());
}
public int GetCompanyId(){
var claim = this.Claims.Single(x=>x.ClaimType == 'currentCompany');
return int.Parse(claim.Value);
}
}
There will be some other functionality in this subclass too. I want to create tokens from this subclass and also want to have it (CustomClaimsIdentity) attached to my controllers in some way, so I can get company id of user and do some other stuff.