Extend CredentialsAuthProvider to get additional html input form fields

I’m assuming based upon this question that if we need to access additional input fields other than username and password on Authenticate(...) that we would need to:

  1. Create new CredentialsAuthProvider that inherits from it
  2. Override the Authenticate(...) method
  3. Access new html input fields using authService.Request.FormData

Would that be correct way or is there a better way?
Is the CredentialsAuthProvider able to authenticate async?

The authService.Request.FormData is a NameValueCollection, is there an extension method or automapper that will map a NameValueCollection to specific DTO?

e.g. authService.Request.FormData.MapToDto(NewAuthenticateRequestDto)

Or is there extension method for authService.Request that would map it to a specific DTO?

You can reference existing fields from the IRequest object through any Request Filters or Session/Auth Event Hooks. Where you want to access and act on that info is up to you, if it’s required as part of Authentication then you’ll want to implement a new AuthProvider otherwise you may be able to add your custom logic in an Auth/Session Event hook.

The underlying HTTP Handler that executes the Authenticate Service is async but there’s no AuthProvider Authenticate() API that returns a Task.

Here’s what ServiceStack uses to Create a Request DTO from the incoming IRequest which is also populated from a custom [Route] and any registered Request Converters.

If you just want to Create a Request DTO from Request Params you can do it with something like:

var reqParams = httpReq.GetFlattenedRequestParams();
var typeDeserializer = new StringMapTypeDeserializer(typeof(MyRequest));
typeDeserializer.PopulateFromMap(typeof(MyRequest).CreateInstance(), reqParams);

Thanks. The event hooks looks like they wouldn’t work as we would need to do some things before OnAuthenticated as I’m assuming that is only called after a user is authenticated. Looks like we’ll need to go the custom AuthProvider.