ahmed elbarbary

ahmed elbarbary

  • NA
  • 1.6k
  • 254.6k

How to return access token as json result ?

Sep 7 2019 9:09 AM
Problem
How to return Access Token as json result ?
I work on asp.net core 2.2 from function below i generate access token
it is success generated as string but i need to generated as json
How to generate access token as json from function below ?
  1. public string GenerateTokens(string userId)  
  2. {  
  3.     var Claims = new Claim[]  
  4.     {  
  5.         new Claim(JwtRegisteredClaimNames.Sub,userId)  
  6.     };  
  7.     var signingkey = new   
  8.     SymmetricSecurityKey(Encoding.UTF8.GetBytes("this is secret phrase"));  
  9.     var SigningCredntials = new SigningCredentials(signingkey,   
  10.     SecurityAlgorithms.HmacSha256);  
  11.     var Jwt = new JwtSecurityToken();  
  12.     var jsonu = new { id = userId };  
  13.     Jwt.Payload["user"] = jsonu;  
  14.     return new JwtSecurityTokenHandler().WriteToken(Jwt);  
  15. }  

Answers (5)