def check_auth(): api_key = request.headers.get("Authorization") or request.args.get("api_key") if session.get("id"): request.account = Account.by_github_id(session.get("id")) if request.account is None: del session["id"] raise Unauthorized() elif api_key is not None: request.account = Account.by_api_key(api_key) if request.account is None: raise Unauthorized() else: request.account = None
def check_auth(): api_key = request.headers.get('Authorization') \ or request.args.get('api_key') if session.get('id'): request.account = Account.by_github_id(session.get('id')) if request.account is None: del session['id'] raise Unauthorized() elif api_key is not None: request.account = Account.by_api_key(api_key) if request.account is None: raise Unauthorized() else: request.account = None
def authorized(resp): if not "access_token" in resp: return redirect(url_for("index")) access_token = resp["access_token"] session["access_token"] = access_token, "" res = requests.get("https://api.github.com/user?access_token=%s" % access_token, verify=False) for k, v in res.json.items(): session[k] = v account = Account.by_github_id(res.json.get("id")) if account is None: account = Account.create(res.json) db.session.commit() flash("Welcome back, %s." % account.login, "success") return redirect(url_for("index"))
def authorize(): token = oauth.github.authorize_access_token() resp = oauth.github.get('user', token=token) profile = resp.json() for k, v in profile.items(): session[k] = v account = Account.by_github_id(profile.get('id')) if account is None: if app.config.get('SIGNUP_DISABLED'): raise Forbidden("Sorry, account creation is disabled") Account.create(profile) db.session.commit() return redirect('/')
def authorized(resp): if "access_token" not in resp: return redirect(url_for("index")) access_token = resp["access_token"] session["access_token"] = access_token, "" res = requests.get("https://api.github.com/user?access_token=%s" % access_token, verify=False) data = res.json() for k, v in data.items(): session[k] = v account = Account.by_github_id(data.get("id")) if account is None: account = Account.create(data) db.session.commit() return redirect("/")
def authorized(resp): if not 'access_token' in resp: return redirect(url_for('index')) access_token = resp['access_token'] session['access_token'] = access_token, '' res = requests.get('https://api.github.com/user?access_token=%s' % access_token, verify=False) data = res.json() for k, v in data.items(): session[k] = v account = Account.by_github_id(data.get('id')) if account is None: account = Account.create(data) db.session.commit() return redirect('/')
def authorized(resp): if not 'access_token' in resp: return redirect(url_for('index')) access_token = resp['access_token'] session['access_token'] = access_token, '' res = requests.get('https://api.github.com/user?access_token=%s' % access_token, verify=False) for k, v in res.json.items(): session[k] = v account = Account.by_github_id(res.json.get('id')) if account is None: account = Account.create(res.json) db.session.commit() flash("Welcome back, %s." % account.login, "success") return redirect(url_for('index'))
def authorized(resp): if not 'access_token' in resp: return redirect(url_for('index')) access_token = resp['access_token'] session['access_token'] = access_token, '' res = requests.get('https://api.github.com/user?access_token=%s' % access_token, verify=False) print [res.content] for k, v in res.json.items(): session[k] = v account = Account.by_github_id(res.json.get('id')) if account is None: account = Account.create(res.json) db.session.commit() flash("Welcome back, %s." % account.login, "success") return redirect(url_for('index'))
def authorized(resp): if 'access_token' not in resp: return redirect(url_for('index')) access_token = resp['access_token'] session['access_token'] = access_token, '' res = requests.get('https://api.github.com/user?access_token=%s' % access_token, verify=False) data = res.json() for k, v in data.items(): session[k] = v account = Account.by_github_id(data.get('id')) if account is None: if app.config.get('SIGNUP_DISABLED'): raise Forbidden("Sorry, account creation is disabled") account = Account.create(data) db.session.commit() return redirect('/')