api_op_GetFederationToken.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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 security credentials (consisting of an access key ID,
  12. // a secret access key, and a security token) for a federated user. A typical use
  13. // is in a proxy application that gets temporary security credentials on behalf of
  14. // distributed applications inside a corporate network. You must call the
  15. // GetFederationToken operation using the long-term security credentials of an IAM
  16. // user. As a result, this call is appropriate in contexts where those credentials
  17. // can be safely stored, usually in a server-based application. For a comparison of
  18. // GetFederationToken with the other API operations that produce temporary
  19. // credentials, see Requesting Temporary Security Credentials
  20. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html)
  21. // and Comparing the Amazon Web Services STS API operations
  22. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html#stsapi_comparison)
  23. // in the IAM User Guide. You can create a mobile-based or browser-based app that
  24. // can authenticate users using a web identity provider like Login with Amazon,
  25. // Facebook, Google, or an OpenID Connect-compatible identity provider. In this
  26. // case, we recommend that you use Amazon Cognito (http://aws.amazon.com/cognito/)
  27. // or AssumeRoleWithWebIdentity. For more information, see Federation Through a
  28. // Web-based Identity Provider
  29. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html#api_assumerolewithwebidentity)
  30. // in the IAM User Guide. You can also call GetFederationToken using the security
  31. // credentials of an Amazon Web Services account root user, but we do not recommend
  32. // it. Instead, we recommend that you create an IAM user for the purpose of the
  33. // proxy application. Then attach a policy to the IAM user that limits federated
  34. // users to only the actions and resources that they need to access. For more
  35. // information, see IAM Best Practices
  36. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html) in the
  37. // IAM User Guide. Session duration The temporary credentials are valid for the
  38. // specified duration, from 900 seconds (15 minutes) up to a maximum of 129,600
  39. // seconds (36 hours). The default session duration is 43,200 seconds (12 hours).
  40. // Temporary credentials obtained by using the Amazon Web Services account root
  41. // user credentials have a maximum duration of 3,600 seconds (1 hour). Permissions
  42. // You can use the temporary credentials created by GetFederationToken in any
  43. // Amazon Web Services service with the following exceptions:
  44. //
  45. // * You cannot call
  46. // any IAM operations using the CLI or the Amazon Web Services API. This limitation
  47. // does not apply to console sessions.
  48. //
  49. // * You cannot call any STS operations except
  50. // GetCallerIdentity.
  51. //
  52. // You can use temporary credentials for single sign-on (SSO)
  53. // to the console. You must pass an inline or managed session policy
  54. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session)
  55. // to this operation. You can pass a single JSON policy document to use as an
  56. // inline session policy. You can also specify up to 10 managed policy Amazon
  57. // Resource Names (ARNs) to use as managed session policies. The plaintext that you
  58. // use for both inline and managed session policies can't exceed 2,048 characters.
  59. // Though the session policy parameters are optional, if you do not pass a policy,
  60. // then the resulting federated user session has no permissions. When you pass
  61. // session policies, the session permissions are the intersection of the IAM user
  62. // policies and the session policies that you pass. This gives you a way to further
  63. // restrict the permissions for a federated user. You cannot use session policies
  64. // to grant more permissions than those that are defined in the permissions policy
  65. // of the IAM user. For more information, see Session Policies
  66. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session)
  67. // in the IAM User Guide. For information about using GetFederationToken to create
  68. // temporary security credentials, see GetFederationToken—Federation Through a
  69. // Custom Identity Broker
  70. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html#api_getfederationtoken).
  71. // You can use the credentials to access a resource that has a resource-based
  72. // policy. If that policy specifically references the federated user session in the
  73. // Principal element of the policy, the session has the permissions allowed by the
  74. // policy. These permissions are granted in addition to the permissions granted by
  75. // the session policies. Tags (Optional) You can pass tag key-value pairs to your
  76. // session. These are called session tags. For more information about session tags,
  77. // see Passing Session Tags in STS
  78. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html) in the
  79. // IAM User Guide. You can create a mobile-based or browser-based app that can
  80. // authenticate users using a web identity provider like Login with Amazon,
  81. // Facebook, Google, or an OpenID Connect-compatible identity provider. In this
  82. // case, we recommend that you use Amazon Cognito (http://aws.amazon.com/cognito/)
  83. // or AssumeRoleWithWebIdentity. For more information, see Federation Through a
  84. // Web-based Identity Provider
  85. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html#api_assumerolewithwebidentity)
  86. // in the IAM User Guide. An administrator must grant you the permissions necessary
  87. // to pass session tags. The administrator can also create granular permissions to
  88. // allow you to pass only specific session tags. For more information, see
  89. // Tutorial: Using Tags for Attribute-Based Access Control
  90. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_attribute-based-access-control.html)
  91. // in the IAM User Guide. Tag key–value pairs are not case sensitive, but case is
  92. // preserved. This means that you cannot have separate Department and department
  93. // tag keys. Assume that the user that you are federating has the
  94. // Department=Marketing tag and you pass the department=engineering session tag.
  95. // Department and department are not saved as separate tags, and the session tag
  96. // passed in the request takes precedence over the user tag.
  97. func (c *Client) GetFederationToken(ctx context.Context, params *GetFederationTokenInput, optFns ...func(*Options)) (*GetFederationTokenOutput, error) {
  98. if params == nil {
  99. params = &GetFederationTokenInput{}
  100. }
  101. result, metadata, err := c.invokeOperation(ctx, "GetFederationToken", params, optFns, c.addOperationGetFederationTokenMiddlewares)
  102. if err != nil {
  103. return nil, err
  104. }
  105. out := result.(*GetFederationTokenOutput)
  106. out.ResultMetadata = metadata
  107. return out, nil
  108. }
  109. type GetFederationTokenInput struct {
  110. // The name of the federated user. The name is used as an identifier for the
  111. // temporary security credentials (such as Bob). For example, you can reference the
  112. // federated user name in a resource-based policy, such as in an Amazon S3 bucket
  113. // policy. The regex used to validate this parameter is a string of characters
  114. // consisting of upper- and lower-case alphanumeric characters with no spaces. You
  115. // can also include underscores or any of the following characters: =,.@-
  116. //
  117. // This member is required.
  118. Name *string
  119. // The duration, in seconds, that the session should last. Acceptable durations for
  120. // federation sessions range from 900 seconds (15 minutes) to 129,600 seconds (36
  121. // hours), with 43,200 seconds (12 hours) as the default. Sessions obtained using
  122. // Amazon Web Services account root user credentials are restricted to a maximum of
  123. // 3,600 seconds (one hour). If the specified duration is longer than one hour, the
  124. // session obtained by using root user credentials defaults to one hour.
  125. DurationSeconds *int32
  126. // An IAM policy in JSON format that you want to use as an inline session policy.
  127. // You must pass an inline or managed session policy
  128. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session)
  129. // to this operation. You can pass a single JSON policy document to use as an
  130. // inline session policy. You can also specify up to 10 managed policy Amazon
  131. // Resource Names (ARNs) to use as managed session policies. This parameter is
  132. // optional. However, if you do not pass any session policies, then the resulting
  133. // federated user session has no permissions. When you pass session policies, the
  134. // session permissions are the intersection of the IAM user policies and the
  135. // session policies that you pass. This gives you a way to further restrict the
  136. // permissions for a federated user. You cannot use session policies to grant more
  137. // permissions than those that are defined in the permissions policy of the IAM
  138. // user. For more information, see Session Policies
  139. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session)
  140. // in the IAM User Guide. The resulting credentials can be used to access a
  141. // resource that has a resource-based policy. If that policy specifically
  142. // references the federated user session in the Principal element of the policy,
  143. // the session has the permissions allowed by the policy. These permissions are
  144. // granted in addition to the permissions that are granted by the session policies.
  145. // The plaintext that you use for both inline and managed session policies can't
  146. // exceed 2,048 characters. The JSON policy characters can be any ASCII character
  147. // from the space character to the end of the valid character list (\u0020 through
  148. // \u00FF). It can also include the tab (\u0009), linefeed (\u000A), and carriage
  149. // return (\u000D) characters. An Amazon Web Services conversion compresses the
  150. // passed inline session policy, managed policy ARNs, and session tags into a
  151. // packed binary format that has a separate limit. Your request can fail for this
  152. // limit even if your plaintext meets the other requirements. The PackedPolicySize
  153. // response element indicates by percentage how close the policies and tags for
  154. // your request are to the upper size limit.
  155. Policy *string
  156. // The Amazon Resource Names (ARNs) of the IAM managed policies that you want to
  157. // use as a managed session policy. The policies must exist in the same account as
  158. // the IAM user that is requesting federated access. You must pass an inline or
  159. // managed session policy
  160. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session)
  161. // to this operation. You can pass a single JSON policy document to use as an
  162. // inline session policy. You can also specify up to 10 managed policy Amazon
  163. // Resource Names (ARNs) to use as managed session policies. The plaintext that you
  164. // use for both inline and managed session policies can't exceed 2,048 characters.
  165. // You can provide up to 10 managed policy ARNs. For more information about ARNs,
  166. // see Amazon Resource Names (ARNs) and Amazon Web Services Service Namespaces
  167. // (https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) in
  168. // the Amazon Web Services General Reference. This parameter is optional. However,
  169. // if you do not pass any session policies, then the resulting federated user
  170. // session has no permissions. When you pass session policies, the session
  171. // permissions are the intersection of the IAM user policies and the session
  172. // policies that you pass. This gives you a way to further restrict the permissions
  173. // for a federated user. You cannot use session policies to grant more permissions
  174. // than those that are defined in the permissions policy of the IAM user. For more
  175. // information, see Session Policies
  176. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session)
  177. // in the IAM User Guide. The resulting credentials can be used to access a
  178. // resource that has a resource-based policy. If that policy specifically
  179. // references the federated user session in the Principal element of the policy,
  180. // the session has the permissions allowed by the policy. These permissions are
  181. // granted in addition to the permissions that are granted by the session policies.
  182. // An Amazon Web Services conversion compresses the passed inline session policy,
  183. // managed policy ARNs, and session tags into a packed binary format that has a
  184. // separate limit. Your request can fail for this limit even if your plaintext
  185. // meets the other requirements. The PackedPolicySize response element indicates by
  186. // percentage how close the policies and tags for your request are to the upper
  187. // size limit.
  188. PolicyArns []types.PolicyDescriptorType
  189. // A list of session tags. Each session tag consists of a key name and an
  190. // associated value. For more information about session tags, see Passing Session
  191. // Tags in STS
  192. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html) in the
  193. // IAM User Guide. This parameter is optional. You can pass up to 50 session tags.
  194. // The plaintext session tag keys can’t exceed 128 characters and the values can’t
  195. // exceed 256 characters. For these and additional limits, see IAM and STS
  196. // Character Limits
  197. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-limits.html#reference_iam-limits-entity-length)
  198. // in the IAM User Guide. An Amazon Web Services conversion compresses the passed
  199. // inline session policy, managed policy ARNs, and session tags into a packed
  200. // binary format that has a separate limit. Your request can fail for this limit
  201. // even if your plaintext meets the other requirements. The PackedPolicySize
  202. // response element indicates by percentage how close the policies and tags for
  203. // your request are to the upper size limit. You can pass a session tag with the
  204. // same key as a tag that is already attached to the user you are federating. When
  205. // you do, session tags override a user tag with the same key. Tag key–value pairs
  206. // are not case sensitive, but case is preserved. This means that you cannot have
  207. // separate Department and department tag keys. Assume that the role has the
  208. // Department=Marketing tag and you pass the department=engineering session tag.
  209. // Department and department are not saved as separate tags, and the session tag
  210. // passed in the request takes precedence over the role tag.
  211. Tags []types.Tag
  212. noSmithyDocumentSerde
  213. }
  214. // Contains the response to a successful GetFederationToken request, including
  215. // temporary Amazon Web Services credentials that can be used to make Amazon Web
  216. // Services requests.
  217. type GetFederationTokenOutput struct {
  218. // The temporary security credentials, which include an access key ID, a secret
  219. // access key, and a security (or session) token. The size of the security token
  220. // that STS API operations return is not fixed. We strongly recommend that you make
  221. // no assumptions about the maximum size.
  222. Credentials *types.Credentials
  223. // Identifiers for the federated user associated with the credentials (such as
  224. // arn:aws:sts::123456789012:federated-user/Bob or 123456789012:Bob). You can use
  225. // the federated user's ARN in your resource-based policies, such as an Amazon S3
  226. // bucket policy.
  227. FederatedUser *types.FederatedUser
  228. // A percentage value that indicates the packed size of the session policies and
  229. // session tags combined passed in the request. The request fails if the packed
  230. // size is greater than 100 percent, which means the policies and tags exceeded the
  231. // allowed space.
  232. PackedPolicySize *int32
  233. // Metadata pertaining to the operation's result.
  234. ResultMetadata middleware.Metadata
  235. noSmithyDocumentSerde
  236. }
  237. func (c *Client) addOperationGetFederationTokenMiddlewares(stack *middleware.Stack, options Options) (err error) {
  238. err = stack.Serialize.Add(&awsAwsquery_serializeOpGetFederationToken{}, middleware.After)
  239. if err != nil {
  240. return err
  241. }
  242. err = stack.Deserialize.Add(&awsAwsquery_deserializeOpGetFederationToken{}, middleware.After)
  243. if err != nil {
  244. return err
  245. }
  246. if err = addSetLoggerMiddleware(stack, options); err != nil {
  247. return err
  248. }
  249. if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
  250. return err
  251. }
  252. if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
  253. return err
  254. }
  255. if err = addResolveEndpointMiddleware(stack, options); err != nil {
  256. return err
  257. }
  258. if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
  259. return err
  260. }
  261. if err = addRetryMiddlewares(stack, options); err != nil {
  262. return err
  263. }
  264. if err = addHTTPSignerV4Middleware(stack, options); err != nil {
  265. return err
  266. }
  267. if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
  268. return err
  269. }
  270. if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
  271. return err
  272. }
  273. if err = addClientUserAgent(stack); err != nil {
  274. return err
  275. }
  276. if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
  277. return err
  278. }
  279. if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
  280. return err
  281. }
  282. if err = addOpGetFederationTokenValidationMiddleware(stack); err != nil {
  283. return err
  284. }
  285. if err = stack.Initialize.Add(newServiceMetadataMiddleware_opGetFederationToken(options.Region), middleware.Before); err != nil {
  286. return err
  287. }
  288. if err = addRequestIDRetrieverMiddleware(stack); err != nil {
  289. return err
  290. }
  291. if err = addResponseErrorMiddleware(stack); err != nil {
  292. return err
  293. }
  294. if err = addRequestResponseLogging(stack, options); err != nil {
  295. return err
  296. }
  297. return nil
  298. }
  299. func newServiceMetadataMiddleware_opGetFederationToken(region string) *awsmiddleware.RegisterServiceMetadata {
  300. return &awsmiddleware.RegisterServiceMetadata{
  301. Region: region,
  302. ServiceID: ServiceID,
  303. SigningName: "sts",
  304. OperationName: "GetFederationToken",
  305. }
  306. }