|
32 | 32 | // // from assumed role. |
33 | 33 | // svc := s3.NewFromConfig(cfg) |
34 | 34 | // |
35 | | -// Assume Role with static MFA Token |
| 35 | +// Assume Role with custom MFA Token provider |
36 | 36 | // |
37 | | -// To assume an IAM role with a MFA token you can either specify a MFA token code |
38 | | -// directly or provide a function to prompt the user each time the credentials |
39 | | -// need to refresh the role's credentials. Specifying the TokenCode should be used |
40 | | -// for short lived operations that will not need to be refreshed, and when you do |
41 | | -// not want to have direct control over the user provides their MFA token. |
| 37 | +// To assume an IAM role with a MFA token you can either specify a custom MFA |
| 38 | +// token provider or use the SDK's built in StdinTokenProvider that will prompt |
| 39 | +// the user for a token code each time the credentials need to to be refreshed. |
| 40 | +// Specifying a custom token provider allows you to control where the token |
| 41 | +// code is retrieved from, and how it is refreshed. |
42 | 42 | // |
43 | | -// With TokenCode the AssumeRoleProvider will be not be able to refresh the role's |
44 | | -// credentials. |
| 43 | +// With a custom token provider, the provider is responsible for refreshing the |
| 44 | +// token code when called. |
45 | 45 | // |
46 | 46 | // cfg, err := config.LoadDefaultConfig(context.TODO()) |
47 | 47 | // if err != nil { |
48 | 48 | // panic(err) |
49 | 49 | // } |
50 | 50 | // |
| 51 | +// staticTokenProvider := func() (string, error) { |
| 52 | +// return someTokenCode, nil |
| 53 | +// } |
| 54 | +// |
51 | 55 | // // Create the credentials from AssumeRoleProvider to assume the role |
52 | 56 | // // referenced by the "myRoleARN" ARN using the MFA token code provided. |
53 | 57 | // creds := stscreds.NewAssumeRoleProvider(sts.NewFromConfig(cfg), "myRoleArn", func(o *stscreds.AssumeRoleOptions) { |
54 | 58 | // o.SerialNumber = aws.String("myTokenSerialNumber") |
55 | | -// o.TokenCode = aws.String("00000000") |
| 59 | +// o.TokenProvider = staticTokenProvider |
56 | 60 | // }) |
57 | 61 | // |
58 | 62 | // cfg.Credentials = aws.NewCredentialsCache(creds) |
@@ -209,11 +213,7 @@ type AssumeRoleOptions struct { |
209 | 213 | // call. See StdinTokenProvider for a provider that prompts and reads from stdin. |
210 | 214 | // |
211 | 215 | // This token provider will be called when ever the assumed role's |
212 | | - // credentials need to be refreshed when SerialNumber is also set and |
213 | | - // TokenCode is not set. |
214 | | - // |
215 | | - // If both TokenCode and TokenProvider is set, TokenProvider will be used and |
216 | | - // TokenCode is ignored. |
| 216 | + // credentials need to be refreshed when SerialNumber is set. |
217 | 217 | TokenProvider func() (string, error) |
218 | 218 |
|
219 | 219 | // A list of session tags that you want to pass. Each session tag consists of a key |
@@ -281,7 +281,7 @@ func (p *AssumeRoleProvider) Retrieve(ctx context.Context) (aws.Credentials, err |
281 | 281 | } |
282 | 282 | input.TokenCode = aws.String(code) |
283 | 283 | } else { |
284 | | - return aws.Credentials{}, fmt.Errorf("assume role with MFA enabled, but neither TokenCode nor TokenProvider are set") |
| 284 | + return aws.Credentials{}, fmt.Errorf("assume role with MFA enabled, but TokenProvider is not set") |
285 | 285 | } |
286 | 286 | } |
287 | 287 |
|
|
0 commit comments