def get_token(): log.info("%s" % dict(request.query)) code = request.query.get('code','') if memcache.get("oauth:%s" % request.query.get('state','')) != "session_id": abort(500, "Invalid state") token_url = "https://api.dropbox.com/1/oauth2/token" log.info(request.url) result = Struct(fetch(token_url, urllib.urlencode({ "code" : code, "grant_type" : "authorization_code", "client_id" : settings.dropbox.app_key, "client_secret": settings.dropbox.app_secret, "redirect_uri" : "http://localhost:8080/authorize/confirmation" }))) if result.status == 200: try: r = Struct(json.loads(result.data)) r.id = "default" log.info(r) t = DropboxToken(**r) t.put() except: log.error("%s", traceback.format_exc()) return result
def get_token(): access_token = memcache.get(TOKEN_KEY, namespace=NS_TOKEN) if not access_token: log.warn("Access token not in memcache") try: token = DropboxToken.get_by_id(TOKEN_KEY) access_token = token.access_token memcache.set(TOKEN_KEY, access_token, namespace=NS_TOKEN) log.info("Access token in memcache") except Exception as e: log.error("Unable to retrieve token from NDB: %s" % e) return access_token
def dump_key(): return str(DropboxToken.get_by_id('default'))