IRequest losing InProcess RequestAttribute?

I have a custom credentials auth provider that overrides the built in CredentialsAuthProvider.
In the TryAuthenticateAsync method I want to check if it is an inprocess request.
What I have found is that IRequest.IsInProcessRequest() initially returns true, but after calling await authRepo.GetUserAuthByUserNameAsync(userName).ConfigAwait(); the result of IRequest.IsInProcessRequest() is false. I can also see that authService.Request.RequestAttributes changes from
Localhost | Secure | HttpPost | Reply | Json | Http | InProcess
to
Localhost | Secure | HttpPost | Reply | Json | Http

I am not sure this is a ServiceStack issue, but maybe you have an idea what could be happening?
Any help would be greatly appreciated!

The code (ServiceStack 6.02. Dotnet 6):

public override async Task<bool> TryAuthenticateAsync(IServiceBase authService, string userName, string password, CancellationToken token = default)
{ 
    IUserAuth userAuth;
    var authRepo = GetUserAuthRepositoryAsync(authService.Request);
    await using (authRepo as IAsyncDisposable)
    {
        Debug.WriteLine(authService.Request.IsInProcessRequest()); //=>True
        userAuth = await authRepo.GetUserAuthByUserNameAsync(userName).ConfigAwait();
        Debug.WriteLine(authService.Request.IsInProcessRequest()); //=>False
    }
}

Can’t see why it would be different from here, what AuthRepository are you using?

and what code are you using to call the Service in process?

Thanks! I’m using OrmliteAuthRepository (SQL Server db). I have been unable to reproduce the problem in a minimal application, but in that minimal app I was using InMemoryAuthRepository. I will do some more digging to see if changing to OrmliteAuthRepository makes a difference.

Code used to call the Service:

public Task<object> AuthenticateWithCredentialsAsync(IRequest request, string username, string password)
{
	using (var service = HostContext.ResolveService<AuthenticateService>(request))
	{
		return service.PostAsync(new Authenticate
		{
			provider = CredentialsAuthProvider.Name,
			UserName = username,
			Password = password
		});
	}
}

It’s because you’re not awaiting service.PostAsync() which causes the Service to be immediately disposed before it’s finished executing.

1 Like

Doh. Of course. Working now. Sorry for wasting your time! Just want to say that I am super impressed by your response time and quality! And not just this time. /Anders

1 Like