Exemplo n.º 1
0
        public override async Task <AuthResult> ExecuteQueryAsync(RefreshSessionQuery query)
        {
            var now   = DateTime.UtcNow;
            var token = await hookrRepository
                        .ReadAsync((context, cancellationToken) => context
                                   .RefreshTokens
                                   .Include(x => x.User)
                                   .FirstOrDefaultAsync(x => !x.Used &&
                                                        x.ExpiresAt > now &&
                                                        x.Value
                                                        .Equals(query.RefreshToken),
                                                        cancellationToken), Token);

            if (token == null)
            {
                throw new RefreshTokenNotFoundException();
            }
            telegramUserIdProvider.Set(token.UserId);
            var result = await CreateAndSaveSessionAsync(token.User);

            token.Used = true;
            await hookrRepository.SaveChangesAsync();

            return(result);
        }
        private async Task <TelegramUser> GetOrCreateTelegramUser(TelegramUserDto dto)
        {
            var user = await hookrRepository
                       .ReadAsync((context, token) => context.TelegramUsers
                                  .AsNoTracking()
                                  .FirstOrDefaultAsync(x => x.Id == dto.Id, token),
                                  Token);

            if (user != null)
            {
                await UpdateTelegramUserAsync(hookrRepository.Context.Update(user).Entity, dto);

                return(user);
            }

            var createdUser = new TelegramUser
            {
                Id    = dto.Id,
                State = TelegramUserStates.Default
            };

            await UpdateTelegramUserAsync(hookrRepository.Context.Add(createdUser).Entity,
                                          dto);

            return(createdUser);
        }
Exemplo n.º 3
0
        public override async Task ExecuteCommandAsync(RevokeTokenCommand command)
        {
            var now   = DateTime.UtcNow;
            var token = await hookrRepository.ReadAsync((context, cancellationToken)
                                                        => context.RefreshTokens
                                                        .FirstOrDefaultAsync(x => !x.Used &&
                                                                             x.ExpiresAt > now &&
                                                                             x.Value.Equals(command.Token),
                                                                             cancellationToken),
                                                        Token);

            if (token == null)
            {
                throw new RefreshTokenNotFoundException();
            }

            token.Used = true;
        }
 protected override Task <TelegramUser> LoadAsync(int args, CancellationToken token = default)
 => hookrRepository
 .ReadAsync((context, cancellationToken) => context.TelegramUsers
            .AsNoTracking()
            .FirstOrDefaultAsync(x => x.Id == args, token), token);