IAuthenticator.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. namespace Best.HTTP.Request.Authenticators
  2. {
  3. /// <summary>
  4. /// Represents an interface for various authentication implementations used in HTTP requests.
  5. /// </summary>
  6. public interface IAuthenticator
  7. {
  8. /// <summary>
  9. /// Set required headers or content for the HTTP request. Called right before the request is sent out.
  10. /// </summary>
  11. /// <remarks>
  12. /// <para>
  13. /// The SetupRequest method will be called every time the request is redirected or retried.
  14. /// </para>
  15. /// </remarks>
  16. /// <param name="request">The HTTP request to which headers or content will be added.</param>
  17. void SetupRequest(HTTPRequest request);
  18. /// <summary>
  19. /// Called when the server is sending a 401 (Unauthorized) response with an WWW-Authenticate header.
  20. /// The authenticator might find additional knowledge about the authentication requirements (like what auth method it should use).
  21. /// If the authenticator is confident it can successfully (re)authenticate the request it can return true and the request will be resent to the server.
  22. /// </summary>
  23. /// <remarks>
  24. /// More details can be found here:
  25. /// <list type="bullet">
  26. /// <item><description><see href="https://www.rfc-editor.org/rfc/rfc9110.html#status.401">RFC-9110 - 401 Unauthorized</see></description></item>
  27. /// <item><description><see href="https://www.rfc-editor.org/rfc/rfc9110.html#name-www-authenticate">RFC-9110 - WWW-Authenticate header</see></description></item>
  28. /// </list>
  29. /// </remarks>
  30. /// <param name="req">The HTTP request that received the 401 response.</param>
  31. /// <param name="resp">The HTTP response containing the 401 (Unauthorized) status.</param>
  32. /// <returns><c>true</c> if the challange is handled by the authenticator and the request can be re-sent with authentication.</returns>
  33. bool HandleChallange(HTTPRequest req, HTTPResponse resp);
  34. }
  35. }