public Task Register(Nonce nonce)
        {
            if (nonce == null)
            {
                throw new ArgumentNullException(nameof(nonce));
            }

            var cacheKey = CacheKeyFactory(nonce.ClientId, nonce.Value);

            _cache.Set(cacheKey, nonce, nonce.Expiration);

            return(_decorated.Register(nonce));
        }
Ejemplo n.º 2
0
        public override async Task <SignatureVerificationFailure> Verify(HttpRequestForSigning signedRequest, Signature signature, Client client)
        {
            if (string.IsNullOrEmpty(signature.Nonce))
            {
                return(null);
            }

            var previousNonce = await _nonceStore.Get(client.Id, signature.Nonce).ConfigureAwait(false);

            if (previousNonce != null && previousNonce.Expiration >= _systemClock.UtcNow)
            {
                return(SignatureVerificationFailure.ReplayedRequest($"The nonce '{previousNonce.Value}' for client {client.Id} ({client.Name}) is not unique and has been used before. It expires at {previousNonce.Expiration:R}."));
            }

            var nonce = new Nonce(
                clientId: client.Id,
                value: signature.Nonce,
                expiration: _systemClock.UtcNow.Add(client.NonceLifetime));
            await _nonceStore.Register(nonce).ConfigureAwait(false);

            return(null);
        }
 public async Task Register(Nonce nonce)
 {
     using (await _lock.WriterLockAsync()) {
         await _decorated.Register(nonce);
     }
 }