示例#1
0
        /// <summary>
        /// Function to generate unique token with expiry against the provided userId.
        /// Also add a record in database for generated token.
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public TokenEntity GenerateToken(long userId)
        {
            string   token     = Guid.NewGuid().ToString();
            DateTime issuedOn  = DateTime.Now;
            DateTime expiredOn = DateTime.Now.AddSeconds(
                Convert.ToDouble(ConfigurationManager.AppSettings["AuthTokenExpiry"]));
            var tokendomain = new Token
            {
                UserId    = userId,
                AuthToken = token,
                IssuedOn  = issuedOn,
                ExpiresOn = expiredOn,
            };

            // Delete Previously Created Tokens for particular user
            DeleteByUserId(userId);

            _unitOfWork.TokenRepository.Insert(tokendomain);
            _unitOfWork.Save();
            var tokenModel = new TokenEntity()
            {
                UserId    = userId,
                IssuedOn  = issuedOn,
                ExpiresOn = expiredOn,
                AuthToken = token
            };

            return(tokenModel);
        }
示例#2
0
        public TokenEntity GenerateToken(int userId)
        {
            string   token       = Guid.NewGuid().ToString();
            DateTime issuedOn    = DateTime.Now;
            DateTime expiredOn   = DateTime.Now.AddSeconds(Convert.ToDouble(ConfigurationManager.AppSettings["AuthTokenExpiry"]));
            var      tokendomain = new Token
            {
                userId    = userId,
                authToken = token,
                issuedOn  = issuedOn,
                expiresOn = expiredOn
            };

            _unitOfWork.TokenRepository.Insert(tokendomain);
            _unitOfWork.Save();
            var tokenModel = new TokenEntity()
            {
                userId    = userId,
                issuedOn  = issuedOn,
                expiresOn = expiredOn,
                authToken = token
            };

            return(tokenModel);
        }
示例#3
0
        ///<summary>
        /// Generate token
        /// </summary>
        public TokenEntity GenerateToken(int userId)
        {
            string   token       = Guid.NewGuid().ToString();
            DateTime issuedOn    = DateTime.Now;
            DateTime expiredOn   = DateTime.Now.AddSeconds(900); // 15 minutes
            var      tokendomain = new Token
            {
                UserId    = userId,
                AuthToken = token,
                IssuedOn  = issuedOn,
                ExpiresOn = expiredOn
            };

            _unitOfWork.TokenRepository.Insert(tokendomain);
            _unitOfWork.Save();
            var tokenModel = new TokenEntity()
            {
                UserId    = userId,
                AuthToken = token,
                IssuedOn  = issuedOn,
                ExpiresOn = expiredOn
            };

            return(tokenModel);
        }