AuthInterceptor class

An interceptor that adds authentication headers to requests.

Inheritance

Constructors

AuthInterceptor({AuthType authType = AuthType.bearer, String? tokenProvider()?, String? username, String? password, String apiKeyHeaderName = 'X-API-Key', Map<String, String> customHeadersProvider()?, Future<bool> onUnauthorized()?, List<String> excludedEndpoints = const []})

Properties

apiKeyHeaderName String
The API key header name (for apiKey auth).
final
authType AuthType
The type of authentication.
final
customHeadersProvider Map<String, String> Function()?
Custom header name and value provider.
final
excludedEndpoints List<String>
Endpoints to exclude from authentication.
final
hashCode int
The hash code for this object.
no setterinherited
onUnauthorized Future<bool> Function()?
Callback when a 401 response is received. Return true to retry the request after refreshing the token.
final
password String?
The password (for basic auth).
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
tokenProvider String? Function()?
The authentication token (for bearer/apiKey).
final
username String?
The username (for basic auth).
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onError(ClientRequest request, Object error, int attemptCount) Future<bool>
Called when an error occurs. Return true to retry the request, false to propagate the error.
override
onRequest(ClientRequest request) Future<ClientRequest?>
Called before the request is sent. Return the modified request, or null to cancel the request.
override
onResponse(ClientRequest request, ClientResponse response) Future<ClientResponse>
Called after the response is received. Return the modified response.
override
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited