Skip to content

Commit 2890ba7

Browse files
hoshMark Allen
authored andcommitted
Pass security token for signed POST requests (aws-beam#16)
1 parent 3ef18a9 commit 2890ba7

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/aws/request.ex

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ defmodule AWS.Request do
1616
def sign_v4(client, now, method, url, headers, body) do
1717
{:ok, long_date} = Timex.format(now, "{YYYY}{0M}{0D}T{h24}{m}{s}Z")
1818
{:ok, short_date} = Timex.format(now, "{YYYY}{0M}{0D}")
19-
headers = Internal.add_date_header(headers, long_date)
19+
20+
headers =
21+
headers
22+
|> Internal.add_date_header(long_date)
23+
|> Internal.add_security_token(client)
24+
2025
canonical_request = Internal.canonical_request(method, url, headers, body)
2126
hashed_canonical_request = Util.sha256_hexdigest(canonical_request)
2227
credential_scope = Internal.credential_scope(short_date, client.region,
@@ -89,6 +94,13 @@ defmodule AWS.Request.Internal do
8994
[{"X-Amz-Date", date}|headers]
9095
end
9196

97+
@doc """
98+
Add an `X-Amz-Security-Token` if credentials configurations are configured for it
99+
"""
100+
def add_security_token(headers, %AWS.Client{session_token: nil}), do: headers
101+
def add_security_token(headers, %AWS.Client{session_token: session_token}),
102+
do: [{"X-Amz-Security-Token", session_token}|headers]
103+
92104
@doc """
93105
Generate an AWS4-HMAC-SHA256 authorization signature.
94106
"""

0 commit comments

Comments
 (0)