# google-auth 2.62.0 (Apache-2.0), harvested by tools/harvest_corpus.py
=== input
Fetch the ID Token from the current environment.

    This function acquires ID token from the environment in the following order.
    See https://google.aip.dev/auth/4110.

    1. If the environment variable ``GOOGLE_APPLICATION_CREDENTIALS`` is set
       to the path of a valid service account JSON file, then ID token is
       acquired using this service account credentials.
    2. If the application is running in Compute Engine, App Engine or Cloud Run,
       then the ID token are obtained from the metadata server.
    3. If metadata server doesn't exist and no valid service account credentials
       are found, :class:`~google.auth.exceptions.DefaultCredentialsError` will
       be raised.

    Example::

        import google.oauth2.id_token
        import google.auth.transport.requests

        request = google.auth.transport.requests.Request()
        target_audience = "https://pubsub.googleapis.com"

        id_token = google.oauth2.id_token.fetch_id_token(request, target_audience)

    Args:
        request (google.auth.transport.Request): A callable used to make
            HTTP requests.
        audience (str): The audience that this ID token is intended for.
        bind_id_token (Optional[bool]): Controls whether to request a
            certificate-bound ID token from the metadata server identity
            endpoint. If ``True``, requests a bound token whenever a valid
            Agent Identity certificate is available and token binding is not
            disabled via ``GOOGLE_API_ENABLE_RUNTIME_BOUND_TOKEN``, falling back
            to an unbound token otherwise (or raising
            :class:`~google.auth.exceptions.RefreshError` if a configured
            certificate is not found after retries). If ``False``, always
            requests an unbound token. If ``None`` (default), token binding is
            determined automatically by the library. Set ``True`` or ``False``
            explicitly if your application requires a specific behavior. Has no
            effect when credentials are loaded from
            ``GOOGLE_APPLICATION_CREDENTIALS``.

    Returns:
        str: The ID token.

    Raises:
        ~google.auth.exceptions.DefaultCredentialsError:
            If metadata server doesn't exist and no valid service account
            credentials are found.
        ~google.auth.exceptions.RefreshError:
            If an error occurred while fetching the ID token or if a required
            certificate file is not found after retries.
    
=== parse google
short_description: 'Fetch the ID Token from the current environment.'
long_description: |
  This function acquires ID token from the environment in the following order.
  See https://google.aip.dev/auth/4110.
  
  1. If the environment variable ``GOOGLE_APPLICATION_CREDENTIALS`` is set
     to the path of a valid service account JSON file, then ID token is
     acquired using this service account credentials.
  2. If the application is running in Compute Engine, App Engine or Cloud Run,
     then the ID token are obtained from the metadata server.
  3. If metadata server doesn't exist and no valid service account credentials
     are found, :class:`~google.auth.exceptions.DefaultCredentialsError` will
     be raised.
  
  Example::
  
      import google.oauth2.id_token
      import google.auth.transport.requests
  
      request = google.auth.transport.requests.Request()
      target_audience = "https://pubsub.googleapis.com"
  
      id_token = google.oauth2.id_token.fetch_id_token(request, target_audience)
blank_after_short_description: True
blank_after_long_description: True
style: google
- DocstringParam
  description: |
    A callable used to make
    HTTP requests.
  kind: param
  key: 'param'
  arg_name: 'request'
  type_name: 'google.auth.transport.Request'
  is_optional: False
- DocstringParam
  description: 'The audience that this ID token is intended for.'
  kind: param
  key: 'param'
  arg_name: 'audience'
  type_name: 'str'
  is_optional: False
- DocstringParam
  description: |
    Controls whether to request a
    certificate-bound ID token from the metadata server identity
    endpoint. If ``True``, requests a bound token whenever a valid
    Agent Identity certificate is available and token binding is not
    disabled via ``GOOGLE_API_ENABLE_RUNTIME_BOUND_TOKEN``, falling back
    to an unbound token otherwise (or raising
    :class:`~google.auth.exceptions.RefreshError` if a configured
    certificate is not found after retries). If ``False``, always
    requests an unbound token. If ``None`` (default), token binding is
    determined automatically by the library. Set ``True`` or ``False``
    explicitly if your application requires a specific behavior. Has no
    effect when credentials are loaded from
    ``GOOGLE_APPLICATION_CREDENTIALS``.
  kind: param
  key: 'param'
  arg_name: 'bind_id_token'
  type_name: 'Optional[bool]'
  is_optional: False
- DocstringReturns
  description: 'The ID token.'
  kind: returns
  key: 'returns'
  type_name: 'str'
  is_generator: False
- DocstringRaises
  description: |
    If metadata server doesn't exist and no valid service account
    credentials are found.
  kind: raises
  key: 'raises'
  type_name: '~google.auth.exceptions.DefaultCredentialsError'
- DocstringRaises
  description: |
    If an error occurred while fetching the ID token or if a required
    certificate file is not found after retries.
  kind: raises
  key: 'raises'
  type_name: '~google.auth.exceptions.RefreshError'
=== detect
google
=== compose google
Fetch the ID Token from the current environment.

This function acquires ID token from the environment in the following order.
See https://google.aip.dev/auth/4110.

1. If the environment variable ``GOOGLE_APPLICATION_CREDENTIALS`` is set
   to the path of a valid service account JSON file, then ID token is
   acquired using this service account credentials.
2. If the application is running in Compute Engine, App Engine or Cloud Run,
   then the ID token are obtained from the metadata server.
3. If metadata server doesn't exist and no valid service account credentials
   are found, :class:`~google.auth.exceptions.DefaultCredentialsError` will
   be raised.

Example::

    import google.oauth2.id_token
    import google.auth.transport.requests

    request = google.auth.transport.requests.Request()
    target_audience = "https://pubsub.googleapis.com"

    id_token = google.oauth2.id_token.fetch_id_token(request, target_audience)

Args:
    request (google.auth.transport.Request): A callable used to make
        HTTP requests.
    audience (str): The audience that this ID token is intended for.
    bind_id_token (Optional[bool]): Controls whether to request a
        certificate-bound ID token from the metadata server identity
        endpoint. If ``True``, requests a bound token whenever a valid
        Agent Identity certificate is available and token binding is not
        disabled via ``GOOGLE_API_ENABLE_RUNTIME_BOUND_TOKEN``, falling back
        to an unbound token otherwise (or raising
        :class:`~google.auth.exceptions.RefreshError` if a configured
        certificate is not found after retries). If ``False``, always
        requests an unbound token. If ``None`` (default), token binding is
        determined automatically by the library. Set ``True`` or ``False``
        explicitly if your application requires a specific behavior. Has no
        effect when credentials are loaded from
        ``GOOGLE_APPLICATION_CREDENTIALS``.

Returns:
    str: The ID token.

Raises:
    ~google.auth.exceptions.DefaultCredentialsError: If metadata server doesn't exist and no valid service account
        credentials are found.
    ~google.auth.exceptions.RefreshError: If an error occurred while fetching the ID token or if a required
        certificate file is not found after retries.
