views:

20

answers:

0

I'm trying to use Google App Engine builtin support for OAuth Provider. I get InvalidOAuthTokenError every time I cal oauth.get_current_user() on the provider side. What I'm doing wrong? Does anyone get this functionality working?

I use this library http://github.com/zbowling/python-oauth2 for OAuth. This is the consumer side code.

class OAuthTestHandler(webapp.RequestHandler):
    def get(self):
        token = oauth.Token(key, secret)
        consumer = oauth.Consumer(CONSUMER_KEY, CONSUMER_SECRET)

        oauth_request = oauth.Request.from_consumer_and_token(consumer, 
                        token=token, http_method='GET', http_url=RESOURCE_URL)
        oauth_request.sign_request(oauth.SignatureMethod_HMAC_SHA1(), consumer, token)

        result = urlfetch.fetch(url=RESOURCE_URL, headers=oauth_request.to_header())

        logging.info("%s" % result.status_code)
        self.response.out.write(result.content)

and this is provider side code

class TestApiHandler(webapp.RequestHandler):
    def get(self):
        try:
            user = oauth.get_current_user()
            self.response.out.write("GOT IT!")
        except Exception, err:
            logging.exception("Failed")
            self.response.out.write("%s" % err)

Getting request token, authorize it and getting access token works without problems.