How can I use flask to validate the Token for a webhook subscription?
Im trying to get a ms graph subscription going in my app but when I send the subscription request to:
And get the follow-up request FROM ms grap to my endpoint (ValidateSubscription), flask refuses to parse it because of its incorrect mediatype which IS text/plain. So far Ive tried using flask-accept module to parse the response like this:
class ValidateSubscription(Resource):
@accept('text/plain')
def post:
if flask.request.args.get("validationToken"):
token = flask.request.args.get('validationToken')
return Response(status=200, mimetype='text/plain', response=token)
else:
# process notification
pass
but it didnt work and I got the same error.
Also Ive tried to add an api representation to my flask app like this:
@api.representation('text/plain')
def output_text(data, code, headers=None):
resp = flask.make_response(data, code, headers)
resp.headers.extend(headers or {})
return resp
When I print out api.representations I see:
OrderedDict([('application/json', <function output_json at 0x7f872b021424>), ('text/plain', <function output_text at 0x7f8728d04214>)])
And I still get the same exact error without change whatsoever. Is there a better way to allow flask-restful to accept a text/plain header or am I doing something wrong? Maybe there is a way to send the token as json from the subscriptions
endpoint?