Attempting to authorize without scopes would fail, unfortunately. That's
why I guard against it.


On Thu, May 29, 2014 at 10:54 AM, Craig Citro <notifications@github.com>
wrote:

> In googleapiclient/discovery.py:
>
> > @@ -249,6 +255,21 @@ def build_from_document(
> >    base = urlparse.urljoin(service['rootUrl'], service['servicePath'])
> >    schema = Schemas(service)
> >
> > +  if credentials:
> > +    should_authorize = True
> > +    if credentials.create_scoped_required():
> > +      if ('auth' in service and
> > +          'oauth2' in service['auth'] and
> > +          'scopes' in service['auth']['oauth2']):
> > +        credentials = credentials.create_scoped(
> > +            service['auth']['oauth2']['scopes'].keys())
> > +      else:
> > +        # No need to authorize the http object
> > +        # if the service does not require authentication.
> > +        should_authorize = False
> > +    if should_authorize:
> > +      http = credentials.authorize(http)
>
> Is there any harm in authorizing the http instance in the case that no
> scopes are required? In particular, I feel like we can simplify our lives:
>
> if credentials:
>   if credentials.create_scoped_required():
>     credentials = credentials.create_scoped()
>   http = credentials.authorize(http)
>
> Now the logic is pretty clear: if we have credentials, we're going to
> authorize the http instance; if we have the default credentials, we first
> possibly create a scoped token from those.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/google/google-api-python-client/pull/4/files#r13194301>
> .
>



-- 
Orest Bolohan

Software Engineer
Cloud/TI Identity and Access Management Services
Google Inc.
Mountain View, CA

(650) 214 3458
orest@google.com