0
0
Fork 0
mirror of https://github.com/alerta/alerta.git synced 2025-01-24 09:19:40 +00:00
alerta_alerta/alerta/auth/userinfo.py
Nick Satterly 49ec257e76
Add attributes field to heartbeat for use in hb alerts (#1128)
* Add attributes field to heartbeat for use in hb alerts

* Whitespace fix for pre-commit hook to pass
2020-01-25 13:03:35 +01:00

25 lines
668 B
Python

import re
from flask import jsonify, request
from flask_cors import cross_origin
from alerta.auth.decorators import permission
from alerta.exceptions import ApiError
from alerta.models.enums import Scope
from alerta.models.token import Jwt
from . import auth
@auth.route('/userinfo', methods=['OPTIONS', 'GET'])
@cross_origin()
@permission(Scope.read_userinfo)
def userinfo():
auth_header = request.headers.get('Authorization', '')
m = re.match(r'Bearer (\S+)', auth_header)
token = m.group(1) if m else None
if token:
return jsonify(Jwt.parse(token).serialize)
else:
raise ApiError('Missing authorization Bearer token', 401)