Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(vercel): import the linked resource into the marketplace installation (#123240)

posthog[bot]0cc4fe6eac9e
diff --git a/docs/published/handbook/engineering/vercel-integration.md b/docs/published/handbook/engineering/vercel-integration.md
index c8a75c501fe6..8a82cf02b284 100644
--- a/docs/published/handbook/engineering/vercel-integration.md
+++ b/docs/published/handbook/engineering/vercel-integration.md
@@ -105,13 +105,14 @@ sequenceDiagram
participant PH as PostHog
User->>VM: Click "Link Existing Account"
- VM->>PH: GET /connect/vercel/callback (OAuth code, no state)
+ VM->>PH: GET /connect/vercel/callback (Marketplace OAuth code, no state)
+ PH->>PH: Exchange Marketplace code, keep the grant for the state (10 min TTL)
PH-->>User: Redirect to Vercel's install page with a state, set a state cookie
User->>VM: Continue on the install page
- VM->>PH: GET /connect/vercel/callback (OAuth code + same state)
+ VM->>PH: GET /connect/vercel/callback (install OAuth code + same state)
PH->>PH: Reject unless the state matches this browser's cookie
- PH->>PH: Exchange code for access token
- PH->>PH: Store session in cache (10 min TTL)
+ PH->>PH: Exchange install code, reject unless its Vercel user matches the Marketplace grant
+ PH->>PH: Sign a link session with the Marketplace grant (10 min TTL)
PH-->>User: Show org selection page
User->>PH: Select org, POST /api/vercel/connect/complete
diff --git a/ee/api/vercel/README.md b/ee/api/vercel/README.md
index 3a732bc754a9..424aeb1e84c5 100644
--- a/ee/api/vercel/README.md
+++ b/ee/api/vercel/README.md
@@ -101,9 +101,9 @@ Vercel marketplace integrations have two separate flows:
When a user clicks "Link Existing Account" in the Vercel Marketplace:
1. Vercel opens a popup to our **Redirect URL** (`/connect/vercel/callback`) with an OAuth code
-2. The Marketplace request has no `state`, so PostHog sends the popup to Vercel's external install page (`https://vercel.com/integrations/{VERCEL_INTEGRATION_SLUG}/new`) with a random `state`, and stores the same value in a host-only `__Host-` cookie. PostHog keeps the Marketplace's `next` link for the return, and a browser holds at most a few pending `state` cookies
-3. Vercel returns to the Redirect URL with `source=external`, a new code, and the same `state`. PostHog rejects the request when the browser has no matching cookie, or when the request has no `state`
-4. PostHog exchanges the code for an access token via `POST /v2/oauth/access_token`
+2. The Marketplace request has no `state`. PostHog exchanges the Marketplace code for an access token via `POST /v2/oauth/access_token` and keeps that grant, encrypted, in the cache for 10 minutes. The resource import must use this grant, because Vercel waits for the import on the Marketplace installation
+3. PostHog sends the popup to Vercel's external install page (`https://vercel.com/integrations/{VERCEL_INTEGRATION_SLUG}/new`) with a random `state`, and stores the same value in a host-only `__Host-` cookie. PostHog keeps the Marketplace's `next` link for the return, and a browser holds at most a few pending `state` cookies
+4. Vercel returns to the Redirect URL with `source=external`, a new code, and the same `state`. PostHog rejects the request when the browser has no matching cookie, or when the request has no `state`. PostHog exchanges the new code only to confirm that it belongs to the same Vercel user as the Marketplace code, and the link session carries the Marketplace grant
5. If the user isn't logged in, they're redirected to `/login` first
6. The user selects which PostHog organization to link
7. An `OrganizationIntegration` record is created with `type=connectable`
diff --git a/ee/api/vercel/crypto.py b/ee/api/vercel/crypto.py
index f9555c301c75..9baedc01dc7d 100644
--- a/ee/api/vercel/crypto.py
+++ b/ee/api/vercel/crypto.py
@@ -36,3 +36,7 @@ def mark_token_used(jti: str, ttl: int) -> bool:
return False
cache.set(cache_key, True, timeout=ttl)
return True
+
+
+def release_used_token(jti: str) -> None:
+ cache.delete(f"{USED_TOKEN_CACHE_PREFIX}{jti}")
diff --git a/ee/api/vercel/test/test_vercel_connect.py b/ee/api/vercel/test/test_vercel_connect.py
index afceac51e5c9..31939472f280 100644
--- a/ee/api/vercel/test/test_vercel_connect.py
+++ b/ee/api/vercel/test/test_vercel_connect.py
@@ -1,3 +1,5 @@
+import re
+import json
from http.cookies import Morsel
from urllib.parse import parse_qs, urlparse
@@ -7,7 +9,9 @@ from unittest.mock import MagicMock, patch
from django.http.response import HttpResponseBase
from django.test import Client, SimpleTestCase, override_settings
+import responses
from parameterized import parameterized
+from requests import PreparedRequest
from rest_framework import status
from posthog.integrations import IntegrationManager
@@ -82,6 +86,59 @@ def _mock_vercel_client(mock_client_class: MagicMock) -> MagicMock:
return mock_client
+def _grant_for_code(code: str, user_id: str = "usr_1") -> OAuthTokenResponse:
+ return OAuthTokenResponse(
+ access_token=f"tok_{code}",
+ token_type="Bearer",
+ installation_id=f"icfg_{code}",
+ user_id=user_id,
+ team_id="team_1",
+ )
+
+
+def _exchanged_codes(mock_client: MagicMock) -> list[str]:
+ return [call.kwargs["code"] for call in mock_client.oauth_token_exchange.call_args_list]
+
+
+MARKETPLACE_INSTALLATION = "icfg_marketplace"
+INSTALL_PAGE_INSTALLATION = "icfg_install_page"
+
+
+def _fake_vercel(vercel: responses.RequestsMock) -> list[str]:
+ # Each OAuth code belongs to the installation of the flow that issued it. Vercel accepts the import only into
+ # the Marketplace installation that opened the link popup, and answers 404 for any other installation.
+ grants = {
+ "code_from_marketplace": (MARKETPLACE_INSTALLATION, "tok_marketplace"),
+ "code_from_install": (INSTALL_PAGE_INSTALLATION, "tok_install_page"),
+ }
+ imported_into: list[str] = []
+
+ def exchange_code(request: PreparedRequest) -> tuple[int, dict[str, str], str]:
+ [code] = parse_qs(str(request.body))["code"]
+ if code not in grants:
+ return 400, {}, json.dumps({"error": "invalid_grant"})
+ installation_id, access_token = grants.pop(code)
+ grant = {"access_token": access_token, "installation_id": installation_id, "user_id": "usr_e2e"}
+ return 200, {}, json.dumps({**grant, "token_type": "Bearer", "team_id": "team_e2e"})
+
+ def import_resource(request: PreparedRequest) -> tuple[int, dict[str, str], str]:
+ match = re.search(r"/installations/([^/]+)/", str(request.url))
+ installation_id = match.group(1) if match else ""
+ if (installation_id, request.headers.get("Authorization")) != (
+ MARKETPLACE_INSTALLATION,
+ "Bearer tok_marketplace",
+ ):
+ return 404, {}, json.dumps({"error": {"code": "not_found", "message": "Integration Resource not found"}})
+ imported_into.append(installation_id)
+ return 200, {}, "{}"
+
+ vercel.add_callback(responses.POST, "https://api.vercel.com/v2/oauth/access_token", callback=exchange_code)
+ vercel.add_callback(
+ responses.PUT, re.compile(r"https://api\.vercel\.com/v1/installations/[^/]+/resources/[^/]+"), import_resource
+ )
+ return imported_into
+
+
def _flow_cookie(response: HttpResponseBase) -> Morsel:
[cookie] = [cookie for name, cookie in response.cookies.items() if name.startswith(CONNECT_NONCE_COOKIE_PREFIX)]
return cookie
@@ -149,7 +206,7 @@ class TestVercelConnectCallback(VercelConnectTestBase):
error_description="Code expired",
)
- response = self._callback_through_vercel_install({"code": "bad_code"})
+ response = self.client.get(self.url, {"code": "bad_code"})
assert response.status_code == status.HTTP_401_UNAUTHORIZED
@@ -182,16 +239,11 @@ class TestVercelConnectCallback(VercelConnectTestBase):
) -> None:
mock_client = MagicMock()
mock_client_class.return_value = mock_client
- mock_client.oauth_token_exchange.return_value = OAuthTokenResponse(
- access_token="tok_123",
- token_type="Bearer",
- installation_id="icfg_new",
- user_id="usr_1",
- team_id="team_1",
- )
+ mock_client.oauth_token_exchange.side_effect = lambda **kwargs: _grant_for_code(kwargs["code"])
response = self._callback_through_vercel_install(
- {"code": "good_code", **return_params}, marketplace_params=marketplace_params
+ {"code": "code_from_install", "configurationId": "icfg_code_from_install", **return_params},
+ marketplace_params={"configurationId": "icfg_code_from_marketplace", **marketplace_params},
)
assert response.status_code == 302
@@ -202,6 +254,11 @@ class TestVercelConnectCallback(VercelConnectTestBase):
assert "next" not in parsed
session_data = _load_connect_session(parsed["session"][0])
assert session_data["next_url"] == expected_next_url
+ assert [session_data["access_token"], session_data["installation_id"], session_data["configuration_id"]] == [
+ "tok_code_from_marketplace",
+ "icfg_code_from_marketplace",
+ "icfg_code_from_marketplace",
+ ]
@parameterized.expand(
[
@@ -311,7 +368,7 @@ class TestVercelConnectCallback(VercelConnectTestBase):
assert cookie["domain"] == ""
assert cookie["httponly"] is True
assert cookie["samesite"] == "Lax"
- mock_client.oauth_token_exchange.assert_not_called()
+ assert _exchanged_codes(mock_client) == ["code_from_marketplace"]
@override_settings(VERCEL_CLIENT_INTEGRATION_ID="client_id", VERCEL_CLIENT_INTEGRATION_SECRET="secret")
@patch("ee.api.vercel.vercel_connect.VercelAPIClient")
@@ -331,12 +388,13 @@ class TestVercelConnectCallback(VercelConnectTestBase):
@parameterized.expand(
[
- ("marketplace", {"source": "marketplace"}, status.HTTP_302_FOUND, []),
- ("source_absent", {}, status.HTTP_302_FOUND, []),
+ ("marketplace", {"source": "marketplace"}, status.HTTP_302_FOUND, ["code_without_state"], []),
+ ("source_absent", {}, status.HTTP_302_FOUND, ["code_without_state"], []),
(
"returned_from_install",
{"source": "external"},
status.HTTP_400_BAD_REQUEST,
+ [],
["missing_state_after_install_redirect"],
),
]
@@ -349,6 +407,7 @@ class TestVercelConnectCallback(VercelConnectTestBase):
_name: str,
params: dict[str, str],
expected_status: int,
+ expected_stateless_exchanges: list[str],
expected_reasons: list[str],
mock_client_class: MagicMock,
mock_capture_exception: MagicMock,
@@ -364,8 +423,10 @@ class TestVercelConnectCallback(VercelConnectTestBase):
)
assert [response.status_code, pending_install.status_code] == [expected_status, status.HTTP_302_FOUND]
- assert [call.kwargs["code"] for call in mock_client.oauth_token_exchange.call_args_list] == [
- "code_from_install"
+ assert _exchanged_codes(mock_client) == [
+ "code_from_marketplace",
+ *expected_stateless_exchanges,
+ "code_from_install",
]
assert [call.args[1]["reason"] for call in mock_capture_exception.call_args_list] == expected_reasons
@@ -395,9 +456,27 @@ class TestVercelConnectCallback(VercelConnectTestBase):
response = self.client.get(self.url, {"code": "code_for_other_installation", "state": state})
assert response.status_code == status.HTTP_400_BAD_REQUEST
- mock_client.oauth_token_exchange.assert_not_called()
+ assert _exchanged_codes(mock_client) == ["code_from_marketplace"]
assert mock_capture_exception.call_args.args[1]["reason"] == expected_reason
+ @override_settings(VERCEL_CLIENT_INTEGRATION_ID="client_id", VERCEL_CLIENT_INTEGRATION_SECRET="secret")
+ @patch("ee.api.vercel.vercel_connect.capture_exception")
+ @patch("ee.api.vercel.vercel_connect.VercelAPIClient")
+ def test_rejects_install_page_signed_in_as_another_vercel_user(
+ self, mock_client_class: MagicMock, mock_capture_exception: MagicMock
+ ) -> None:
+ mock_client = MagicMock()
+ mock_client_class.return_value = mock_client
+ mock_client.oauth_token_exchange.side_effect = [
+ _grant_for_code("attacker_marketplace_code", user_id="usr_attacker"),
+ _grant_for_code("victim_install_code", user_id="usr_victim"),
+ ]
+
+ response = self._callback_through_vercel_install({"code": "victim_install_code", "source": "external"})
+
+ assert response.status_code == status.HTTP_400_BAD_REQUEST
+ assert mock_capture_exception.call_args.args[1]["reason"] == "install_user_mismatch"
+
@override_settings(VERCEL_CLIENT_INTEGRATION_ID="client_id", VERCEL_CLIENT_INTEGRATION_SECRET="secret")
@patch("ee.api.vercel.vercel_connect.VercelAPIClient")
def test_install_state_works_once(self, mock_client_class: MagicMock) -> None:
@@ -408,13 +487,14 @@ class TestVercelConnectCallback(VercelConnectTestBase):
replay = self.client.get(self.url, {"code": "second_code", "state": state})
assert [first.status_code, replay.status_code] == [302, status.HTTP_400_BAD_REQUEST]
- assert mock_client.oauth_token_exchange.call_count == 1
+ assert _exchanged_codes(mock_client) == ["code_from_marketplace", "first_code"]
@override_settings(VERCEL_CLIENT_INTEGRATION_ID="client_id", VERCEL_CLIENT_INTEGRATION_SECRET="secret")
@patch("ee.api.vercel.vercel_connect.VercelAPIClient")
def test_retry_after_failed_exchange_keeps_marketplace_next(self, mock_client_class: MagicMock) -> None:
mock_client = _mock_vercel_client(mock_client_class)
mock_client.oauth_token_exchange.side_effect = [
+ mock_client.oauth_token_exchange.return_value,
OAuthTokenResponse(access_token="", token_type="", installation_id="", user_id="", error="server_error"),
mock_client.oauth_token_exchange.return_value,
]
@@ -1009,6 +1089,18 @@ class TestVercelConnectComplete(VercelConnectTestBase):
assert properties["installation_id"] == CACHED_SESSION_DATA["installation_id"]
assert properties["resource_id"] == mock_client.import_resource.call_args.kwargs["resource_id"]
+ mock_client.import_resource.return_value = OperationResult(success=True)
+ retry = self.client.post(
+ self.url,
+ {
+ "session": session_token,
+ "organization_id": str(self.organization.id),
+ "environment_mapping": {"production": self.team.pk},
+ },
+ content_type="application/json",
+ )
+ assert retry.status_code == status.HTTP_201_CREATED
+
@override_settings(VERCEL_CLIENT_INTEGRATION_ID="client_id", VERCEL_CLIENT_INTEGRATION_SECRET="secret")
class TestVercelConnectEndToEnd(VercelConnectTestBase):
@@ -1019,7 +1111,6 @@ class TestVercelConnectEndToEnd(VercelConnectTestBase):
]
)
@patch("ee.vercel.integration.VercelIntegration")
- @patch("ee.api.vercel.vercel_connect.VercelAPIClient")
def test_end_to_end_callback_to_complete(
self,
_name: str,
@@ -1027,35 +1118,42 @@ class TestVercelConnectEndToEnd(VercelConnectTestBase):
link_host: str,
signed_in_at_callback: bool,
expected_cookie_domain: str,
- mock_client_class: MagicMock,
_mock_vercel_integration: MagicMock,
) -> None:
- _mock_vercel_client(mock_client_class)
if not signed_in_at_callback:
self.client.logout()
- callback_response = self._callback_through_vercel_install({"code": "good_code"}, host=callback_host)
- session_token = _session_token_from_redirect(callback_response["Location"])
+ with responses.RequestsMock() as vercel:
+ imported_into = _fake_vercel(vercel)
+ callback_response = self._callback_through_vercel_install(
+ {"code": "code_from_install", "configurationId": INSTALL_PAGE_INSTALLATION, "source": "external"},
+ host=callback_host,
+ marketplace_params={"configurationId": MARKETPLACE_INSTALLATION, "source": "marketplace"},
+ )
+ session_token = _session_token_from_redirect(callback_response["Location"])
- self.client.force_login(self.user)
- session_response = self.client.get(
- "/api/vercel/connect/session", {"session": session_token}, HTTP_HOST=link_host
- )
- complete_response = self.client.post(
- "/api/vercel/connect/complete",
- {
- "session": session_token,
- "organization_id": str(self.organization.id),
- "environment_mapping": {"production": self.team.pk},
- },
- content_type="application/json",
- HTTP_HOST=link_host,
- )
+ self.client.force_login(self.user)
+ session_response = self.client.get(
+ "/api/vercel/connect/session", {"session": session_token}, HTTP_HOST=link_host
+ )
+ complete_response = self.client.post(
+ "/api/vercel/connect/complete",
+ {
+ "session": session_token,
+ "organization_id": str(self.organization.id),
+ "environment_mapping": {"production": self.team.pk},
+ },
+ content_type="application/json",
+ HTTP_HOST=link_host,
+ )
assert callback_response.status_code == 302
assert session_response.status_code == status.HTTP_200_OK
- assert complete_response.status_code == status.HTTP_201_CREATED
+ assert complete_response.status_code == status.HTTP_201_CREATED, complete_response.json()
assert complete_response.json()["status"] == "linked"
+ assert imported_into == [MARKETPLACE_INSTALLATION]
+ link = OrganizationIntegration.objects.get(organization=self.organization)
+ assert [link.integration_id, link.config["configuration_id"]] == [MARKETPLACE_INSTALLATION] * 2
cleared_cookie = _flow_cookie(complete_response)
assert cleared_cookie["max-age"] == 0
assert cleared_cookie["domain"] == expected_cookie_domain
diff --git a/ee/api/vercel/vercel_connect.py b/ee/api/vercel/vercel_connect.py
index fcab5d6f4627..0007239ab5c1 100644
--- a/ee/api/vercel/vercel_connect.py
+++ b/ee/api/vercel/vercel_connect.py
@@ -25,8 +25,8 @@ from posthog.models.organization_integration import OrganizationIntegration
from posthog.models.team import Team
from posthog.models.user import User
-from ee.api.vercel.crypto import decrypt_payload, encrypt_payload, mark_token_used
-from ee.vercel.client import APIError, VercelAPIClient
+from ee.api.vercel.crypto import decrypt_payload, encrypt_payload, mark_token_used, release_used_token
+from ee.vercel.client import APIError, OAuthTokenResponse, VercelAPIClient
logger = structlog.get_logger(__name__)
@@ -47,6 +47,7 @@ CONNECT_NONCE_COOKIE_PATH = "/api/vercel/connect"
INSTALL_STATE_COOKIE_PREFIX = "__Host-ph_vercel_install_state_"
MAX_PENDING_INSTALL_STATES = 5
INSTALL_CONTINUATION_CACHE_PREFIX = "vercel_connect_install_next:"
+INSTALL_CONTINUATION_SALT = "vercel_connect_install"
SESSION_INVALID_MESSAGE = "Session expired or invalid. Please try linking again from Vercel."
_BROWSER_NONCE_KEY = "browser_nonce"
@@ -127,8 +128,22 @@ def _install_continuation_cache_key(state: str) -> str:
return INSTALL_CONTINUATION_CACHE_PREFIX + hashlib.sha256(state.encode()).hexdigest()
-def _install_continuation(state: str) -> str:
- return cache.get(_install_continuation_cache_key(state), "")
+def _save_install_continuation(state: str, continuation: dict) -> None:
+ cache.set(
+ _install_continuation_cache_key(state),
+ encrypt_payload(continuation, salt=INSTALL_CONTINUATION_SALT, jti=False),
+ timeout=CONNECT_SESSION_TIMEOUT,
+ )
+
+
+def _install_continuation(state: str) -> dict | None:
+ token = cache.get(_install_continuation_cache_key(state))
+ if not token:
+ return None
+ try:
+ return decrypt_payload(token, salt=INSTALL_CONTINUATION_SALT, ttl=CONNECT_SESSION_TIMEOUT)
+ except InvalidToken:
+ return None
def _forget_install_continuation(state: str) -> None:
@@ -146,14 +161,13 @@ def _drop_excess_install_state_cookies(request: Request, response: HttpResponse)
response.delete_cookie(name, path="/", samesite="Lax")
-def _redirect_through_vercel_install(request: Request, next_url: str) -> HttpResponse:
+def _redirect_through_vercel_install(request: Request, continuation: dict) -> HttpResponse:
# A Marketplace install calls back without a state, so nothing ties its code to this browser. Vercel's
# external install flow returns the state we send, and the state cookie ties that state to this browser.
state = secrets.token_urlsafe(32)
slug = quote(settings.VERCEL_INTEGRATION_SLUG, safe="")
response = HttpResponseRedirect(f"https://vercel.com/integrations/{slug}/new?{urlencode({'state': state})}")
- if next_url:
- cache.set(_install_continuation_cache_key(state), next_url, timeout=CONNECT_SESSION_TIMEOUT)
+ _save_install_continuation(state, continuation)
_drop_excess_install_state_cookies(request, response)
response.set_cookie(
_install_state_cookie_name(state),
@@ -201,6 +215,35 @@ def _require_install_state_from_this_browser(request: Request, state: str) -> No
raise exceptions.ValidationError(SESSION_INVALID_MESSAGE)
+def _require_same_vercel_user(continuation: dict, install_grant: OAuthTokenResponse) -> None:
+ if secrets.compare_digest(continuation["user_id"].encode(), install_grant.user_id.encode()):
+ return
+
+ capture_exception(
+ Exception("Vercel connect: install page returned a different Vercel user"),
+ {"reason": "install_user_mismatch", "integration": "vercel"},
+ )
+ raise exceptions.ValidationError(SESSION_INVALID_MESSAGE)
+
+
+def _exchange_code(code: str, client_id: str, client_secret: str, redirect_uri: str) -> OAuthTokenResponse:
+ token_response = VercelAPIClient(bearer_token=None).oauth_token_exchange(
+ code=code,
+ client_id=client_id,
+ client_secret=client_secret,
+ redirect_uri=redirect_uri,
+ )
+ if token_response.error:
+ logger.error(
+ "vercel_connect_token_exchange_failed",
+ error=token_response.error,
+ error_description=token_response.error_description,
+ integration="vercel",
+ )
+ raise exceptions.AuthenticationFailed("Vercel authentication failed")
+ return token_response
+
+
def _mark_token_used(jti: str) -> bool:
return mark_token_used(jti, ttl=CONNECT_SESSION_TIMEOUT)
@@ -316,38 +359,35 @@ class VercelConnectCallbackViewSet(viewsets.GenericViewSet):
state = request.query_params.get("state")
if not state:
_reject_install_return_without_state(request)
- return _redirect_through_vercel_install(request, next_url)
+ # Vercel waits for the import on the installation of this Marketplace code, so keep its grant.
+ # The install page code only proves which Vercel user holds this browser.
+ marketplace_grant = _exchange_code(code, client_id, client_secret, redirect_uri)
+ return _redirect_through_vercel_install(
+ request,
+ {
+ "access_token": marketplace_grant.access_token,
+ "token_type": marketplace_grant.token_type,
+ "installation_id": marketplace_grant.installation_id,
+ "user_id": marketplace_grant.user_id,
+ "team_id": marketplace_grant.team_id,
+ "configuration_id": configuration_id,
+ "next_url": next_url,
+ },
+ )
_require_install_state_from_this_browser(request, state)
- next_url = _install_continuation(state) or next_url
-
- client = VercelAPIClient(bearer_token=None)
- token_response = client.oauth_token_exchange(
- code=code,
- client_id=client_id,
- client_secret=client_secret,
- redirect_uri=redirect_uri,
- )
-
- if token_response.error:
- logger.error(
- "vercel_connect_token_exchange_failed",
- error=token_response.error,
- error_description=token_response.error_description,
- integration="vercel",
+ continuation = _install_continuation(state)
+ if continuation is None:
+ capture_exception(
+ Exception("Vercel connect: install state has no Marketplace grant"),
+ {"reason": "missing_marketplace_grant", "integration": "vercel"},
)
- raise exceptions.AuthenticationFailed("Vercel authentication failed")
+ raise exceptions.ValidationError(SESSION_INVALID_MESSAGE)
+
+ _require_same_vercel_user(continuation, _exchange_code(code, client_id, client_secret, redirect_uri))
browser_nonce = secrets.token_urlsafe(32)
session_token = _sign_connect_session(
- {
- "access_token": token_response.access_token,
- "token_type": token_response.token_type,
- "installation_id": token_response.installation_id,
- "user_id": token_response.user_id,
- "team_id": token_response.team_id,
- "configuration_id": configuration_id,
- "next_url": next_url,
- },
+ {**continuation, "next_url": continuation.get("next_url") or next_url},
browser_nonce=browser_nonce,
)
@@ -512,10 +552,15 @@ class VercelConnectLinkViewSet(viewsets.GenericViewSet):
resource_id=resource_id,
integration="vercel",
)
+
with transaction.atomic():
org_integration.delete()
for resource in resources.values():
IntegrationManager.vercel.oauth.delete(resource.team_id, resource.id, ignore_usages=True)
+
+ # The rollback leaves nothing behind, so the same session can try the link again.
+ release_used_token(jti)
+
capture_exception(
VercelImportError("Vercel did not accept the resource import"),
{