Exemplo n.º 1
0
        public AuthToken GetNewTokenForUser(ApiUser user)
        {
            string key = user.Secret;
            string data = user.UserName + user.Password + user.GetHashCode() + randomGen.Next();

            string hash = _hashProvider.GetHash(key, data);

            var resultToken = new AuthToken
            {
                Value = hash,
                ApiUser = user,
                Expiration = DateTime.Now.AddMinutes(DEFAULT_TOKEN_TIME_IN_MINUTES),
                IsActive = true
            };

            _tokenRespository.Add(resultToken);

            return resultToken;
        }
Exemplo n.º 2
0
        public AuthToken GetActiveTokenForUser(ApiUser user)
        {
            AuthToken activeToken = _tokenRespository.Get(token => token.IsActive).FirstOrDefault();

            return activeToken;
        }