diff --git a/ihatemoney/api/common.py b/ihatemoney/api/common.py index c33ee70c..fa097dec 100644 --- a/ihatemoney/api/common.py +++ b/ihatemoney/api/common.py @@ -35,7 +35,9 @@ def need_auth(f): auth_token = auth_header.split(" ")[1] except IndexError: abort(401) - project_id = Project.verify_token(auth_token, token_type="auth", project_id=project_id) + project_id = Project.verify_token( + auth_token, token_type="auth", project_id=project_id + ) if auth_token and project_id: project = Project.query.get(project_id) if project: diff --git a/ihatemoney/models.py b/ihatemoney/models.py index ddf9b714..2a4cf3a4 100644 --- a/ihatemoney/models.py +++ b/ihatemoney/models.py @@ -367,7 +367,8 @@ class Project(db.Model): :param token: Serialized TimedJsonWebToken :param token_type: Either "auth" for authentication (invalidated when project code changed), or "reset" for password reset (invalidated after expiration) - :param project_id: Project ID. Used for token_type "auth" to use the password as serializer secret key. + :param project_id: Project ID. Used for token_type "auth" to use the password as serializer + secret key. :param max_age: Token expiration time (in seconds). Only used with token_type "reset" """ loads_kwargs = {} @@ -378,7 +379,7 @@ class Project(db.Model): loads_kwargs["max_age"] = max_age else: project = Project.query.get(project_id) - password = project.password if project is not None else '' + password = project.password if project is not None else "" serializer = URLSafeSerializer( current_app.config["SECRET_KEY"] + password, salt=token_type ) @@ -390,7 +391,9 @@ class Project(db.Model): return None data_project = data.get("project_id") - return data_project if project_id is None or data_project == project_id else None + return ( + data_project if project_id is None or data_project == project_id else None + ) def __str__(self): return self.name diff --git a/ihatemoney/tests/api_test.py b/ihatemoney/tests/api_test.py index 0894b15b..83d5aa2a 100644 --- a/ihatemoney/tests/api_test.py +++ b/ihatemoney/tests/api_test.py @@ -213,7 +213,9 @@ class APITestCase(IhatemoneyTestCase): "/api/projects/raclette/token", headers=self.get_auth("raclette") ) decoded_resp = json.loads(resp.data.decode("utf-8")) - resp = self.client.get(f"/authenticate?token={decoded_resp['token']}&project_id=raclette") + resp = self.client.get( + f"/authenticate?token={decoded_resp['token']}&project_id=raclette" + ) # Test that we are redirected. self.assertEqual(302, resp.status_code) diff --git a/ihatemoney/web.py b/ihatemoney/web.py index 0f75d640..47df3f49 100644 --- a/ihatemoney/web.py +++ b/ihatemoney/web.py @@ -206,7 +206,9 @@ def authenticate(project_id=None): # Try to get project_id from token first token = request.args.get("token") if token: - project_id = Project.verify_token(token, token_type="auth", project_id=project_id) + project_id = Project.verify_token( + token, token_type="auth", project_id=project_id + ) token_auth = True else: token_auth = False