'Returns the OAuth2 token_uri, or None to use the default URI.
Returns:
A string that is the token_uri, or None.
Raises:
RuntimeError: The user has requested authentication for a service account
but the environment is not correct for that to work.'

def _GetTokenUri(self):

    if self.options.authenticate_service_account:
        url = ('%s/%s/scopes' % (METADATA_BASE, SERVICE_ACCOUNT_BASE))
        try:
            vm_scopes_string = self.read_url_contents(url)
        except urllib2.URLError as e:
            raise RuntimeError(('Could    not    obtain    scope    list    from    metadata    service:    %s:    %s.    This    may    be    because    we    are    not    running    in    a    Google    Compute    Engine    VM.' % (url, e)))
        vm_scopes = vm_scopes_string.split()
        missing = list(set(self.oauth_scopes).difference(vm_scopes))
        if missing:
            raise RuntimeError(('Required    scopes    %s    missing    from    %s.    This    VM    instance    probably    needs    to    be    recreated    with    the    missing    scopes.' % (missing, vm_scopes)))
        return ('%s/%s/token' % (METADATA_BASE, SERVICE_ACCOUNT_BASE))
    else:
        return None
