Example #1
0
        public async Task <SecurityKey> GetCurrentSecurityKey()
        {
            var current = await _store.GetCurrent();

            if (NeedsUpdate(current))
            {
                // According NIST - https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf - Private key should be removed when no longer needs
                await _store.Revoke(current);

                var newKey = await GenerateKey();

                return(newKey);
            }

            // options has change. Change current key
            if (!await CheckCompatibility(current))
            {
                current = await _store.GetCurrent();
            }

            return(current);
        }
    public async Task ShouldNotThrowExceptionWhenGetSignManyTimes()
    {
        await GenerateKey();

        var currentA = await _store.GetCurrent();

        var currentB = await _store.GetCurrent();

        var currentC = await _store.GetCurrent();

        var currentD = await _store.GetCurrent();

        var token = new SecurityTokenDescriptor()
        {
            Issuer             = "test.jwt",
            Subject            = new ClaimsIdentity(),
            Expires            = DateTime.UtcNow.AddMinutes(3),
            SigningCredentials = new SigningCredentials(currentD.GetSecurityKey(), _options.Value.Jws)
        };
    }