(request, service_account="default", scopes=None)
return token_json["access_token"], token_expiry
Get the OAuth 2.0 access token for a service account.

    Args:
        request (google.auth.transport.Request): A callable used to make
            HTTP requests.
        service_account (str): The string 'default' or a service account email
            address. The determines which service account for which to acquire
            an access token.
        scopes (Optional[Union[str, List[str]]]): Optional string or list of
            strings with auth scopes.
    Returns:
        Union[str, datetime]: The access token and its expiration.

    Raises:
        google.auth.exceptions.TransportError: if an error occurred while
            retrieving metadata.
Get the OAuth 2.0 access token for a service account.
Get the OAuth 2 . 0 access token for a service account .
def get_service_account_token(request, service_account="default", scopes=None):
    """Get the OAuth 2.0 access token for a service account.

    Args:
        request (google.auth.transport.Request): A callable used to make
            HTTP requests.
        service_account (str): The string 'default' or a service account email
            address. The determines which service account for which to acquire
            an access token.
        scopes (Optional[Union[str, List[str]]]): Optional string or list of
            strings with auth scopes.
    Returns:
        Union[str, datetime]: The access token and its expiration.

    Raises:
        google.auth.exceptions.TransportError: if an error occurred while
            retrieving metadata.
    """
    if scopes:
        if not isinstance(scopes, str):
            scopes = ",".join(scopes)
        params = {"scopes": scopes}
    else:
        params = None

    path = "instance/service-accounts/{0}/token".format(service_account)
    token_json = get(request, path, params=params)
    token_expiry = _helpers.utcnow() + datetime.timedelta(
        seconds=token_json["expires_in"]
    )
    return token_json["access_token"], token_expiry
def get_service_account_token ( request , service_account = "default" , scopes = None ) : if scopes : if not isinstance ( scopes , str ) : scopes = "," . join ( scopes ) params = { "scopes" : scopes } else : params = None path = "instance/service-accounts/{0}/token" . format ( service_account ) token_json = get ( request , path , params = params ) token_expiry = _helpers . utcnow ( ) + datetime . timedelta ( seconds = token_json [ "expires_in" ] ) return token_json [ "access_token" ] , token_expiry