get_o_auth_token
¶
get_o_auth_token(
credential_provider_arn: CredentialProviderArn,
grant_type: GrantType,
*,
config_overrides: Optional[CredentialBrokerClientConfig] = None,
scopes: Optional[Scopes] = None,
resources: Optional[Resources] = None,
audiences: Optional[Audiences] = None,
custom_parameters: Optional[CustomParameters] = None,
force_authentication: Optional[bool] = None,
session_uri: Optional[SessionUri] = None,
) -> GetOAuthTokenResponse
Retrieves an OAuth access token from a credential provider. The broker authenticates to the provider's authorization server with the client credentials configured on the provider, obtains a token, and returns it — so your workload never handles the provider's client secret.
The broker caches the access token it obtains until that token expires, or for up to one hour when the token's own lifetime is longer than an hour. A call made while a cached token is still valid returns that token instead of requesting a new one; set forceAuthentication to bypass the cache and force a fresh request to the authorization server.
The grant type you name must be one the provider allows. CLIENT_CREDENTIALS returns a token representing the workload itself; TOKEN_EXCHANGE returns a token that preserves the identity of the caller the workload is acting for; AUTHORIZATION_CODE returns a token representing an end user who granted consent, and requires a consent session that user has already completed, named in sessionUri; JWT_AUTHORIZATION_GRANT presents a signed JWT as the grant, so no client secret is sent on the token request. Of the supported vendors, only Microsoft Entra ID accepts this grant today: Entra implements on-behalf-of delegation with the RFC 7523 JWT bearer grant (urn:ietf:params:oauth:grant-type:jwt-bearer), where other authorization servers use RFC 8693 token exchange.
Parameters:
-
credential_provider_arn(CredentialProviderArn) –Amazon Resource Name of the credential provider to obtain the token from. The provider must be an OAuth provider and must be READY.
-
grant_type(GrantType) –How the token is obtained. Must be one of the grant types the provider allows; a grant the provider does not allow is rejected.
-
scopes(Optional[Scopes], default:None) –The OAuth scopes to request from the authorization server.
-
resources(Optional[Resources], default:None) –Resource indicators (RFC 8707) naming the APIs this token is for. Omit unless the authorization server requires them.
-
audiences(Optional[Audiences], default:None) –Audience values (RFC 8693) naming the intended recipients of this token. Omit unless the authorization server requires them.
-
custom_parameters(Optional[CustomParameters], default:None) –Extra parameters to include in the request to the authorization server, for vendor extensions. Added to the standard OAuth parameters; they never override them.
-
force_authentication(Optional[bool], default:None) –Request a new token from the authorization server even when the broker already holds a valid one for this provider. Defaults to false, which returns the held token when one is available.
-
session_uri(Optional[SessionUri], default:None) –Return the token obtained for a consent session that a user has already completed. Supply the handle returned when the session was started.
Raises:
-
AccessDeniedException–The caller is not authorized to perform the request, or a resource the request depends on refused access.
reasondistinguishes a denial by this service from a denial reported by a dependency the caller configured, such as a customer-owned secret, KMS key, or external identity provider, which usually points at a permission or configuration fix outside this API. -
InternalServerException–The request failed because of an unexpected error in the service. Whether the request took effect is undefined, so for a create or update, read the resource back before retrying. Retryable: the same request may succeed later.
-
ResourceNotFoundException–The requested resource does not exist, or the caller is not permitted to know that it exists. A resource that was deleted, or that is still being created, can also be reported this way.
-
ServiceQuotaExceededException–The request would exceed a service quota, so it was rejected and nothing was created or changed. Delete resources that are no longer needed, or request a quota increase in Service Quotas using
serviceCodeandquotaCode, then retry. -
ServiceUnavailableException–A downstream dependency the broker relies on is temporarily unavailable, notably the customer's external IdP token/discovery endpoint (upstream 5xx,
server_error, ortemporarily_unavailable). Retryable: the same request may succeed later. -
ThrottlingException–The request was denied because the caller exceeded a request rate limit. Nothing was changed. Retry with exponential backoff, honoring
retryAfterSecondswhen it is present. -
ValidationException–The request is not valid. The request was rejected before any change was made, so it is safe to correct the input and retry. Use
reasonto branch in code andmessagefor the human-readable detail of which field or combination of fields was at fault. -
UnknownServiceError–The service returned an error code this client does not model.
Source code in docs_src/capo_credentialbroker/_services/credential_broker.py
280 281 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 | |