python3-launchpadlib credentials.py broken for new auth creds

Bug #1583741 reported by Brad Figg
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
launchpadlib
New
Undecided
Unassigned

Bug Description

The authorization page:
 (https://launchpad.net/+authorize-token?oauth_token=q6jtzNhdL91dHMtKx3sz&allow_permission=DESKTOP_INTEGRATION)
should be opening in your browser. Use your browser to authorize
this program to access Launchpad on your behalf.
Waiting to hear from Launchpad about your decision...
Created new window in existing browser session.
Traceback (most recent call last):
  File "./bug", line 94, in <module>
    exit(app.main())
  File "./bug", line 61, in main
    lp = s.lp
  File "./bug", line 52, in lp
    s._lp = Launchpad('random').service
  File "./bug", line 34, in __init__
    version='devel')
  File "/usr/lib/python3/dist-packages/launchpadlib/launchpad.py", line 544, in login_with
    credential_save_failed, version)
  File "/usr/lib/python3/dist-packages/launchpadlib/launchpad.py", line 351, in _authorize_token_and_login
    credentials = authorization_engine(credentials, credential_store)
  File "/usr/lib/python3/dist-packages/launchpadlib/credentials.py", line 545, in __call__
    self.make_end_user_authorize_token(credentials, request_token_string)
  File "/usr/lib/python3/dist-packages/launchpadlib/credentials.py", line 658, in make_end_user_authorize_token
    self.web_root)
  File "/usr/lib/python3/dist-packages/launchpadlib/credentials.py", line 233, in exchange_request_token_for_access_token
    self.access_token = AccessToken.from_string(content)
  File "/usr/lib/python3/dist-packages/launchpadlib/credentials.py", line 251, in from_string
    key = params['oauth_token']
KeyError: 'oauth_token'

I worked around the problem with the following horrible, hack:
  class AccessToken(_AccessToken):
      """An OAuth access token."""

      @classmethod
      def from_params(cls, params):
          """Create and return a new `AccessToken` from the given dict."""
          key = params['oauth_token']
          secret = params['oauth_token_secret']
          context = params.get('lp.context')
          return cls(key, secret, context)

      @classmethod
      def from_string(cls, query_string):
          """Create and return a new `AccessToken` from the given string."""
          params = cgi.parse_qs(query_string, keep_blank_values=False)
          p = {}
          for x in params:
              k = x.decode('utf-8')
              p[k] = []
              p[k].append(params[x][0].decode('utf-8'))
          key = p['oauth_token']
          assert len(key) == 1, (
              "Query string must have exactly one oauth_token.")
          key = key[0]
          secret = p['oauth_token_secret']
          assert len(secret) == 1, "Query string must have exactly one secret."
          secret = secret[0]
          context = params.get('lp.context')
          if context is not None:
              assert len(context) == 1, (
                  "Query string must have exactly one context")
              context = context[0]
          return cls(key, secret, context)

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.