Is there any way to return more data to the client with the bearer token?
I have written the below code using OAuthBearerAuthentication but unable to return more data. I am only getting "token", "token-type" and "expires in".
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
using (UserMasterRepository _repo = new UserMasterRepository())
{
var user = _repo.ValidateUser(context.UserName, context.Password);
if (user == null)
{
context.SetError("invalid_grant", "Provided username and password is incorrect");
return;
}
var identity = new ClaimsIdentity(context.Options.AuthenticationType);
identity.AddClaim(new Claim(ClaimTypes.Role, (user.role_id).ToString()));
identity.AddClaim(new Claim(ClaimTypes.Name, user.user_name));
identity.AddClaim(new Claim("Email", user.user_email));
identity.AddClaim(new Claim("Phone Number", user.user_phone_no));
context.Validated(identity);
}
}
I require more information about the user. For example, I have a tbl_user field in the database. Can I include other information about the user to return, other than "access_token", "token_type" and "expires_in"? If not, how can I get the user in the API based on the access_token?
Any help will be highly appreciated!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…