Sbef98 / IOT

A led is enough somtimes
Apache License 2.0
0 stars 1 forks source link

Protect https queries to cloud #37

Closed Paula-Kli closed 2 years ago

Paula-Kli commented 2 years ago

I have an idea on how to solve it and will do that tomorrow from here

Sbef98 commented 2 years ago

Could you tell me what are you gonna use? Something like jwt authentication? https://flask-jwt.readthedocs.io/en/latest/

Paula-Kli commented 2 years ago

Could you tell me what are you gonna use? Something like jwt authentication? https://flask-jwt.readthedocs.io/en/latest/

Oh it is German - sorry yes something like this:

def token_required(f):
   @wraps(f)
   def decorator(*args, **kwargs):

      token = None

      if 'x-access-tokens' in request.headers:
         token = request.headers['x-access-tokens']

      if not token:
         return jsonify({'message': 'a valid token is missing'})

      try:
         data = jwt.decode(token, app.config[SECRET_KEY])
         current_user = Users.query.filter_by(public_id=data['public_id']).first()
      except:
         return jsonify({'message': 'token is invalid'})

        return f(current_user, *args, **kwargs)
   return decorator

without the author... and then the bridge can include the token in the x-access-token http header... or do you have a better recommondation on what to do/ use?

Paula-Kli commented 2 years ago

I would rather not use Flask-JWT as it seems not be updated since 2015 (https://pypi.org/project/Flask-JWT/)