|
2 | 2 | -module(aws_signature). |
3 | 3 |
|
4 | 4 | -export([sign_v4/9, sign_v4/10, sign_v4_event/7, sign_v4_query_params/7, sign_v4_query_params/8]). |
| 5 | +-export([sign_v4a/10]). |
5 | 6 |
|
6 | 7 | -type header() :: {binary(), binary()}. |
7 | 8 | -type headers() :: [header()]. |
8 | 9 | -type query_param() :: {binary(), binary()}. |
9 | 10 | -type query_params() :: [query_param()]. |
10 | 11 |
|
| 12 | +%% @doc Implements the <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_sigv.html">Asymmetric Signature Version 4 (SigV4a)</a> algorithm. |
| 13 | +%% |
| 14 | +%% This function takes AWS client credentials and request details, |
| 15 | +%% based on which it computes the signature and returns headers |
| 16 | +%% extended with the authorization entries. |
| 17 | +%% |
| 18 | +%% `URL' must be valid, with all components properly escaped. |
| 19 | +%% For example, "https://example.com/path%20to" is valid, whereas |
| 20 | +%% "https://example.com/path to" is not. |
| 21 | +%% |
| 22 | +%% It is essential that the provided request details are final |
| 23 | +%% and the returned headers are used to make the request. All |
| 24 | +%% custom headers need to be assembled before the signature is |
| 25 | +%% calculated. |
| 26 | +%% |
| 27 | +%% The following options are supported: |
| 28 | +%% |
| 29 | +%% <dl> |
| 30 | +%% <dt>`add_payload_hash_header'</dt> |
| 31 | +%% <dd> |
| 32 | +%% When `true' adds the `X-Amz-Content-Sha256' header to signed requests. |
| 33 | +%% Amazon S3 is an example of a service that requires this setting. |
| 34 | +%% Defaults to `false'. |
| 35 | +%% </dd> |
| 36 | +%% <dt>`disable_implicit_payload_hashing'</dt> |
| 37 | +%% <dd> |
| 38 | +%% When `true' use the "UNSIGNED-PAYLOAD" sentinel instead of computing |
| 39 | +%% SHA256 digest of the payload. Defaults to `false'. |
| 40 | +%% </dd> |
| 41 | +%% </dl> |
| 42 | +-spec sign_v4a(binary(), binary(), binary(), [binary()], binary(), |
| 43 | + binary(), binary(), headers(), binary(), map()) |
| 44 | + -> {ok, headers()} | {error, any()}. |
| 45 | +sign_v4a(AccessKeyID, SecretAccessKey, SessionToken, Regions, |
| 46 | + Service, Method, URL, Headers, Body, Options) -> |
| 47 | + aws_sigv4a:sign_request(AccessKeyID, SecretAccessKey, SessionToken, Regions, |
| 48 | + Service, Method, URL, Headers, Body, Options). |
| 49 | + |
11 | 50 | %% @doc Same as {@link sign_v4/10} with no options. |
12 | 51 | sign_v4(AccessKeyID, SecretAccessKey, Region, Service, DateTime, Method, URL, Headers, Body) -> |
13 | 52 | sign_v4(AccessKeyID, SecretAccessKey, Region, Service, DateTime, Method, URL, Headers, Body, []). |
|
0 commit comments