Ejemplo n.º 1
0
def save_token(token, request, *args, **kwargs):
    Token.delete_by_client_and_user(request.client.client_id, request.user.id)
    expires = datetime.now() + timedelta(seconds=_THOUSAND_DAY)

    return Token.create(
        request.client.client_id,
        request.user.id,
        token["token_type"],
        token["access_token"],
        token["refresh_token"],
        expires,
        token["scope"],
    )
Ejemplo n.º 2
0
def delete_token():
    token_id = request.form['token']
    token = Token.get(token_id)
    if not token:
        return jsonify({'message': 'not found'}), 404
    if token.user_id != g.user.id:
        return jsonify({'message': 'not allowed'}), 403
    token.delete()
    return jsonify({'message': 'ok'})
Ejemplo n.º 3
0
def delete_token():
    token_id = request.form["token"]
    token = Token.get(token_id)
    if not token:
        return {"message": "not found"}, 404
    if token.user_id != g.user.id:
        return {"message": "not allowed"}, 403
    token.delete()
    return {"message": "ok"}
Ejemplo n.º 4
0
def load_token(access_token=None, refresh_token=None):
    if access_token:
        return Token.get_by_access(access_token)
    return Token.get_by_refresh(refresh_token)
Ejemplo n.º 5
0
def authorized_tokens():
    tokens = Token.get_by_user(g.user.id, g.start, g.limit)
    return render_template('authorized.html', tokens=tokens)