Skip to content

Commit

Permalink
chore: adding missing documentation and example to increase score on …
Browse files Browse the repository at this point in the history
…pub.dev
  • Loading branch information
Kevin Takla committed Apr 25, 2024
1 parent 3cea562 commit 73ba2e0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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() {
Expand Down
31 changes: 31 additions & 0 deletions example/example.dart
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 2 additions & 0 deletions lib/src/client/dio_interceptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
3 changes: 3 additions & 0 deletions lib/src/core/exception/requests_signature_exception.dart
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 73ba2e0

Please sign in to comment.