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 ?
- public string GenerateTokens(string userId)
- {
- var Claims = new Claim[]
- {
- new Claim(JwtRegisteredClaimNames.Sub,userId)
- };
- var signingkey = new
- SymmetricSecurityKey(Encoding.UTF8.GetBytes("this is secret phrase"));
- var SigningCredntials = new SigningCredentials(signingkey,
- SecurityAlgorithms.HmacSha256);
- var Jwt = new JwtSecurityToken();
- var jsonu = new { id = userId };
- Jwt.Payload["user"] = jsonu;
- return new JwtSecurityTokenHandler().WriteToken(Jwt);
- }

Abhijeet JadhavRank #349 · 7.2K reputationPosted Sep 8, 2019, 3:25 AM EDT
ahmed elbarbaryRank #1,060 · 1.8K reputationPosted Sep 8, 2019, 4:00 AM EDT
ahmed elbarbaryRank #1,060 · 1.8K reputationPosted Sep 8, 2019, 4:08 AM EDT
ahmed elbarbaryRank #1,060 · 1.8K reputationPosted Sep 8, 2019, 6:40 AM EDT
Jaimin ShethiyaRank #177 · 13.7K reputationPosted Sep 24, 2019, 3:46 AM EDT
If you have multiple data return in API then can you use below example
public IActionResult PostUserLogins([FromBody] Users user)
{
...
...
var result = new { result1 = value1, result2 = value2 };
return Ok(result);
}
let me know if you have needed any other help.
Thanks