1

I have develop API to generate JWT token and hosted into MS Azure App Services.From Last couple of months we have issued around 1,000,00 token and now we want to clear/remove the all token from memory as per our business requirement.

If we not remove/clear the token from memory , It will still persist because we issue token for 1 years and it will consume our memory up to one years.

I have tried "Restart" option of app services but after restart, Previous generated token is still available in memory and we can access this JWT token.

Please suggest that how can we remove to previous generated token from Memory in MS App Services.

OUR MAIN OBJECTIVE TO REMOVE ALL PREVIOUS TOKEN FROM OUR MS AZURE APP SERVICES AND FREE TO MEMORY BECAUSE CURRENTLY OUR MOST OF MEMORY ARE TAKEN BY PREVIOUS TOKEN.

Thanks in advance!! Technologies:- C# .NET

using Microsoft.IdentityModel.Tokens;
using System.IdentityModel.Tokens.Jwt;
using System.Security.Claims;
public async static Task<string> GenerateToken(string userid, char type,string contactId)
        {
            string _userKeyCombination = userid+"|"+ contactId;
            byte[] key = Convert.FromBase64String(_SecretKey);
            SymmetricSecurityKey securityKey = new SymmetricSecurityKey(key);            
            SecurityTokenDescriptor descriptor = new SecurityTokenDescriptor();
            descriptor.Subject = new ClaimsIdentity(claims: new[] { new Claim(type: ClaimTypes.Name, 
                                 value: _userKeyCombination) });
            descriptor.Expires = DateTime.UtcNow.AddMonths(12));
            descriptor.SigningCredentials = new SigningCredentials(securityKey, algorithm: 
                                            SecurityAlgorithms.HmacSha256Signature);
            JwtSecurityTokenHandler handler = new JwtSecurityTokenHandler();
            JwtSecurityToken token = handler.CreateJwtSecurityToken(descriptor);
            string _token = handler.WriteToken(token);
            return _token;

        }

Ravi Kumar
  • 11
  • 1
  • Has your problem been solved? – Jason Pan Jul 28 '20 at 01:56
  • JWT tokens are not kept in the memory. They are just generated, signed using secret key and returned. To validate token you only need token (sent from client) and secret key. Token contains all the data - client ID, valid-to date, signed data, etc. Only client keeps his token, it's not kept on server side - it is valid for the time saved inside token. You can check what token contains on https://jwt.io – dey Jul 28 '20 at 05:58

0 Answers0