api_op_AssumeRoleWithWebIdentity.go 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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/service/sts/types"
  7. "github.com/aws/smithy-go/middleware"
  8. smithyhttp "github.com/aws/smithy-go/transport/http"
  9. )
  10. // Returns a set of temporary security credentials for users who have been
  11. // authenticated in a mobile or web application with a web identity provider.
  12. // Example providers include the OAuth 2.0 providers Login with Amazon and
  13. // Facebook, or any OpenID Connect-compatible identity provider such as Google or
  14. // Amazon Cognito federated identities
  15. // (https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-identity.html).
  16. // For mobile applications, we recommend that you use Amazon Cognito. You can use
  17. // Amazon Cognito with the Amazon Web Services SDK for iOS Developer Guide
  18. // (http://aws.amazon.com/sdkforios/) and the Amazon Web Services SDK for Android
  19. // Developer Guide (http://aws.amazon.com/sdkforandroid/) to uniquely identify a
  20. // user. You can also supply the user with a consistent identity throughout the
  21. // lifetime of an application. To learn more about Amazon Cognito, see Amazon
  22. // Cognito Overview
  23. // (https://docs.aws.amazon.com/mobile/sdkforandroid/developerguide/cognito-auth.html#d0e840)
  24. // in Amazon Web Services SDK for Android Developer Guide and Amazon Cognito
  25. // Overview
  26. // (https://docs.aws.amazon.com/mobile/sdkforios/developerguide/cognito-auth.html#d0e664)
  27. // in the Amazon Web Services SDK for iOS Developer Guide. Calling
  28. // AssumeRoleWithWebIdentity does not require the use of Amazon Web Services
  29. // security credentials. Therefore, you can distribute an application (for example,
  30. // on mobile devices) that requests temporary security credentials without
  31. // including long-term Amazon Web Services credentials in the application. You also
  32. // don't need to deploy server-based proxy services that use long-term Amazon Web
  33. // Services credentials. Instead, the identity of the caller is validated by using
  34. // a token from the web identity provider. For a comparison of
  35. // AssumeRoleWithWebIdentity with the other API operations that produce temporary
  36. // credentials, see Requesting Temporary Security Credentials
  37. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html)
  38. // and Comparing the Amazon Web Services STS API operations
  39. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html#stsapi_comparison)
  40. // in the IAM User Guide. The temporary security credentials returned by this API
  41. // consist of an access key ID, a secret access key, and a security token.
  42. // Applications can use these temporary security credentials to sign calls to
  43. // Amazon Web Services service API operations. Session Duration By default, the
  44. // temporary security credentials created by AssumeRoleWithWebIdentity last for one
  45. // hour. However, you can use the optional DurationSeconds parameter to specify the
  46. // duration of your session. You can provide a value from 900 seconds (15 minutes)
  47. // up to the maximum session duration setting for the role. This setting can have a
  48. // value from 1 hour to 12 hours. To learn how to view the maximum value for your
  49. // role, see View the Maximum Session Duration Setting for a Role
  50. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use.html#id_roles_use_view-role-max-session)
  51. // in the IAM User Guide. The maximum session duration limit applies when you use
  52. // the AssumeRole* API operations or the assume-role* CLI commands. However the
  53. // limit does not apply when you use those operations to create a console URL. For
  54. // more information, see Using IAM Roles
  55. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use.html) in the IAM
  56. // User Guide. Permissions The temporary security credentials created by
  57. // AssumeRoleWithWebIdentity can be used to make API calls to any Amazon Web
  58. // Services service with the following exception: you cannot call the STS
  59. // GetFederationToken or GetSessionToken API operations. (Optional) You can pass
  60. // inline or managed session policies
  61. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session)
  62. // to this operation. You can pass a single JSON policy document to use as an
  63. // inline session policy. You can also specify up to 10 managed policy Amazon
  64. // Resource Names (ARNs) to use as managed session policies. The plaintext that you
  65. // use for both inline and managed session policies can't exceed 2,048 characters.
  66. // Passing policies to this operation returns new temporary credentials. The
  67. // resulting session's permissions are the intersection of the role's
  68. // identity-based policy and the session policies. You can use the role's temporary
  69. // credentials in subsequent Amazon Web Services API calls to access resources in
  70. // the account that owns the role. You cannot use session policies to grant more
  71. // permissions than those allowed by the identity-based policy of the role that is
  72. // being assumed. For more information, see Session Policies
  73. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session)
  74. // in the IAM User Guide. Tags (Optional) You can configure your IdP to pass
  75. // attributes into your web identity token as session tags. Each session tag
  76. // consists of a key name and an associated value. For more information about
  77. // session tags, 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 pass up to 50 session tags. The plaintext session tag
  80. // keys can’t exceed 128 characters and the values can’t exceed 256 characters. For
  81. // these and additional limits, see IAM and STS Character Limits
  82. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_iam-limits.html#reference_iam-limits-entity-length)
  83. // in the IAM User Guide. An Amazon Web Services conversion compresses the passed
  84. // inline session policy, managed policy ARNs, and session tags into a packed
  85. // binary format that has a separate limit. Your request can fail for this limit
  86. // even if your plaintext meets the other requirements. The PackedPolicySize
  87. // response element indicates by percentage how close the policies and tags for
  88. // your request are to the upper size limit. You can pass a session tag with the
  89. // same key as a tag that is attached to the role. When you do, the session tag
  90. // overrides the role tag with the same key. An administrator must grant you the
  91. // permissions necessary to pass session tags. The administrator can also create
  92. // granular permissions to allow you to pass only specific session tags. For more
  93. // information, see Tutorial: Using Tags for Attribute-Based Access Control
  94. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/tutorial_attribute-based-access-control.html)
  95. // in the IAM User Guide. You can set the session tags as transitive. Transitive
  96. // tags persist during role chaining. For more information, see Chaining Roles with
  97. // Session Tags
  98. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_session-tags.html#id_session-tags_role-chaining)
  99. // in the IAM User Guide. Identities Before your application can call
  100. // AssumeRoleWithWebIdentity, you must have an identity token from a supported
  101. // identity provider and create a role that the application can assume. The role
  102. // that your application assumes must trust the identity provider that is
  103. // associated with the identity token. In other words, the identity provider must
  104. // be specified in the role's trust policy. Calling AssumeRoleWithWebIdentity can
  105. // result in an entry in your CloudTrail logs. The entry includes the Subject
  106. // (http://openid.net/specs/openid-connect-core-1_0.html#Claims) of the provided
  107. // web identity token. We recommend that you avoid using any personally
  108. // identifiable information (PII) in this field. For example, you could instead use
  109. // a GUID or a pairwise identifier, as suggested in the OIDC specification
  110. // (http://openid.net/specs/openid-connect-core-1_0.html#SubjectIDTypes). For more
  111. // information about how to use web identity federation and the
  112. // AssumeRoleWithWebIdentity API, see the following resources:
  113. //
  114. // * Using Web
  115. // Identity Federation API Operations for Mobile Apps
  116. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_oidc_manual.html)
  117. // and Federation Through a Web-based Identity Provider
  118. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_request.html#api_assumerolewithwebidentity).
  119. //
  120. // *
  121. // Web Identity Federation Playground
  122. // (https://aws.amazon.com/blogs/aws/the-aws-web-identity-federation-playground/).
  123. // Walk through the process of authenticating through Login with Amazon, Facebook,
  124. // or Google, getting temporary security credentials, and then using those
  125. // credentials to make a request to Amazon Web Services.
  126. //
  127. // * Amazon Web Services SDK
  128. // for iOS Developer Guide (http://aws.amazon.com/sdkforios/) and Amazon Web
  129. // Services SDK for Android Developer Guide (http://aws.amazon.com/sdkforandroid/).
  130. // These toolkits contain sample apps that show how to invoke the identity
  131. // providers. The toolkits then show how to use the information from these
  132. // providers to get and use temporary security credentials.
  133. //
  134. // * Web Identity
  135. // Federation with Mobile Applications
  136. // (http://aws.amazon.com/articles/web-identity-federation-with-mobile-applications).
  137. // This article discusses web identity federation and shows an example of how to
  138. // use web identity federation to get access to content in Amazon S3.
  139. func (c *Client) AssumeRoleWithWebIdentity(ctx context.Context, params *AssumeRoleWithWebIdentityInput, optFns ...func(*Options)) (*AssumeRoleWithWebIdentityOutput, error) {
  140. if params == nil {
  141. params = &AssumeRoleWithWebIdentityInput{}
  142. }
  143. result, metadata, err := c.invokeOperation(ctx, "AssumeRoleWithWebIdentity", params, optFns, c.addOperationAssumeRoleWithWebIdentityMiddlewares)
  144. if err != nil {
  145. return nil, err
  146. }
  147. out := result.(*AssumeRoleWithWebIdentityOutput)
  148. out.ResultMetadata = metadata
  149. return out, nil
  150. }
  151. type AssumeRoleWithWebIdentityInput struct {
  152. // The Amazon Resource Name (ARN) of the role that the caller is assuming.
  153. //
  154. // This member is required.
  155. RoleArn *string
  156. // An identifier for the assumed role session. Typically, you pass the name or
  157. // identifier that is associated with the user who is using your application. That
  158. // way, the temporary security credentials that your application will use are
  159. // associated with that user. This session name is included as part of the ARN and
  160. // assumed role ID in the AssumedRoleUser response element. The regex used to
  161. // validate this parameter is a string of characters consisting of upper- and
  162. // lower-case alphanumeric characters with no spaces. You can also include
  163. // underscores or any of the following characters: =,.@-
  164. //
  165. // This member is required.
  166. RoleSessionName *string
  167. // The OAuth 2.0 access token or OpenID Connect ID token that is provided by the
  168. // identity provider. Your application must get this token by authenticating the
  169. // user who is using your application with a web identity provider before the
  170. // application makes an AssumeRoleWithWebIdentity call.
  171. //
  172. // This member is required.
  173. WebIdentityToken *string
  174. // The duration, in seconds, of the role session. The value can range from 900
  175. // seconds (15 minutes) up to the maximum session duration setting for the role.
  176. // This setting can have a value from 1 hour to 12 hours. If you specify a value
  177. // higher than this setting, the operation fails. For example, if you specify a
  178. // session duration of 12 hours, but your administrator set the maximum session
  179. // duration to 6 hours, your operation fails. To learn how to view the maximum
  180. // value for your role, see View the Maximum Session Duration Setting for a Role
  181. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use.html#id_roles_use_view-role-max-session)
  182. // in the IAM User Guide. By default, the value is set to 3600 seconds. The
  183. // DurationSeconds parameter is separate from the duration of a console session
  184. // that you might request using the returned credentials. The request to the
  185. // federation endpoint for a console sign-in token takes a SessionDuration
  186. // parameter that specifies the maximum length of the console session. For more
  187. // information, see Creating a URL that Enables Federated Users to Access the
  188. // Amazon Web Services Management Console
  189. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_enable-console-custom-url.html)
  190. // in the IAM User Guide.
  191. DurationSeconds *int32
  192. // An IAM policy in JSON format that you want to use as an inline session policy.
  193. // This parameter is optional. Passing policies to this operation returns new
  194. // temporary credentials. The resulting session's permissions are the intersection
  195. // of the role's identity-based policy and the session policies. You can use the
  196. // role's temporary credentials in subsequent Amazon Web Services API calls to
  197. // access resources in the account that owns the role. You cannot use session
  198. // policies to grant more permissions than those allowed by the identity-based
  199. // policy of the role that is being assumed. For more information, see Session
  200. // Policies
  201. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session)
  202. // in the IAM User Guide. The plaintext that you use for both inline and managed
  203. // session policies can't exceed 2,048 characters. The JSON policy characters can
  204. // be any ASCII character from the space character to the end of the valid
  205. // character list (\u0020 through \u00FF). It can also include the tab (\u0009),
  206. // linefeed (\u000A), and carriage return (\u000D) characters. An Amazon Web
  207. // Services conversion compresses the passed inline session policy, managed policy
  208. // ARNs, and session tags into a packed binary format that has a separate limit.
  209. // Your request can fail for this limit even if your plaintext meets the other
  210. // requirements. The PackedPolicySize response element indicates by percentage how
  211. // close the policies and tags for your request are to the upper size limit.
  212. Policy *string
  213. // The Amazon Resource Names (ARNs) of the IAM managed policies that you want to
  214. // use as managed session policies. The policies must exist in the same account as
  215. // the role. This parameter is optional. You can provide up to 10 managed policy
  216. // ARNs. However, the plaintext that you use for both inline and managed session
  217. // policies can't exceed 2,048 characters. For more information about ARNs, see
  218. // Amazon Resource Names (ARNs) and Amazon Web Services Service Namespaces
  219. // (https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) in
  220. // the Amazon Web Services General Reference. An Amazon Web Services conversion
  221. // compresses the passed inline session policy, managed policy ARNs, and session
  222. // tags into a packed binary format that has a separate limit. Your request can
  223. // fail for this limit even if your plaintext meets the other requirements. The
  224. // PackedPolicySize response element indicates by percentage how close the policies
  225. // and tags for your request are to the upper size limit. Passing policies to this
  226. // operation returns new temporary credentials. The resulting session's permissions
  227. // are the intersection of the role's identity-based policy and the session
  228. // policies. You can use the role's temporary credentials in subsequent Amazon Web
  229. // Services API calls to access resources in the account that owns the role. You
  230. // cannot use session policies to grant more permissions than those allowed by the
  231. // identity-based policy of the role that is being assumed. For more information,
  232. // see Session Policies
  233. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html#policies_session)
  234. // in the IAM User Guide.
  235. PolicyArns []types.PolicyDescriptorType
  236. // The fully qualified host component of the domain name of the OAuth 2.0 identity
  237. // provider. Do not specify this value for an OpenID Connect identity provider.
  238. // Currently www.amazon.com and graph.facebook.com are the only supported identity
  239. // providers for OAuth 2.0 access tokens. Do not include URL schemes and port
  240. // numbers. Do not specify this value for OpenID Connect ID tokens.
  241. ProviderId *string
  242. noSmithyDocumentSerde
  243. }
  244. // Contains the response to a successful AssumeRoleWithWebIdentity request,
  245. // including temporary Amazon Web Services credentials that can be used to make
  246. // Amazon Web Services requests.
  247. type AssumeRoleWithWebIdentityOutput struct {
  248. // The Amazon Resource Name (ARN) and the assumed role ID, which are identifiers
  249. // that you can use to refer to the resulting temporary security credentials. For
  250. // example, you can reference these credentials as a principal in a resource-based
  251. // policy by using the ARN or assumed role ID. The ARN and ID include the
  252. // RoleSessionName that you specified when you called AssumeRole.
  253. AssumedRoleUser *types.AssumedRoleUser
  254. // The intended audience (also known as client ID) of the web identity token. This
  255. // is traditionally the client identifier issued to the application that requested
  256. // the web identity token.
  257. Audience *string
  258. // The temporary security credentials, which include an access key ID, a secret
  259. // access key, and a security token. The size of the security token that STS API
  260. // operations return is not fixed. We strongly recommend that you make no
  261. // assumptions about the maximum size.
  262. Credentials *types.Credentials
  263. // A percentage value that indicates the packed size of the session policies and
  264. // session tags combined passed in the request. The request fails if the packed
  265. // size is greater than 100 percent, which means the policies and tags exceeded the
  266. // allowed space.
  267. PackedPolicySize *int32
  268. // The issuing authority of the web identity token presented. For OpenID Connect ID
  269. // tokens, this contains the value of the iss field. For OAuth 2.0 access tokens,
  270. // this contains the value of the ProviderId parameter that was passed in the
  271. // AssumeRoleWithWebIdentity request.
  272. Provider *string
  273. // The value of the source identity that is returned in the JSON web token (JWT)
  274. // from the identity provider. You can require users to set a source identity value
  275. // when they assume a role. You do this by using the sts:SourceIdentity condition
  276. // key in a role trust policy. That way, actions that are taken with the role are
  277. // associated with that user. After the source identity is set, the value cannot be
  278. // changed. It is present in the request for all actions that are taken by the role
  279. // and persists across chained role
  280. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_terms-and-concepts#iam-term-role-chaining)
  281. // sessions. You can configure your identity provider to use an attribute
  282. // associated with your users, like user name or email, as the source identity when
  283. // calling AssumeRoleWithWebIdentity. You do this by adding a claim to the JSON web
  284. // token. To learn more about OIDC tokens and claims, see Using Tokens with User
  285. // Pools
  286. // (https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-using-tokens-with-identity-providers.html)
  287. // in the Amazon Cognito Developer Guide. For more information about using source
  288. // identity, see Monitor and control actions taken with assumed roles
  289. // (https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_control-access_monitor.html)
  290. // in the IAM User Guide. The regex used to validate this parameter is a string of
  291. // characters consisting of upper- and lower-case alphanumeric characters with no
  292. // spaces. You can also include underscores or any of the following characters:
  293. // =,.@-
  294. SourceIdentity *string
  295. // The unique user identifier that is returned by the identity provider. This
  296. // identifier is associated with the WebIdentityToken that was submitted with the
  297. // AssumeRoleWithWebIdentity call. The identifier is typically unique to the user
  298. // and the application that acquired the WebIdentityToken (pairwise identifier).
  299. // For OpenID Connect ID tokens, this field contains the value returned by the
  300. // identity provider as the token's sub (Subject) claim.
  301. SubjectFromWebIdentityToken *string
  302. // Metadata pertaining to the operation's result.
  303. ResultMetadata middleware.Metadata
  304. noSmithyDocumentSerde
  305. }
  306. func (c *Client) addOperationAssumeRoleWithWebIdentityMiddlewares(stack *middleware.Stack, options Options) (err error) {
  307. err = stack.Serialize.Add(&awsAwsquery_serializeOpAssumeRoleWithWebIdentity{}, middleware.After)
  308. if err != nil {
  309. return err
  310. }
  311. err = stack.Deserialize.Add(&awsAwsquery_deserializeOpAssumeRoleWithWebIdentity{}, middleware.After)
  312. if err != nil {
  313. return err
  314. }
  315. if err = addSetLoggerMiddleware(stack, options); err != nil {
  316. return err
  317. }
  318. if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
  319. return err
  320. }
  321. if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
  322. return err
  323. }
  324. if err = addResolveEndpointMiddleware(stack, options); err != nil {
  325. return err
  326. }
  327. if err = addRetryMiddlewares(stack, options); err != nil {
  328. return err
  329. }
  330. if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
  331. return err
  332. }
  333. if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
  334. return err
  335. }
  336. if err = addClientUserAgent(stack); err != nil {
  337. return err
  338. }
  339. if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
  340. return err
  341. }
  342. if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
  343. return err
  344. }
  345. if err = addOpAssumeRoleWithWebIdentityValidationMiddleware(stack); err != nil {
  346. return err
  347. }
  348. if err = stack.Initialize.Add(newServiceMetadataMiddleware_opAssumeRoleWithWebIdentity(options.Region), middleware.Before); err != nil {
  349. return err
  350. }
  351. if err = addRequestIDRetrieverMiddleware(stack); err != nil {
  352. return err
  353. }
  354. if err = addResponseErrorMiddleware(stack); err != nil {
  355. return err
  356. }
  357. if err = addRequestResponseLogging(stack, options); err != nil {
  358. return err
  359. }
  360. return nil
  361. }
  362. func newServiceMetadataMiddleware_opAssumeRoleWithWebIdentity(region string) *awsmiddleware.RegisterServiceMetadata {
  363. return &awsmiddleware.RegisterServiceMetadata{
  364. Region: region,
  365. ServiceID: ServiceID,
  366. SigningName: "sts",
  367. OperationName: "AssumeRoleWithWebIdentity",
  368. }
  369. }