Skip to content

Commit b91fa97

Browse files
fix userid in claim
1 parent eb2b8d5 commit b91fa97

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/sentry/api/endpoints/organization_intercom_jwt.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,12 @@ def get(
6969
user = request.user
7070
now = int(datetime.datetime.now(datetime.UTC).timestamp())
7171
exp = now + JWT_VALIDITY_WINDOW_SECONDS
72+
# intercom creates chat history based on this ID so we need one per (org, user) pair
73+
intercom_user_id = f"{user.id}-{organization.id}"
7274

7375
# Build JWT claims - user_id is required by Intercom
7476
claims = {
75-
"user_id": str(user.id),
77+
"user_id": intercom_user_id,
7678
"email": user.email,
7779
"iat": now,
7880
"exp": exp,
@@ -90,7 +92,7 @@ def get(
9092
created_at = int(user.last_active.timestamp())
9193

9294
user_data = {
93-
"userId": f"{user.id}-{organization.id}",
95+
"userId": intercom_user_id,
9496
"email": user.email,
9597
"name": user.get_display_name(),
9698
"createdAt": created_at,

tests/sentry/api/endpoints/test_organization_intercom_jwt.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def test_get_jwt_without_secret_configured(self) -> None:
2727
def test_get_jwt_success(self) -> None:
2828
"""With feature flag and secret configured, should return JWT and user data."""
2929
test_secret = "test-intercom-secret-key"
30+
intercom_user_id = f"{self.user.id}-{self.organization.id}"
3031

3132
with (
3233
self.feature("organizations:intercom-support"),
@@ -39,7 +40,7 @@ def test_get_jwt_success(self) -> None:
3940

4041
# Verify user data
4142
user_data = response.data["userData"]
42-
assert user_data["userId"] == str(self.user.id)
43+
assert user_data["userId"] == intercom_user_id
4344
assert user_data["email"] == self.user.email
4445
assert user_data["organizationId"] == str(self.organization.id)
4546
assert user_data["organizationName"] == self.organization.name
@@ -49,7 +50,7 @@ def test_get_jwt_success(self) -> None:
4950
token = response.data["jwt"]
5051
decoded = jwt.decode(token, test_secret, algorithms=["HS256"], audience=False)
5152

52-
assert decoded["user_id"] == str(self.user.id)
53+
assert decoded["user_id"] == intercom_user_id
5354
assert decoded["email"] == self.user.email
5455
assert "iat" in decoded
5556
assert "exp" in decoded

0 commit comments

Comments
 (0)