Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 ?

What I have tried:

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);
        }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900