def google_app_authorize(request): local_redirect = request.values.get("redirect_url", None) scope = request.values.get("scope", None) if not (local_redirect or scope): return BadRequest() request.session["local_redirect"] = local_redirect # request.session['scope'] = scope google_auth = GoogleAuth(settings.GOOGLE_OAUTH_CONSUMER_KEY, settings.GOOGLE_OAUTH_CONSUMER_SECRET) # scope = "https://www.google.com/m8/feeds/" request_token = google_auth.get_request_token(parameters={"scope": scope}) request.session["google_request_token"] = request_token.to_string() callback_url = url_for("backup_bridge/google_app_oauth_callback", _external=True) url = google_auth.get_authorization_url(request_token, callback_url=callback_url) return redirect(url)
def google_app_oauth_callback(request): request_token = GoogleAuth.token_from_string(request.session["google_request_token"]) del request.session["google_request_token"] google_auth = GoogleAuth(settings.GOOGLE_OAUTH_CONSUMER_KEY, settings.GOOGLE_OAUTH_CONSUMER_SECRET) # scope = 'https://www.google.com/m8/feeds/' local_redirect = request.session.get("local_redirect", None) request.session.pop("local_redirect", None) try: access_token = google_auth.get_access_token(request_token) url = "%s?access_token=%s" % (local_redirect, urllib.quote(access_token.to_string())) return redirect(url) except: url = "%s?access_token=" % (local_redirect,) return redirect(url)