private async Task ValidateOfficeUserAsync(ResourceOwnerPasswordValidationContext context) { try { var exists = await _officeUserRepository.ExisteAsync(context.UserName, context.Password); if (!exists) { context.Result = BuildInvalidGrantValidationResult(); return; } var user = await _officeUserRepository.BuscarPorUsernameAsync(context.UserName); context.Result = new GrantValidationResult( subject: user.Codigo.ToString(), authenticationMethod: "custom", claims: user.Permissoes.AsSecurityClaims() ); } catch (Exception ex) { _logger.LogError(ex, ex.Message); context.Result = BuildInvalidGrantValidationResult(); } }
private async Task OfficeUserIsActiveAsync(IsActiveContext context) { var userId = context.Subject.Claims.First(c => c.Type == JwtClaimTypes.Subject); if (Guid.TryParse(userId.Value, out var guidId)) { context.IsActive = await _officeUserRepository.ExisteAsync(guidId); } }