Skip to content

create_o_auth2_token async

create_o_auth2_token(
    token_input: CreateOAuth2TokenRequestBody,
    *,
    config_overrides: Optional[AsyncSigninClientConfig] = None,
) -> CreateOAuth2TokenResponse

Exchanges an authorization code or refresh token for an OAuth 2.0 access token and refresh token.

Parameters:

  • token_input (CreateOAuth2TokenRequestBody) –

    Flattened token operation inputs. The "grant_type" in the request body determines the specific operation.

Raises:

Source code in docs_src/capo_signin/_services/async_signin.py
async def create_o_auth2_token(
    self,
    token_input: "capo_signin.types.create_o_auth2_token_request_body.CreateOAuth2TokenRequestBody",
    *,
    config_overrides: Optional[AsyncSigninClientConfig] = None,
) -> "capo_signin.types.create_o_auth2_token_response.CreateOAuth2TokenResponse":
    """Exchanges an authorization code or refresh token for an OAuth 2.0 access token and refresh token.

    Args:
        token_input: Flattened token operation inputs. The "grant_type" in the request body determines the specific operation.

    Raises:
        capo_signin.errors.access_denied_exception.AccessDeniedException: You do not have sufficient access to perform this action.
        capo_signin.errors.internal_server_exception.InternalServerException: The request failed because of an internal server error.
        capo_signin.errors.too_many_requests_error.TooManyRequestsError: The request failed because you exceeded the request rate limit for this operation.
        capo_signin.errors.validation_exception.ValidationException: The request failed because it contains a malformed, missing, or invalid parameter.
        capo_signin.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_signin.types.create_o_auth2_token_request.CreateOAuth2TokenRequest]",
    ) -> AsyncOperationResponse[
        "capo_signin.types.create_o_auth2_token_response.CreateOAuth2TokenResponse"
    ]:
        import capo_signin._operations.signin.create_o_auth2_token

        (
            output,
            http_response,
        ) = await capo_signin._operations.signin.create_o_auth2_token.async_create_o_auth2_token(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_signin.types.create_o_auth2_token_request.CreateOAuth2TokenRequest",
    ) -> dict[str, Any]:
        import capo_signin.types.create_o_auth2_token_request

        return capo_signin.types.create_o_auth2_token_request.redact_sensitive(
            input_
        )

    def _redact_output(
        output: "capo_signin.types.create_o_auth2_token_response.CreateOAuth2TokenResponse",
    ) -> dict[str, Any]:
        import capo_signin.types.create_o_auth2_token_response

        return capo_signin.types.create_o_auth2_token_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "CreateOAuth2Token",
            redact_input=_redact_input,
            redact_output=_redact_output,
        ),
    )
    input_: capo_signin.types.create_o_auth2_token_request.CreateOAuth2TokenRequest = {
        "token_input": token_input
    }

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output