private static async Task UpdateSubjectRefreshTokensList(string token, RefreshTokenDescription desc, IRedisConnection c)
        {
            var skKey = SubjectRefreshTokensRedisKey.Create(desc.LoginRequest.Subject);
            var sk    = new RedisKey <SubjectRefreshTokenList>(skKey, c);
            var subjectRefreshTokenList = await sk.GetAsync();

            if (subjectRefreshTokenList != null)
            {
                var expiredRt = subjectRefreshTokenList
                                .Where(t => t.NotAfter < DateTime.Now)
                                .ToArray();
                foreach (var srt in expiredRt)
                {
                    subjectRefreshTokenList.Remove(srt);
                }
            }
            else
            {
                subjectRefreshTokenList = new SubjectRefreshTokenList();
            }

            subjectRefreshTokenList.Add(new SubjectRefreshToken
            {
                RefreshToken = token,
                NotAfter     = desc.NotAfter
            });

            await sk.SetAsync(subjectRefreshTokenList);
        }
        private static async Task SaveToken(string token, RefreshTokenDescription desc, IRedisConnection c)
        {
            var tkKey = RefreshTokenRedisKey.Create(token);
            var tk    = new RedisKey <RefreshTokenDescription>(tkKey, c);
            await tk.SetAsync(desc);

            await tk.SetExpirationAsync(desc.NotAfter - DateTime.Now);
        }
예제 #3
0
        public async Task Register(string authCode, LoginRequest request)
        {
            var keyName = LoginRedisKey.Create(authCode);

            using (var c = await _redisManager.GetConnection())
            {
                var requestKey = new RedisKey <LoginRequest>(keyName, c);

                await requestKey.SetAsync(request);

#if DEBUG
                bool setExpResult = await requestKey.SetExpirationAsync(TimeSpan.FromSeconds(15));
#else
                bool setExpResult = await requestKey.SetExpirationAsync(TimeSpan.FromMinutes(1));
#endif
                if (!setExpResult)
                {
                    throw new InvalidOperationException("Can't set expiration")
                          .AndFactIs("request", request)
                          .AndFactIs("key", keyName);
                }
            }
        }