honk
honk
CC#
Created by honk on 7/31/2024 in #help
MassTransit: UseConsumeFilter throws nullreference exception on startup if I have batch consumers
MassTransit config
services.AddMassTransit(config =>
{
config.AddConsumers(typeof(MyNonBatchConsumer).Assembly);

config.UsingAmazonSqs((context, cfg) =>
{
cfg.UsePublishFilter(typeof(LoggingPublishFilter<>), provider);
cfg.UseConsumeFilter(typeof(LoggingConsumeFilter<>), provider);

cfg.ReceiveEndpoint($"{typeof(Startup).Namespace?.Replace(".", "_")}_{environment.EnvironmentName}", receiveEndpointConfig =>
{
//tried registering the filter here as well, didn't work
receiveEndpointConfig.ConfigureConsumer<MyNonBatchConsumer>(context);
//Batch consumer
receiveEndpointConfig.ConfigureConsumer<MyBatchConsumer>(context);
});
}));
});

services.AddScoped(typeof(LoggingPublishFilter<>));
services.AddScoped(typeof(LoggingConsumeFilter<>));
services.AddMassTransit(config =>
{
config.AddConsumers(typeof(MyNonBatchConsumer).Assembly);

config.UsingAmazonSqs((context, cfg) =>
{
cfg.UsePublishFilter(typeof(LoggingPublishFilter<>), provider);
cfg.UseConsumeFilter(typeof(LoggingConsumeFilter<>), provider);

cfg.ReceiveEndpoint($"{typeof(Startup).Namespace?.Replace(".", "_")}_{environment.EnvironmentName}", receiveEndpointConfig =>
{
//tried registering the filter here as well, didn't work
receiveEndpointConfig.ConfigureConsumer<MyNonBatchConsumer>(context);
//Batch consumer
receiveEndpointConfig.ConfigureConsumer<MyBatchConsumer>(context);
});
}));
});

services.AddScoped(typeof(LoggingPublishFilter<>));
services.AddScoped(typeof(LoggingConsumeFilter<>));
Batch Consumer:
csharp
public class MyBatchConsumerHandler :
IIntegrationEventBatchHandler<MyBatchConsumer>
{
private readonly IMediator _mediator;

public MyBatchConsumerHandler(IMediator mediator)
{
_mediator = mediator;
}

public async Task Consume(ConsumeContext<Batch<MyBatchConsumer>> context)
{
//removed for brevity
}
}
csharp
public class MyBatchConsumerHandler :
IIntegrationEventBatchHandler<MyBatchConsumer>
{
private readonly IMediator _mediator;

public MyBatchConsumerHandler(IMediator mediator)
{
_mediator = mediator;
}

public async Task Consume(ConsumeContext<Batch<MyBatchConsumer>> context)
{
//removed for brevity
}
}
Program runs when I comment out the receiveEndpointConfig.ConfigureConsumer<MyBatchConsumer>(context);. I need filters for logging purposes. Has anyone else ran into this issue?
1 replies
CC#
Created by honk on 7/5/2024 in #help
ASP.NET Core 5 Identity reset password token is randomly invalid
Using IdentityServer4 + ASP.NET Core Identity with .NET 5. Our password reset endpoint throws errors, however, if I re-send the request a few times (the exact same request), it works again. Here's a summary of our process: after the user verifies, I generate the password reset token like this: var token = await _userManager.GeneratePasswordResetTokenAsync(user); Then I pass this token to the front end, which sends this token to the password reset endpoint, where this token is validated:
csharp
// removed rest of the code for brevity
if (user == null)
{
throw new CustomException(UserNotFoundException);
}
var isValid = await userManager.VerifyUserTokenAsync(user, userManager.Options.Tokens.PasswordResetTokenProvider, "ResetPassword", token);
if (!isValid)
{
throw new CustomException(InvalidTokenException);
}
return isValid;
csharp
// removed rest of the code for brevity
if (user == null)
{
throw new CustomException(UserNotFoundException);
}
var isValid = await userManager.VerifyUserTokenAsync(user, userManager.Options.Tokens.PasswordResetTokenProvider, "ResetPassword", token);
if (!isValid)
{
throw new CustomException(InvalidTokenException);
}
return isValid;
The VerifyUserTokenAsync method returns false most of the time, but after several retries (between 2 to 10 tries), it eventually works. This issue only occurs in our production environment; our testing environments do not exhibit this problem. The issue seems isolated to the PasswordResetTokenProvider, as our custom OTP provider functions correctly without failure. Steps I've taken so far: Verified that the token generated by GeneratePasswordResetTokenAsync and the token sent in the request are identical. Ensured the token is sent in the request body to prevent encoding/decoding mismatches. Confirmed that the SecurityStamp is not null during the process. Any idea what could be causing this? at this point I'm feeling lost and don't know where to look. One suspicion I have, is that there might be several instances of our identity app running, and that maybe causing the issue (although I don't know if that would cause an issue in the first place). I'd be happy to provide more code if needed. (reposted from SO, as I got no answers there :harold: ) Thanks!
3 replies
CC#
Created by honk on 5/19/2023 in #help
❔ Force log out the user after account deletion with JWT bearer auth.
Hello, I'm working on adding a feature that allows administrators to delete users. As things currently stand, when a user is deleted, their account is successfully removed, but their JWT token remains in the browser, allowing them to still access most of the website without any issues. I've come up with a few possible solutions, such as regularly checking from the frontend using an API call or websockets to see if the user has been deleted or not. However, I would prefer to use a built-in functionality if available. I came across SecurityStampValidationOptions, but it doesn't seem to work when I tried using it after AddIdentity with services.Configure<>. Is there a simpler way to achieve this?
15 replies
CC#
Created by honk on 2/16/2023 in #help
❔ Auto incremented Id not sequential
Hello, I have an auto increment on an Id(integer) column on a database, however values are not sequential. The gaps aren't caused by deletion, as we have no functionality for it on our website( unless someone is intentionally deleting them by hand :p ). For example, these are the Id's for the first 22 records from the db:
34
67
100
133
134
135
166
199
232
265
298
331
364
397
430
463
496
529
562
595
628
34
67
100
133
134
135
166
199
232
265
298
331
364
397
430
463
496
529
562
595
628
Is this something to worry about? I'm using EF core.
11 replies
CC#
Created by honk on 2/2/2023 in #help
❔ Performance of many small requests vs less but bigger requests
I have 2 projects: an API hosted on aws and a desktop application. Currently, I'm fetching around 4k records from an API(let's call these "ParentObjects"), each of them with a list of objects("ChildObjects") containing 50~ records on average. I'm fetching 10 ParentObjects at a time in a for loop, so in total, I'm hitting the API endpoint for around 400 times to display the full data. Would it be better to increase the number of fetched records per http request?
16 replies
CC#
Created by honk on 11/11/2022 in #help
❔ Does WebClient have the same socket exhaustion problem like HttpClient?
title
5 replies
CC#
Created by honk on 8/25/2022 in #help
Validating an object not received during a request(FluentValidation) [Answered]
Hi, I'm trying to achieve this: I receive Id and someRequest model from an endpoint(separate ID because I'm trying to comply to REST standards and don't want to cram [FromRoute] into the request model]. I also have a different someCommand model,the takes aforementioned id and model into the constructor and creates an object that will be queried against database)This model has validation using AbstractValidation<T> class of FluentValidation. I'm wondering, would these validators even work, considering I'm not receiving this model from the request?
10 replies