api_op_GetSessionToken.go 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. // Code generated by smithy-go-codegen DO NOT EDIT.
  2. package sts
  3. import (
  4. "context"
  5. awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
  6. "github.com/aws/aws-sdk-go-v2/aws/signer/v4"
  7. "github.com/aws/aws-sdk-go-v2/service/sts/types"
  8. "github.com/aws/smithy-go/middleware"
  9. smithyhttp "github.com/aws/smithy-go/transport/http"
  10. )
  11. // Returns a set of temporary credentials for an Amazon Web Services account or IAM
  12. // user. The credentials consist of an access key ID, a secret access key, and a
  13. // security token. Typically, you use GetSessionToken if you want to use MFA to
  14. // protect programmatic calls to specific Amazon Web Services API operations like
  15. // Amazon EC2 StopInstances. MFA-enabled IAM users would need to call
  16. // GetSessionToken and submit an MFA code that is associated with their MFA device.
  17. // Using the temporary security credentials that are returned from the call, IAM
  18. // users can then make programmatic calls to API operations that require MFA
  19. // authentication. If you do not supply a correct MFA code, then the API returns an
  20. // access denied error. For a comparison of GetSessionToken with the other API
  21. // operations that produce temporary credentials, see Requesting Temporary Security
  22. // Credentials
  23. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html)
  24. // and Comparing the Amazon Web Services STS API operations
  25. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html#stsapi_comparison)
  26. // in the IAM User Guide. No permissions are required for users to perform this
  27. // operation. The purpose of the sts:GetSessionToken operation is to authenticate
  28. // the user using MFA. You cannot use policies to control authentication
  29. // operations. For more information, see Permissions for GetSessionToken
  30. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_control-access_getsessiontoken.html)
  31. // in the IAM User Guide. Session Duration The GetSessionToken operation must be
  32. // called by using the long-term Amazon Web Services security credentials of the
  33. // Amazon Web Services account root user or an IAM user. Credentials that are
  34. // created by IAM users are valid for the duration that you specify. This duration
  35. // can range from 900 seconds (15 minutes) up to a maximum of 129,600 seconds (36
  36. // hours), with a default of 43,200 seconds (12 hours). Credentials based on
  37. // account credentials can range from 900 seconds (15 minutes) up to 3,600 seconds
  38. // (1 hour), with a default of 1 hour. Permissions The temporary security
  39. // credentials created by GetSessionToken can be used to make API calls to any
  40. // Amazon Web Services service with the following exceptions:
  41. //
  42. // * You cannot call
  43. // any IAM API operations unless MFA authentication information is included in the
  44. // request.
  45. //
  46. // * You cannot call any STS API except AssumeRole or
  47. // GetCallerIdentity.
  48. //
  49. // We recommend that you do not call GetSessionToken with
  50. // Amazon Web Services account root user credentials. Instead, follow our best
  51. // practices
  52. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#create-iam-users)
  53. // by creating one or more IAM users, giving them the necessary permissions, and
  54. // using IAM users for everyday interaction with Amazon Web Services. The
  55. // credentials that are returned by GetSessionToken are based on permissions
  56. // associated with the user whose credentials were used to call the operation. If
  57. // GetSessionToken is called using Amazon Web Services account root user
  58. // credentials, the temporary credentials have root user permissions. Similarly, if
  59. // GetSessionToken is called using the credentials of an IAM user, the temporary
  60. // credentials have the same permissions as the IAM user. For more information
  61. // about using GetSessionToken to create temporary credentials, go to Temporary
  62. // Credentials for Users in Untrusted Environments
  63. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html#api_getsessiontoken)
  64. // in the IAM User Guide.
  65. func (c *Client) GetSessionToken(ctx context.Context, params *GetSessionTokenInput, optFns ...func(*Options)) (*GetSessionTokenOutput, error) {
  66. if params == nil {
  67. params = &GetSessionTokenInput{}
  68. }
  69. result, metadata, err := c.invokeOperation(ctx, "GetSessionToken", params, optFns, c.addOperationGetSessionTokenMiddlewares)
  70. if err != nil {
  71. return nil, err
  72. }
  73. out := result.(*GetSessionTokenOutput)
  74. out.ResultMetadata = metadata
  75. return out, nil
  76. }
  77. type GetSessionTokenInput struct {
  78. // The duration, in seconds, that the credentials should remain valid. Acceptable
  79. // durations for IAM user sessions range from 900 seconds (15 minutes) to 129,600
  80. // seconds (36 hours), with 43,200 seconds (12 hours) as the default. Sessions for
  81. // Amazon Web Services account owners are restricted to a maximum of 3,600 seconds
  82. // (one hour). If the duration is longer than one hour, the session for Amazon Web
  83. // Services account owners defaults to one hour.
  84. DurationSeconds *int32
  85. // The identification number of the MFA device that is associated with the IAM user
  86. // who is making the GetSessionToken call. Specify this value if the IAM user has a
  87. // policy that requires MFA authentication. The value is either the serial number
  88. // for a hardware device (such as GAHT12345678) or an Amazon Resource Name (ARN)
  89. // for a virtual device (such as arn:aws:iam::123456789012:mfa/user). You can find
  90. // the device for an IAM user by going to the Amazon Web Services Management
  91. // Console and viewing the user's security credentials. The regex used to validate
  92. // this parameter is a string of characters consisting of upper- and lower-case
  93. // alphanumeric characters with no spaces. You can also include underscores or any
  94. // of the following characters: =,.@:/-
  95. SerialNumber *string
  96. // The value provided by the MFA device, if MFA is required. If any policy requires
  97. // the IAM user to submit an MFA code, specify this value. If MFA authentication is
  98. // required, the user must provide a code when requesting a set of temporary
  99. // security credentials. A user who fails to provide the code receives an "access
  100. // denied" response when requesting resources that require MFA authentication. The
  101. // format for this parameter, as described by its regex pattern, is a sequence of
  102. // six numeric digits.
  103. TokenCode *string
  104. noSmithyDocumentSerde
  105. }
  106. // Contains the response to a successful GetSessionToken request, including
  107. // temporary Amazon Web Services credentials that can be used to make Amazon Web
  108. // Services requests.
  109. type GetSessionTokenOutput struct {
  110. // The temporary security credentials, which include an access key ID, a secret
  111. // access key, and a security (or session) token. The size of the security token
  112. // that STS API operations return is not fixed. We strongly recommend that you make
  113. // no assumptions about the maximum size.
  114. Credentials *types.Credentials
  115. // Metadata pertaining to the operation's result.
  116. ResultMetadata middleware.Metadata
  117. noSmithyDocumentSerde
  118. }
  119. func (c *Client) addOperationGetSessionTokenMiddlewares(stack *middleware.Stack, options Options) (err error) {
  120. err = stack.Serialize.Add(&awsAwsquery_serializeOpGetSessionToken{}, middleware.After)
  121. if err != nil {
  122. return err
  123. }
  124. err = stack.Deserialize.Add(&awsAwsquery_deserializeOpGetSessionToken{}, middleware.After)
  125. if err != nil {
  126. return err
  127. }
  128. if err = addSetLoggerMiddleware(stack, options); err != nil {
  129. return err
  130. }
  131. if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
  132. return err
  133. }
  134. if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
  135. return err
  136. }
  137. if err = addResolveEndpointMiddleware(stack, options); err != nil {
  138. return err
  139. }
  140. if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
  141. return err
  142. }
  143. if err = addRetryMiddlewares(stack, options); err != nil {
  144. return err
  145. }
  146. if err = addHTTPSignerV4Middleware(stack, options); err != nil {
  147. return err
  148. }
  149. if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
  150. return err
  151. }
  152. if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
  153. return err
  154. }
  155. if err = addClientUserAgent(stack); err != nil {
  156. return err
  157. }
  158. if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
  159. return err
  160. }
  161. if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
  162. return err
  163. }
  164. if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetSessionToken(options.Region), middleware.Before); err != nil {
  165. return err
  166. }
  167. if err = addRequestIDRetrieverMiddleware(stack); err != nil {
  168. return err
  169. }
  170. if err = addResponseErrorMiddleware(stack); err != nil {
  171. return err
  172. }
  173. if err = addRequestResponseLogging(stack, options); err != nil {
  174. return err
  175. }
  176. return nil
  177. }
  178. func newServiceMetadataMiddleware_opGetSessionToken(region string) *awsmiddleware.RegisterServiceMetadata {
  179. return &awsmiddleware.RegisterServiceMetadata{
  180. Region: region,
  181. ServiceID: ServiceID,
  182. SigningName: "sts",
  183. OperationName: "GetSessionToken",
  184. }
  185. }