Ejemplo n.º 1
0
        /// <summary>
        /// Gets the state of the token.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="claims">The claims.</param>
        /// <param name="isRevoked">if set to <c>true</c> [is revoked].</param>
        /// <param name="isUsed">if set to <c>true</c> [is used].</param>
        /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
        private bool GetTokenState(string token, List <Claim> claims, out bool isRevoked, out bool isUsed)
        {
            isRevoked = false;
            isUsed    = false;

            if (string.IsNullOrEmpty(token) || claims == null || !claims.Any())
            {
                return(false);
            }

            JwtTokenUsedOrRevoked found = null;

            using (var db = new LiteDatabase(_tokenDataBase))
            {
                var tokens = db.GetCollection <JwtTokenUsedOrRevoked>(TOKEN_DATA_COLLECTION);
                found = tokens.Find(c => c.Token.Equals(token)).FirstOrDefault();

                if (found != null)
                {
                    isUsed    = found.IsUsed;
                    isRevoked = found.IsRevoked;
                }
            }

            return(found != null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Marks the token as used.
        /// </summary>
        /// <param name="token">The token.</param>
        private void MarkTokenAsUsed(string token)
        {
            using (var db = new LiteDatabase(_tokenDataBase))
            {
                var tokens = db.GetCollection <JwtTokenUsedOrRevoked>(TOKEN_DATA_COLLECTION);
                var found  = tokens.Find(c => c.Token.Equals(token)).FirstOrDefault();

                if (found == null)
                {
                    var record = new JwtTokenUsedOrRevoked
                    {
                        Token          = token,
                        IsUsed         = true,
                        ExpirationDate = token.GetExpirationDate(),
                        UsedDate       = DateTime.UtcNow
                    };

                    tokens.Insert(record);
                }
            }
        }