1
0
forked from ScoDoc/ScoDoc
ScoDoc/app/api/tokens.py

24 lines
659 B
Python
Raw Normal View History

2021-09-09 12:49:23 +02:00
from flask import jsonify
2022-05-03 08:55:56 +02:00
from app import db, log
2021-09-09 12:49:23 +02:00
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():
2022-05-03 13:35:17 +02:00
"renvoie un jeton jwt pour l'utilisateur courant"
2021-09-09 12:49:23 +02:00
token = basic_auth.current_user().get_token()
2022-05-03 08:55:56 +02:00
log(f"API: giving token to {basic_auth.current_user()}")
2021-09-09 12:49:23 +02:00
db.session.commit()
return jsonify({"token": token})
@bp.route("/tokens", methods=["DELETE"])
@token_auth.login_required
def revoke_token():
2022-05-03 13:35:17 +02:00
"révoque le jeton de l'utilisateur courant"
2021-09-09 12:49:23 +02:00
token_auth.current_user().revoke_token()
db.session.commit()
return "", 204