Beispiel #1
0
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
Beispiel #2
0
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
Beispiel #3
0
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
Beispiel #4
0
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"))
Beispiel #5
0
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('/')
Beispiel #6
0
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('/')
Beispiel #8
0
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('/')
Beispiel #9
0
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'))
Beispiel #10
0
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'))
Beispiel #11
0
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('/')