Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include project code into project authentication token #802

Merged
merged 11 commits into from
Oct 10, 2021
Prev Previous commit
Next Next commit
simplify the token
Keep it in a list, for forward compatibillity
  • Loading branch information
Glandos committed Sep 16, 2021
commit 6c0d0e22b084f94f0a0df1e5e1ec5b61ea72df7c
6 changes: 3 additions & 3 deletions ihatemoney/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,12 +350,12 @@ def generate_token(self, token_type="auth"):
serializer = URLSafeTimedSerializer(
current_app.config["SECRET_KEY"], salt=token_type
)
token = serializer.dumps({"project_id": self.id})
token = serializer.dumps([self.id])
else:
serializer = URLSafeSerializer(
current_app.config["SECRET_KEY"] + self.password, salt=token_type
)
token = serializer.dumps({"project_id": self.id})
token = serializer.dumps([self.id])

return token

Expand Down Expand Up @@ -390,7 +390,7 @@ def verify_token(token, token_type="auth", project_id=None, max_age=3600):
except BadSignature:
return None

data_project = data.get("project_id")
data_project = data[0] if isinstance(data, list) else None
return (
data_project if project_id is None or data_project == project_id else None
)
Expand Down