diff --git a/README.md b/README.md index 6d18b07..2555d11 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Signs and validates HTTP requests. This projects can help you implements [HMAC](https://en.wikipedia.org/wiki/HMAC) signature to HTTP requests on flutter projects. -[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE) +[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE) [![Pub Package](https://img.shields.io/pub/v/requests_signature_dart.svg)](https://pub.dartlang.org/packages/requests_signature_dart) [![package publisher](https://img.shields.io/pub/publisher/requests_signature_dart.svg)](https://pub.dev/packages/requests_signature_dart/publisher) ## Getting Started @@ -28,6 +28,7 @@ Then do the following to add a `RequestsSignatureInterceptor` to your Dio client ```dart import 'package:requests_signature_dart/requests_signature_dart.dart'; +import 'package:requests_signature_dart/src/client/requests_signature_options.dart'; import 'package:dio/dio.dart'; void main() { diff --git a/example/example.dart b/example/example.dart new file mode 100644 index 0000000..b5ab6b6 --- /dev/null +++ b/example/example.dart @@ -0,0 +1,31 @@ +import 'package:requests_signature_dart/requests_signature_dart.dart'; +import 'package:requests_signature_dart/src/client/requests_signature_options.dart'; +import 'package:dio/dio.dart'; + +void main() { + // Instantiate Dio client. + final dio = Dio(); + + // Define signature options. + final signatureOptions = RequestsSignatureOptions( + clientId: 'your_client_id', // Your unique client ID + clientSecret: 'your_client_secret', // Your client secret key + headerName: + 'X-Request-Signature', // Name of the custom header for the signature + signaturePattern: + '{ClientId}:{Nonce}:{Timestamp}:{SignatureBody}', // Pattern for the signature header value + clockSkew: Duration( + seconds: 30), // Clock skew duration (30 seconds in this example) + disableAutoRetryOnClockSkew: + false, // Disable auto retry on clock skew if set to true + ); + + // Instantiate interceptor. + final interceptor = RequestsSignatureInterceptor( + signatureOptions, + dio, + ); + + // Add interceptor to Dio client. + dio.interceptors.add(interceptor); +} diff --git a/lib/src/client/dio_interceptor.dart b/lib/src/client/dio_interceptor.dart index 486e372..2162a74 100644 --- a/lib/src/client/dio_interceptor.dart +++ b/lib/src/client/dio_interceptor.dart @@ -32,6 +32,8 @@ class RequestsSignatureInterceptor extends Interceptor { /// /// Optionally, you can provide custom implementations for /// [signatureBodySourceBuilder] and [signatureBodySigner]. + /// + /// Optionally, you can provide a custom loigc to get the current time via [getTime]. RequestsSignatureInterceptor( this._options, this._dioInstance, { diff --git a/lib/src/core/exception/requests_signature_exception.dart b/lib/src/core/exception/requests_signature_exception.dart index d17f1ad..1dd6a78 100644 --- a/lib/src/core/exception/requests_signature_exception.dart +++ b/lib/src/core/exception/requests_signature_exception.dart @@ -1,6 +1,9 @@ +/// Exceptions thrown during Requests Signature processing. class RequestsSignatureException implements Exception { + /// Message to display when this exception is raised. final String message; + /// Constructs a new [RequestsSignatureException] with a given [message]. RequestsSignatureException(this.message); @override