digitaldavidg / gdata-python-client

Automatically exported from code.google.com/p/gdata-python-client
0 stars 0 forks source link

AuthSubTokenInfo exception #440

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. AppEngine project based on 
http://code.google.com/p/gdata-mashups/source/browse/trunk/src/contacts%2Bcalend
ar%2Bappengine/main.py
2. Pieces of source code:
class ProjectHandler(webapp.RequestHandler):
    def get(self):
        # Get the current user
        self.current_user = users.GetCurrentUser()
        if not self.current_user:
            self.redirect(users.create_login_url(self.request.uri))
            return
        # Manage our Authentication for the user
        self.ManageAuth()
        self.LookupToken()
        if not self.client.GetAuthSubToken():
            self.redirect(self.client.GenerateAuthSubURL(
              self.request.uri, (gdata.service.CLIENT_LOGIN_SCOPES['cl'][0], 
                gdata.service.CLIENT_LOGIN_SCOPES['cl'][1]),
              secure=False, session=True).to_string())
            return

        # exception here
        info = self.client.AuthSubTokenInfo()

    def ManageAuth(self):
        self.client = gdata.service.GDataService()
        gdata.alt.appengine.run_on_appengine(self.client)
        # The one time use token value from the URL after the AuthSub redirect.
        auth_sub_token = self.request.get('token', None)
        if auth_sub_token and not self.client.GetAuthSubToken():
            # Upgrade to a session token and store the session token.
            self.UpgradeAndStoreToken(auth_sub_token)

    def LookupToken(self):
        if self.current_user:
            stored_tokens = StoredToken.gql('WHERE user_email = :1',
                self.current_user.email())
        for token in stored_tokens:
            self.client.SetAuthSubToken(token.session_token)
            return

    def UpgradeAndStoreToken(self, auth_sub_token):
        self.client.SetAuthSubToken(auth_sub_token)
        self.client.UpgradeToSessionToken()
        if self.current_user:
            # Create a new token object for the data store which associates the
            # session token with the requested URL and the current user.
            new_token = StoredToken(user_email=self.current_user.email(),
                session_token=self.client.GetAuthSubToken())
            new_token.put()
            #self.redirect('http://%s/' % HOST_NAME)

What is the expected output? What do you see instead?
Expected some result or RequestError exception.
I see:
Traceback (most recent call last):
  File "C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 511, in __call__
    handler.get(*groups)
  File "C:\proj\main.py", line 104, in get
    info = self.client.AuthSubTokenInfo()
  File "C:\proj\gdata\service.py", line 938, in AuthSubTokenInfo
    token = self.token_store.find_token(scopes[0])
TypeError: 'NoneType' object is unsubscriptable

What version of the product are you using?
gdata-2.0.11.final.tar.gz
GoogleAppEngine-1.3.7.msi
python-2.5.4.msi

Please provide any additional information below.

Original issue reported on code.google.com by Sergey.Shishmintzev@gmail.com on 1 Sep 2010 at 8:25

GoogleCodeExporter commented 9 years ago
GDataService.RevokeAuthSubToken has same issue.

It is can be fix by following code:
    scopes = lookup_scopes(self.service)
    if scopes:
      token = self.token_store.find_token(scopes[0])
    else:
      token = self.token_store.find_token(atom.token_store.SCOPE_ALL)
instead of:
    scopes = lookup_scopes(self.service)
    token = self.token_store.find_token(scopes[0])

Original comment by Sergey.Shishmintzev@gmail.com on 1 Sep 2010 at 9:12

GoogleCodeExporter commented 9 years ago
Wouldn't it be more appropriate for AuthSubTokenInfo() to return None if 
lookup_scopes() returns None?

Original comment by joe.gregorio@gmail.com on 10 Sep 2010 at 2:38