Security.Jwt icon indicating copy to clipboard operation
Security.Jwt copied to clipboard

Generate new Key before expiration of old key

Open shubhambothara opened this issue 3 years ago • 2 comments

Is there a way to generate a new key before expiration of old key so that client can replace the old key?

shubhambothara avatar Jul 01 '22 09:07 shubhambothara

Yes, it's possible.

The best way is:

First inject IJwtStore and revoke the current key, then generate new one.

public RevokeMyKey(IJsonWebKeyStore store, IJwtService service)
{
     _store = store;
     _service = service;
}

public RevokeCurrentKey()
{
        var oldCurrent = await _store.GetCurrent();
        /*Remove private key material*/
        await _store.Revoke(oldCurrent);
       var newCurrent = _service.GenerateKey();
}

brunobritodev avatar Jul 04 '22 19:07 brunobritodev

For those who came into this:

We'll add a new feat: Revoke current and generate new key:

await _service.GenerateNewKey();

brunobritodev avatar Jul 04 '22 19:07 brunobritodev