HttpAuthClient constructor

HttpAuthClient({
  1. Client? client,
  2. required SharedPreferences sharedPreferences,
  3. String refreshTokenUrl(
    1. String token,
    2. JWT decodedToken
    )?,
  4. FutureOr<Map<String, String>> customRefreshTokenResponseParser(
    1. String body
    )?,
  5. String? refreshTokenMethod,
  6. Duration? maxAge,
  7. Duration? refreshTokenTimeout,
  8. FutureOr<Map<String, String>> customRefreshTokenRequestBodyFieldsMapper(
    1. String refreshToken,
    2. String authToken
    )?,
  9. FutureOr<String> customRefreshTokenRequestBodyMapper(
    1. String refreshToken,
    2. String authToken
    )?,
  10. void onRefreshToken(
    1. Map<String, String> tokens
    )?,
  11. void onRefreshTokenFailure(
    1. String token,
    2. Object exception
    )?,
  12. FutureOr<Map<String, String>> customRefreshTokenCallback(
    1. String token,
    2. String? refreshToken
    )?,
  13. Future<Request> customRefreshTokenRequestWrapper(
    1. Request request
    )?,
})

Implementation

HttpAuthClient({
  http.Client? client,
  required this.sharedPreferences,
  this.refreshTokenUrl,
  FutureOr<Map<String, String>> Function(String body)? customRefreshTokenResponseParser,
  String? refreshTokenMethod,
  Duration? maxAge,
  Duration? refreshTokenTimeout,
  FutureOr<Map<String, String>> Function(String refreshToken, String authToken)?
      customRefreshTokenRequestBodyFieldsMapper,
  this.customRefreshTokenRequestBodyMapper,
  this.onRefreshToken,
  this.onRefreshTokenFailure,
  this.customRefreshTokenCallback,
  this.customRefreshTokenRequestWrapper,
}) : assert(
        refreshTokenUrl == null || customRefreshTokenCallback == null,
        "You cannot define both 'refreshTokenUrl' & 'customRefreshTokenCallback' since the latest will override refresh logic behavior",
      ) {
  this.refreshTokenResponseParser = customRefreshTokenResponseParser ?? _defaultRefreshTokenResponseParser;
  this.refreshTokenMethod = "POST";
  this.refreshTokenRequestBodyFieldsMapper =
      customRefreshTokenRequestBodyFieldsMapper ?? _defaultCustomRefreshTokenRequestBodyFieldsMapper;
  this.refreshTokenTimeout = refreshTokenTimeout ?? const Duration(seconds: 15);

  _httpClient = client is http.Client ? client : http.Client();
  _refreshController = StreamController.broadcast();
}