@@ -93,14 +93,16 @@ type STSAssumeRoleOptions struct {
9393 AccessKey string
9494 SecretKey string
9595
96- Policy string // Optional to assign a policy to the assumed role
96+ SessionToken string // Optional if the first request is made with temporary credentials.
97+ Policy string // Optional to assign a policy to the assumed role
9798
9899 Location string // Optional commonly needed with AWS STS.
99100 DurationSeconds int // Optional defaults to 1 hour.
100101
101102 // Optional only valid if using with AWS STS
102103 RoleARN string
103104 RoleSessionName string
105+ ExternalID string
104106}
105107
106108// NewSTSAssumeRole returns a pointer to a new
@@ -161,6 +163,9 @@ func getAssumeRoleCredentials(clnt *http.Client, endpoint string, opts STSAssume
161163 if opts .Policy != "" {
162164 v .Set ("Policy" , opts .Policy )
163165 }
166+ if opts .ExternalID != "" {
167+ v .Set ("ExternalId" , opts .ExternalID )
168+ }
164169
165170 u , err := url .Parse (endpoint )
166171 if err != nil {
@@ -181,6 +186,9 @@ func getAssumeRoleCredentials(clnt *http.Client, endpoint string, opts STSAssume
181186 }
182187 req .Header .Set ("Content-Type" , "application/x-www-form-urlencoded" )
183188 req .Header .Set ("X-Amz-Content-Sha256" , hex .EncodeToString (hash .Sum (nil )))
189+ if opts .SessionToken != "" {
190+ req .Header .Set ("X-Amz-Security-Token" , opts .SessionToken )
191+ }
184192 req = signer .SignV4STS (* req , opts .AccessKey , opts .SecretKey , opts .Location )
185193
186194 resp , err := clnt .Do (req )
0 commit comments