I've implemented AuthenticateAsync based on this Microsoft example.
As per the example, AuthenticateAsync() contains
IPrincipal principal = await AuthenticateAsync(userName, password, cancellationToken);
which I have implemented to make a call to the SQL Server database via System.Data.SqlClient.SqlConnection (blocking on I/O) - which results in the warning
This async method lacks 'await' operators and will run synchronously.
The docs say AuthenticateAsync must return
A Task that will perform authentication.
I've considered
- Ignore the warning
- Not without knowing why Microsoft declared IAuthenticationFilter.AuthenticateAsync async. Perhaps IIS wants to defer execution?
- Wrap the blocking call in Task.Run()
- Could this double the number of expensive threads IIS is using?
What should I be doing?
Is it OK to block inside AuthenticateAsync?