Skip to content

Dart library for signing AWS requests with Signature Version 4

License

Notifications You must be signed in to change notification settings

arnemolland/sigv4

Repository files navigation

logo-long

sigv4 pub style: pedantic license

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

This is not actively maintained. If you're looking for alternatives, check out aws_client. If you'd like to continue using this library and have a fix for an issue, I'll be happy to review PRs.

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);

About

Dart library for signing AWS requests with Signature Version 4

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages