Example #1
0
def handle_error_response(response_body):
    """Translates an error response from an OAuth operation into an
    OAuthError exception.

    Args:
        response_body (str): The decoded response data.

    Raises:
        google.auth.exceptions.OAuthError
    """
    try:
        error_components = []
        error_data = json.loads(response_body)

        error_components.append("Error code {}".format(error_data["error"]))
        if "error_description" in error_data:
            error_components.append(": {}".format(
                error_data["error_description"]))
        if "error_uri" in error_data:
            error_components.append(" - {}".format(error_data["error_uri"]))
        error_details = "".join(error_components)
    # If no details could be extracted, use the response data.
    except (KeyError, ValueError):
        error_details = response_body

    raise exceptions.OAuthError(error_details, response_body)
Example #2
0
 def _inject_authenticated_request_body(self, request_body):
     if (self._client_authentication is not None
             and self._client_authentication.client_auth_type is
             ClientAuthType.request_body):
         if request_body is None:
             raise exceptions.OAuthError(
                 "HTTP request does not support request-body")
         else:
             request_body[
                 "client_id"] = self._client_authentication.client_id
             request_body["client_secret"] = (
                 self._client_authentication.client_secret or "")