def oauth_callback(): code = request.args.get("code", None) if not code: logging.error("No code, no authorization") abort(500) redirect_uri = helpers.url_for("oauth_callback", _external=True) oauth_helper = OAuthDanceHelper(redirect_uri=redirect_uri) credentials = oauth_helper.step2_exchange(code) client = Client.get_by_id(1) if not client: logging.error("No client object, aborting authorization") abort(500) client.credentials = credentials.to_json() if credentials.refresh_token: client.refresh_token = credentials.refresh_token client.put() return redirect(helpers.url_for("settings"))
def oauth_callback(self): code = request.args.get('code', None) if code: redirect_uri = helpers.url_for('oauth.oauth_callback', _external=True) oauth_helper = OAuthDanceHelper(redirect_uri) credentials = oauth_helper.step2_exchange(code) client = Client.get_by_id(1) if client: client.credentials = credentials.to_json() if credentials.refresh_token: client.refresh_token = credentials.refresh_token client.put() return redirect(helpers.url_for('oauth.index')) else: logging.error('No client object, aborting authorization') abort(500) else: logging.error('No code, no authorization') abort(500)
def oauth_callback(): code = request.args.get('code', None) if not code: logging.error('No code, no authorization') abort(500) state = request.args.get('state', None) if not state: logging.error('No state, no authorization') abort(500) domain_name = urllib.unquote(state) redirect_uri = url_for('oauth_callback', _external=True) oauth_helper = OAuthDanceHelper(redirect_uri=redirect_uri) credentials = oauth_helper.step2_exchange(code) primary_domain = PrimaryDomain.get_or_create(domain_name) primary_domain.credentials = credentials.to_json() if credentials.refresh_token: primary_domain.refresh_token = credentials.refresh_token user = users.get_current_user() primary_domain.admin_email = user.email() primary_domain.put() return redirect(url_for('settings'))