sigv4 3.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 84
logo-long

sigv4 pub style: pedantic license

A Dart library for signing AWS requests with Signature Version 4.

Usage #

Create a Sigv4Client. This will hold your secrets and configuration. Some omitted default values:

  • region defaults to eu-west-1
  • serviceNamedefaults to execute-api
final client = Sigv4Client(
  keyId: 'your_access_key_id',
  accessKey: 'your_access_key',
  region: 'eu-west-1',.
  serviceName: 'execute-api',
);

The easier way to create a request is by getting a package:http request object:

// A simple GET-request
final request = client.request('https://service.aws.com/endpoint');

get(request.url, headers: request.headers);

// A larger request
final request = client.request(
  'https://service.aws.com/endpoint',
  method: 'POST',
  query: {'key': 'value'},
  headers: {'header': 'value'},
  body: {'content': 'some-content'},
);

post(request.url, headers: request.headers, body: request.body);

Alternatively, you can get the canonical string and signed headers separately:

final path = 'https://service.aws.com/endpoint';
final query = {'key': 'value'};

final url = client.canonicalUrl(path, query: query);
final headers = client.signedHeaders(
  path,
  query: query,
);

get(url, headers: headers);

Extensions #

As of Dart 2.7.0, extensions were introduced. As of this release, sigv4 has extensions for these HTTP clients, as well as any source gen package built on these:

  • http
  • dio
  • chopper

All extensions adds a .sign() method to the request object which uses the client to sign the request. Example using Dio:

  final dio = RequestOptions(method: 'GET', path: 'https://service.aws.com').sign(client);

Changelog #

3.1.2 #

  • Fixed incorrect string for non-payload S3 requests (@jfrsbg)

3.1.1 #

  • Added signPayload and encoding parameters to support S3 signed payloads

3.1.0 #

  • service and region parameters are now required

3.0.0+1 #

  • External image reference in readme

3.0.0 #

  • Added/clarified documentation
  • Added extensions for http, dio and chopper

BREAKING CHANGES #

Renamed some parameters to be more consistent with AWS's documentation

  • accessKey => keyId
  • secretKey => accessKey

2.1.0+2 #

  • Removed too complex signature text (dependent on current datetime)

2.1.0+1 #

  • Formatting

2.1.0 #

  • Fixed request headers type mismatch
  • Added tests

2.0.1 #

  • Fixed non-string query parameter type errors
  • Tweaked readme

2.0.0 #

BREAKING CHANGES: #

  • Removed Sigv4Request, only Sigv4Client is needed

  • Exposed methods for building headers and canonical path independently

  • Exposed a wrapper method that returns a http Request object

  • Added documentation and README

1.0.0 #

  • Initial version

example/example.dart

import 'package:dio/dio.dart';
import 'package:http/http.dart';
import 'package:sigv4/sigv4.dart';

/// This sample contains several placeholders for otherwise secret keys
/// and values, and will not run before you provide valid values and
/// a valid endpoint.
void main() {
  final client = Sigv4Client(
    keyId: 'your_access_key_id',
    accessKey: 'your_access_key',
    region: 'eu-west-1',
    serviceName: 'execute-api',
  );

  // Some fictive endpoint
  final path = 'https://service.aws.com/endpoint/replace-this-placeholder';

  // Create the request
  var request = client.request(path);

  // GET request
  get(request.url, headers: request.headers);

  // A larger request
  final largeRequest = client.request(
    path,
    method: 'POST',
    query: {'key': 'value'},
    headers: {'header': 'value'},
    body: {'content': 'some-content'},
  );

  // POST request
  post(largeRequest.url, headers: largeRequest.headers, body: largeRequest.body);

  final query = {'key': 'value'};

  final url = client.canonicalUrl(path, query: query);
  final headers = client.signedHeaders(
    path,
    query: query,
  );

  // GET request
  get(url, headers: headers);

  // Extensions on `http` Request objects
  Request('GET', Uri.parse(path)).sign(client);

  // Extensions on `dio` RequestOptions objects
  RequestOptions(method: 'GET', path: path).sign(client);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  sigv4: ^3.1.2

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:sigv4/sigv4.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
67
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
84
Learn more about scoring.

We analyzed this package on Jan 19, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.0
  • pana: 0.13.4

Health suggestions

Format lib/src/client.dart.

Run dartfmt to format lib/src/client.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
chopper ^3.0.1+1 3.0.1+1
convert ^2.1.1 2.1.1
crypto ^2.1.4 2.1.4
dio ^3.0.8 3.0.8
http ^0.12.0+2 0.12.0+4
meta ^1.1.8 1.1.8
Transitive dependencies
async 2.4.0
charcode 1.1.2
collection 1.14.12
http_parser 3.1.3
logging 0.11.4
path 1.6.4
source_span 1.6.0
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
mockito ^4.1.1
pedantic ^1.8.0+1 1.9.0
test ^1.9.4