There is no session,viewbag,tempdata in core api. i want to pass one data to another controller.Here I WANT PASS USER ID TO ANOTHER CONTROLLER
public async Task
{
var user = await userManager.FindByNameAsync(model.Username);
if (user != null && await userManager.CheckPasswordAsync(user, model.Password))
{
var userRoles = await userManager.GetRolesAsync(user);
var authClaims = new List
{
new Claim(ClaimTypes.Name, user.UserName),
new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
};
foreach (var userRole in userRoles)
{
authClaims.Add(new Claim(ClaimTypes.Role, userRole));
}
var authSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["JWT:Secret"]));
var token = new JwtSecurityToken(
issuer: _configuration["JWT:ValidIssuer"],
audience: _configuration["JWT:ValidAudience"],
expires: DateTime.Now.AddHours(3),
claims: authClaims,
signingCredentials: new SigningCredentials(authSigningKey, SecurityAlgorithms.HmacSha256)
);
return Ok(new
{
token = new JwtSecurityTokenHandler().WriteToken(token),
username=user.UserName,
email=user.Email,
role=user.Role,
id=user.Id,
expiration = token.ValidTo
});
}
Arnab MukherjeePosted Jun 9, 2021, 6:28 AM
selvi jpPosted Jun 9, 2021, 5:30 AM
Rajendran SPosted Jun 8, 2021, 4:29 PM