ScoDoc/app/api/tokens.py

21 lines
490 B
Python
Raw Permalink Normal View History

2021-09-09 12:49:23 +02:00
from flask import jsonify
from app import db
from app.api import bp
from app.api.auth import basic_auth, token_auth
@bp.route("/tokens", methods=["POST"])
@basic_auth.login_required
def get_token():
token = basic_auth.current_user().get_token()
db.session.commit()
return jsonify({"token": token})
@bp.route("/tokens", methods=["DELETE"])
@token_auth.login_required
def revoke_token():
token_auth.current_user().revoke_token()
db.session.commit()
return "", 204