mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 09:15:41 +00:00
28 lines
726 B
Python
28 lines
726 B
Python
|
from flask_restx import Namespace, Resource
|
||
|
from .auth import basic_auth, token_auth
|
||
|
from .. import db
|
||
|
|
||
|
|
||
|
ns = Namespace('token', description='Authentication token operations')
|
||
|
|
||
|
|
||
|
@ns.route('/')
|
||
|
class Token(Resource):
|
||
|
'''Get or revoke a user authentication token'''
|
||
|
|
||
|
@ns.doc(security='basicAuth')
|
||
|
@basic_auth.login_required
|
||
|
def post(self):
|
||
|
'''Get user token'''
|
||
|
token = basic_auth.current_user().get_token()
|
||
|
db.session.commit()
|
||
|
return {'token': 'Bearer ' + token}
|
||
|
|
||
|
@ns.doc(security='apiKey')
|
||
|
@token_auth.login_required
|
||
|
def delete(self):
|
||
|
'''Revoke user token'''
|
||
|
token_auth.current_user().revoke_token()
|
||
|
db.session.commit()
|
||
|
return '', 204
|