Frage

The Using GAE / Decorators guide tells me that "you need to add a specific URL handler to your application to handle the redirection from the authorization server back to your application":

  def main():
    application = webapp.WSGIApplication(
       [
         ('/', MainHandler),
         ('/about', AboutHandler),
         (decorator.callback_path, decorator.callback_handler()),
       ],
       debug=True)
    run_wsgi_app(application)

Currently I am unable to properly set this up. As a result, I get and see the HTTP 302 callback response (while it should be caught by the handler) instead of the response I'm expecting. I have two questions to address that:

  1. The oauth2client/appengine.py shipping in GAE 1.8.0 has no callback_path attribute and no callback_handler() method, what are we supposed to do? Directly bind ('/oauth2callback', OAuth2Handler) instead of (decorator.callback_path, decorator.callback_handler())?
  2. What does that imply for myapp.yaml? Is it right to declare a new block like:
    - url: /oauth2callback
      script: oauth2client/appengine.py

Thanks for your help! Here is my current code:


myapp.py

class UpdatePage(webapp2.RequestHandler):

    def get(self):
        playlist_id = self.youtube_create_playlist()
        ...

    @decorator.oauth_required
    def youtube_create_playlist(self):
        http = decorator.http()
        request = youtube.playlists().insert(...)
        response = request.execute(http=http)
        return response["id"]

    ...

    update = webapp2.WSGIApplication([
                                      ('/update', UpdatePage),
                                      ('/oauth2callback', OAuth2Handler)
                                      ],
                                     debug=True)

app.yaml

application: myapp
version: 1
runtime: python27
api_version: 1
threadsafe: false

handlers:
- url: /
  static_files: index.html
  upload: index.html

- url: /oauth2callback
  script: oauth2client/appengine.py

- url: /update
  script: myapp.update
War es hilfreich?

Lösung

This library does not ship in App Engine.

The version you should be using is google-api-python-client-1.1 hosted on the project download page.

I believe the version you're referring to is the (somewhat old) version of google-api-python-client included in the App Engine SDK. This is only included to perform simple OAuth 2.0 for appcfg.py and is a stable version for performing this simple task. Though it is in the SDK, it is NOT in the runtime and not endorsed as a current version of google-api-python-client for these reasons.

I'd also like to note that the article you linked explicitly points to installation instructions.

UPDATE: As noted there, your WSGI handler should contain the callback from the decorator

routes = [
    ('/update', UpdatePage),
    (decorator.callback_path, decorator.callback_handler()),
]
update = webapp2.WSGIApplication(routes, debug=True)

and your app.yaml should allow your main handler should either explicitly match the the route in decorator.callback_path

- url: /oauth2callback
  script: myapp.update

or should just route all remaining requests to your WSGI handler

- url: /.*
  script: myapp.update

(This second approach would likely warrant adding a 404 catch-all to the WSGI handler.)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top