From 956e77829565745b9d191ed8daed9c0f1ec31b5a Mon Sep 17 00:00:00 2001 From: Ben Wilson Date: Mon, 29 Jun 2015 17:13:24 -0400 Subject: [PATCH] store the token for temporary credentials --- lib/ex_aws/auth.ex | 8 ++++++++ lib/ex_aws/instance_meta.ex | 1 + 2 files changed, 9 insertions(+) diff --git a/lib/ex_aws/auth.ex b/lib/ex_aws/auth.ex index dec6b65d..60445bd5 100644 --- a/lib/ex_aws/auth.ex +++ b/lib/ex_aws/auth.ex @@ -2,6 +2,8 @@ defmodule ExAws.Auth do import ExAws.Auth.Utils alias Timex.DateFormat + @moduledoc false + def headers(http_method, url, service, config, headers, body) do now = %{Timex.Date.now | ms: 0} headers = [ @@ -22,7 +24,13 @@ defmodule ExAws.Auth do now) [{"Authorization", auth_header} | headers ] + |> handle_temp_credentials(config) + end + + def handle_temp_credentials(headers, %{token: token}) do + [{"X-Amz-Security-Token", token} | headers] end + def handle_temp_credentials(headers, _), do: headers def auth_header(access_key, secret_key, http_method, url, region, service, headers, body, now) do date = DateFormat.format!(now, "%Y%m%d", :strftime) diff --git a/lib/ex_aws/instance_meta.ex b/lib/ex_aws/instance_meta.ex index 40569cf0..25c64365 100644 --- a/lib/ex_aws/instance_meta.ex +++ b/lib/ex_aws/instance_meta.ex @@ -18,6 +18,7 @@ defmodule ExAws.InstanceMeta do %{ access_key_id: result["AccessKeyId"], secret_access_key: result["SecretAccessKey"], + token: result["Token"], expiration: result["Expiration"] } end