Пример #1
0
        public async Task StoreUserLogin(string userId, string accessToken, string refreshToken, RefreshTokenDto oldToken = null)
        {
            if (oldToken.IsNotEmpty())
            {
                var existingUserLogin = _dbContext.UserLogins.FirstOrDefault(x =>
                                                                             x.AccessToken == oldToken.AccessToken &&
                                                                             x.RefreshToken == oldToken.RefreshToken &&
                                                                             x.UserId == oldToken.UserId
                                                                             );
                if (existingUserLogin.IsNotEmpty())
                {
                    existingUserLogin.AccessToken  = accessToken;
                    existingUserLogin.RefreshToken = refreshToken;
                    existingUserLogin.UpdateAt     = DateTime.Now;
                    _dbContext.UserLogins.Update(existingUserLogin);
                    await _dbContext.SaveChangesAsync();
                }
            }
            else
            {
                var userLogin = new UserLogin
                {
                    UserId       = userId,
                    AccessToken  = accessToken,
                    RefreshToken = refreshToken
                };
                await _dbContext.UserLogins.AddAsync(userLogin);

                await _dbContext.SaveChangesAsync();
            }
        }
        public async Task SaveRefreshTokenAsync(UserToken userToken, CancellationToken cancellationToken = default(CancellationToken))
        {
            await this.tokenStoreDbContext.UserToken.AddAsync(userToken, cancellationToken);

            await tokenStoreDbContext.SaveChangesAsync(cancellationToken);
        }