I am building a RESTful API for an upcoming project. This needs some kind of user account verification. I implemented a token based confirmation procedure previously using itsdangerous. But I wonder wether I can accomplish the same by using JWT-Extended, as its already part of my app and I want to keep the number of dependencies as low as possible.
Could I just use a normal access_token for that?
I appreciate your help!
Edit:
I implemented the following two methods and they seem to work. I am just not sure, if this is considered good practice.
@blueprint.route('/gen_confirmation_token', methods=['GET'])
@jwt_required
def gen_confirmation_token():
access_token = create_access_token(identity=get_jwt_identity(), user_claims={"confirm": True}, expires_delta=dt.timedelta(seconds=3600))
# TODO send a link to mail
return jsonify({"message": "confirmation token sent"}), 200
@blueprint.route('/confirm/<string:token>', methods=['GET'])
@jwt_required
def confirm_user(token):
user_identity = get_jwt_identity()
current_user = User.query.get(user_identity)
decoded_token = decode_token(token)
if decoded_token['identity'] == user_identity and decoded_token['user_claims'].get('confirm', False):
current_user.confirm()
return jsonify({"message": "user confirmed"}), 200
return jsonify({"message": "invalid confirmation token"}), 400