create_token_with_iam
¶
create_token_with_iam(
client_id: ClientId,
grant_type: GrantType,
*,
config_overrides: Optional[SSOOIDCClientConfig] = None,
code: Optional[AuthCode] = None,
refresh_token: Optional[RefreshToken] = None,
assertion: Optional[Assertion] = None,
scope: Optional[Scopes] = None,
redirect_uri: Optional[URI] = None,
subject_token: Optional[SubjectToken] = None,
subject_token_type: Optional[TokenTypeURI] = None,
requested_token_type: Optional[TokenTypeURI] = None,
code_verifier: Optional[CodeVerifier] = None,
) -> CreateTokenWithIAMResponse
Creates and returns access and refresh tokens for authorized client applications that are authenticated using any IAM entity, such as a service role or user. These tokens might contain defined scopes that specify permissions such as read:profile or write:data. Through downscoping, you can use the scopes parameter to request tokens with reduced permissions compared to the original client application's permissions or, if applicable, the refresh token's scopes. The access token can be used to fetch short-lived credentials for the assigned Amazon Web Services accounts or to access application APIs using bearer authentication.
This API is used with Signature Version 4. For more information, see Amazon Web Services Signature Version 4 for API Requests.
Parameters:
-
client_id(ClientId) –The unique identifier string for the client or application. This value is an application ARN that has OAuth grants configured.
-
grant_type(GrantType) –Supports the following OAuth grant types: Authorization Code, Refresh Token, JWT Bearer, and Token Exchange. Specify one of the following values, depending on the grant type that you want:
* Authorization Code -
authorization_code* Refresh Token -
refresh_token* JWT Bearer -
urn:ietf:params:oauth:grant-type:jwt-bearer* Token Exchange -
urn:ietf:params:oauth:grant-type:token-exchange -
code(Optional[AuthCode], default:None) –Used only when calling this API for the Authorization Code grant type. This short-lived code is used to identify this authorization request. The code is obtained through a redirect from IAM Identity Center to a redirect URI persisted in the Authorization Code GrantOptions for the application.
-
refresh_token(Optional[RefreshToken], default:None) –Used only when calling this API for the Refresh Token grant type. This token is used to refresh short-lived tokens, such as the access token, that might expire.
For more information about the features and limitations of the current IAM Identity Center OIDC implementation, see Considerations for Using this Guide in the IAM Identity Center OIDC API Reference.
-
assertion(Optional[Assertion], default:None) –Used only when calling this API for the JWT Bearer grant type. This value specifies the JSON Web Token (JWT) issued by a trusted token issuer. To authorize a trusted token issuer, configure the JWT Bearer GrantOptions for the application.
-
scope(Optional[Scopes], default:None) –The list of scopes for which authorization is requested. The access token that is issued is limited to the scopes that are granted. If the value is not specified, IAM Identity Center authorizes all scopes configured for the application, including the following default scopes:
openid,aws,sts:identity_context. -
redirect_uri(Optional[URI], default:None) –Used only when calling this API for the Authorization Code grant type. This value specifies the location of the client or application that has registered to receive the authorization code.
-
subject_token(Optional[SubjectToken], default:None) –Used only when calling this API for the Token Exchange grant type. This value specifies the subject of the exchange. The value of the subject token must be an access token issued by IAM Identity Center to a different client or application. The access token must have authorized scopes that indicate the requested application as a target audience.
-
subject_token_type(Optional[TokenTypeURI], default:None) –Used only when calling this API for the Token Exchange grant type. This value specifies the type of token that is passed as the subject of the exchange. The following value is supported:
* Access Token -
urn:ietf:params:oauth:token-type:access_token -
requested_token_type(Optional[TokenTypeURI], default:None) –Used only when calling this API for the Token Exchange grant type. This value specifies the type of token that the requester can receive. The following values are supported:
* Access Token -
urn:ietf:params:oauth:token-type:access_token* Refresh Token -
urn:ietf:params:oauth:token-type:refresh_token -
code_verifier(Optional[CodeVerifier], default:None) –Used only when calling this API for the Authorization Code grant type. This value is generated by the client and presented to validate the original code challenge value the client passed at authorization time.
Raises:
-
AccessDeniedException–You do not have sufficient access to perform this action.
-
AuthorizationPendingException–Indicates that a request to authorize a client with an access user session token is pending.
-
ExpiredTokenException–Indicates that the token issued by the service is expired and is no longer valid.
-
InternalServerException–Indicates that an error from the service occurred while trying to process a request.
-
InvalidClientException–Indicates that the
clientIdorclientSecretin the request is invalid. For example, this can occur when a client sends an incorrectclientIdor an expiredclientSecret. -
InvalidGrantException–Indicates that a request contains an invalid grant. This can occur if a client makes a CreateToken request with an invalid grant type.
-
InvalidRequestException–Indicates that something is wrong with the input to the request. For example, a required parameter might be missing or out of range.
-
InvalidRequestRegionException–Indicates that a token provided as input to the request was issued by and is only usable by calling IAM Identity Center endpoints in another region.
-
InvalidScopeException–Indicates that the scope provided in the request is invalid.
-
SlowDownException–Indicates that the client is making the request too frequently and is more than the service can handle.
-
UnauthorizedClientException–Indicates that the client is not currently authorized to make the request. This can happen when a
clientIdis not issued for a public client. -
UnsupportedGrantTypeException–Indicates that the grant type in the request is not supported by the service.
-
UnknownServiceError–The service returned an error code this client does not model.
Examples:
Call OAuth/OIDC /token endpoint for Authorization Code grant with IAM authentication
>>> client.create_token_with_iam(client_id='arn:aws:sso::123456789012:application/ssoins-111111111111/apl-222222222222', grant_type='authorization_code', code='yJraWQiOiJrZXktMTU2Njk2ODA4OCIsImFsZyI6IkhTMzg0In0EXAMPLEAUTHCODE', redirect_uri='https://mywebapp.example/redirect', scope=['openid', 'aws', 'sts:identity_context'])
Call OAuth/OIDC /token endpoint for JWT Bearer grant with IAM authentication
>>> client.create_token_with_iam(client_id='arn:aws:sso::123456789012:application/ssoins-111111111111/apl-222222222222', grant_type='urn:ietf:params:oauth:grant-type:jwt-bearer', assertion='eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IjFMVE16YWtpaGlSbGFfOHoyQkVKVlhlV01xbyJ9.eyJ2ZXIiOiIyLjAiLCJpc3MiOiJodHRwczovL2xvZ2luLm1pY3Jvc29mdG9ubGluZS5jb20vOTEyMjA0MGQtNmM2Ny00YzViLWIxMTItMzZhMzA0YjY2ZGFkL3YyLjAiLCJzdWIiOiJBQUFBQUFBQUFBQUFBQUFBQUFBQUFJa3pxRlZyU2FTYUZIeTc4MmJidGFRIiwiYXVkIjoiNmNiMDQwMTgtYTNmNS00NmE3LWI5OTUtOTQwYzc4ZjVhZWYzIiwiZXhwIjoxNTM2MzYxNDExLCJpYXQiOjE1MzYyNzQ3MTEsIm5iZiI6MTUzNjI3NDcxMSwibmFtZSI6IkFiZSBMaW5jb2xuIiwicHJlZmVycmVkX3VzZXJuYW1lIjoiQWJlTGlAbWljcm9zb2Z0LmNvbSIsIm9pZCI6IjAwMDAwMDAwLTAwMDAtMDAwMC02NmYzLTMzMzJlY2E3ZWE4MSIsInRpZCI6IjkxMjIwNDBkLTZjNjctNGM1Yi1iMTEyLTM2YTMwNGI2NmRhZCIsIm5vbmNlIjoiMTIzNTIzIiwiYWlvIjoiRGYyVVZYTDFpeCFsTUNXTVNPSkJjRmF0emNHZnZGR2hqS3Y4cTVnMHg3MzJkUjVNQjVCaXN2R1FPN1lXQnlqZDhpUURMcSFlR2JJRGFreXA1bW5PcmNkcUhlWVNubHRlcFFtUnA2QUlaOGpZIn0.1AFWW-Ck5nROwSlltm7GzZvDwUkqvhSQpm55TQsmVo9Y59cLhRXpvB8n-55HCr9Z6G_31_UbeUkoz612I2j_Sm9FFShSDDjoaLQr54CreGIJvjtmS3EkK9a7SJBbcpL1MpUtlfygow39tFjY7EVNW9plWUvRrTgVk7lYLprvfzw-CIqw3gHC-T7IK_m_xkr08INERBtaecwhTeN4chPC4W3jdmw_lIxzC48YoQ0dB1L9-ImX98Egypfrlbm0IBL5spFzL6JDZIRRJOu8vecJvj1mq-IUhGt0MacxX8jdxYLP-KUu2d9MbNKpCKJuZ7p8gwTL5B7NlUdh_dmSviPWrw')
Call OAuth/OIDC /token endpoint for Refresh Token grant with IAM authentication
>>> client.create_token_with_iam(client_id='arn:aws:sso::123456789012:application/ssoins-111111111111/apl-222222222222', grant_type='refresh_token', refresh_token='aorvJYubGpU6i91YnH7Mfo-AT2fIVa1zCfA_Rvq9yjVKIP3onFmmykuQ7E93y2I-9Nyj-A_sVvMufaLNL0bqnDRtgAkc0:MGUCMFrRsktMRVlWaOR70XGMFGLL0SlcCw4DiYveIiOVx1uK9BbD0gvAddsW3UTLozXKMgIxAJ3qxUvjpnlLIOaaKOoa/FuNgqJVvr9GMwDtnAtlh9iZzAkEXAMPLEREFRESHTOKEN')
Call OAuth/OIDC /token endpoint for Token Exchange grant with IAM authentication
>>> client.create_token_with_iam(client_id='arn:aws:sso::123456789012:application/ssoins-111111111111/apl-222222222222', grant_type='urn:ietf:params:oauth:grant-type:token-exchange', subject_token='aoak-Hig8TUDPNX1xZwOMXM5MxOWDL0E0jg9P6_C_jKQPxS_SKCP6f0kh1Up4g7TtvQqkMnD-GJiU_S1gvug6SrggAkc0:MGYCMQD3IatVjV7jAJU91kK3PkS/SfA2wtgWzOgZWDOR7sDGN9t0phCZz5It/aes/3C1Zj0CMQCKWOgRaiz6AIhza3DSXQNMLjRKXC8F8ceCsHlgYLMZ7hZDIFFERENTACCESSTOKEN', subject_token_type='urn:ietf:params:oauth:token-type:access_token', requested_token_type='urn:ietf:params:oauth:token-type:access_token')
Source code in docs_src/capo_sso_oidc/_services/ssooidc.py
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |