Skip to content

get_authorization_token

get_authorization_token(
    domain: DomainName,
    *,
    config_overrides: Optional[codeartifactClientConfig] = None,
    domain_owner: Optional[AccountId] = None,
    duration_seconds: Optional[AuthorizationTokenDurationSeconds] = None,
) -> GetAuthorizationTokenResult

Generates a temporary authorization token for accessing repositories in the domain. This API requires the codeartifact:GetAuthorizationToken and sts:GetServiceBearerToken permissions. For more information about authorization tokens, see CodeArtifact authentication and tokens.

CodeArtifact authorization tokens are valid for a period of 12 hours when created with the login command. You can call login periodically to refresh the token. When you create an authorization token with the GetAuthorizationToken API, you can set a custom authorization period, up to a maximum of 12 hours, with the durationSeconds parameter.

The authorization period begins after login or GetAuthorizationToken is called. If login or GetAuthorizationToken is called while assuming a role, the token lifetime is independent of the maximum session duration of the role. For example, if you call sts assume-role and specify a session duration of 15 minutes, then generate a CodeArtifact authorization token, the token will be valid for the full authorization period even though this is longer than the 15-minute session duration.

See Using IAM Roles for more information on controlling session duration.

Parameters:

  • domain (DomainName) –

    The name of the domain that is in scope for the generated authorization token.

  • domain_owner (Optional[AccountId], default: None ) –

    The 12-digit account number of the Amazon Web Services account that owns the domain. It does not include dashes or spaces.

  • duration_seconds (Optional[AuthorizationTokenDurationSeconds], default: None ) –

    The time, in seconds, that the generated authorization token is valid. Valid values are 0 and any number between 900 (15 minutes) and 43200 (12 hours). A value of 0 will set the expiration of the authorization token to the same expiration of the user's role's temporary credentials.

Raises:

  • AccessDeniedException –

    The operation did not succeed because of an unauthorized access attempt.

  • InternalServerException –

    The operation did not succeed because of an error that occurred inside CodeArtifact.

  • ResourceNotFoundException –

    The operation did not succeed because the resource requested is not found in the service.

  • ThrottlingException –

    The operation did not succeed because too many requests are sent to the service.

  • ValidationException –

    The operation did not succeed because a parameter in the request was sent with an invalid value.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_codeartifact/_services/codeartifact.py
def get_authorization_token(
    self,
    domain: "capo_codeartifact.types.domain_name.DomainName",
    *,
    config_overrides: Optional[codeartifactClientConfig] = None,
    domain_owner: Optional["capo_codeartifact.types.account_id.AccountId"] = None,
    duration_seconds: Optional[
        "capo_codeartifact.types.authorization_token_duration_seconds.AuthorizationTokenDurationSeconds"
    ] = None,
) -> "capo_codeartifact.types.get_authorization_token_result.GetAuthorizationTokenResult":
    """<p> Generates a temporary authorization token for accessing repositories in the domain. This API requires the <code>codeartifact:GetAuthorizationToken</code> and <code>sts:GetServiceBearerToken</code> permissions. For more information about authorization tokens, see <a href="https://docs.aws.amazon.com/codeartifact/latest/ug/tokens-authentication.html">CodeArtifact authentication and tokens</a>. </p> <note> <p>CodeArtifact authorization tokens are valid for a period of 12 hours when created with the <code>login</code> command. You can call <code>login</code> periodically to refresh the token. When you create an authorization token with the <code>GetAuthorizationToken</code> API, you can set a custom authorization period, up to a maximum of 12 hours, with the <code>durationSeconds</code> parameter.</p> <p>The authorization period begins after <code>login</code> or <code>GetAuthorizationToken</code> is called. If <code>login</code> or <code>GetAuthorizationToken</code> is called while assuming a role, the token lifetime is independent of the maximum session duration of the role. For example, if you call <code>sts assume-role</code> and specify a session duration of 15 minutes, then generate a CodeArtifact authorization token, the token will be valid for the full authorization period even though this is longer than the 15-minute session duration.</p> <p>See <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use.html">Using IAM Roles</a> for more information on controlling session duration. </p> </note>

    Args:
        domain: <p> The name of the domain that is in scope for the generated authorization token. </p>
        domain_owner: <p> The 12-digit account number of the Amazon Web Services account that owns the domain. It does not include dashes or spaces. </p>
        duration_seconds: <p>The time, in seconds, that the generated authorization token is valid. Valid values are <code>0</code> and any number between <code>900</code> (15 minutes) and <code>43200</code> (12 hours). A value of <code>0</code> will set the expiration of the authorization token to the same expiration of the user's role's temporary credentials.</p>

    Raises:
        capo_codeartifact.errors.access_denied_exception.AccessDeniedException: <p> The operation did not succeed because of an unauthorized access attempt. </p>
        capo_codeartifact.errors.internal_server_exception.InternalServerException: <p> The operation did not succeed because of an error that occurred inside CodeArtifact. </p>
        capo_codeartifact.errors.resource_not_found_exception.ResourceNotFoundException: <p> The operation did not succeed because the resource requested is not found in the service. </p>
        capo_codeartifact.errors.throttling_exception.ThrottlingException: <p> The operation did not succeed because too many requests are sent to the service. </p>
        capo_codeartifact.errors.validation_exception.ValidationException: <p> The operation did not succeed because a parameter in the request was sent with an invalid value. </p>
        capo_codeartifact.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_codeartifact.types.get_authorization_token_request.GetAuthorizationTokenRequest]",
    ) -> OperationResponse[
        "capo_codeartifact.types.get_authorization_token_result.GetAuthorizationTokenResult"
    ]:
        import capo_codeartifact._operations.code_artifact_control_plane_service.get_authorization_token

        output, http_response = (
            capo_codeartifact._operations.code_artifact_control_plane_service.get_authorization_token.get_authorization_token(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("GetAuthorizationToken")
    )
    input_: capo_codeartifact.types.get_authorization_token_request.GetAuthorizationTokenRequest = {
        "domain": domain
    }
    if domain_owner is not None:
        input_["domain_owner"] = domain_owner
    if duration_seconds is not None:
        input_["duration_seconds"] = duration_seconds

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output