From 7aeefd12a2d698fb7e523373be42dc63732b7f7b Mon Sep 17 00:00:00 2001 From: etaylormcgregor-stytch Date: Mon, 29 Jul 2024 14:27:03 -0400 Subject: [PATCH] [AUTH-3740] Sessions migrate endpoint (#212) * Retired Emails Changes * Minor version bump. * Remove OAuth tenant code. * Include docs fix * sessions migrate * redo gen all --------- Co-authored-by: Jack Cook Co-authored-by: Evelyn Taylor-McGregor --- stytch/consumer/api/sessions.py | 39 ++++++++++++++++++++++++++++++ stytch/consumer/models/sessions.py | 8 ++++++ 2 files changed, 47 insertions(+) diff --git a/stytch/consumer/api/sessions.py b/stytch/consumer/api/sessions.py index e59980e..c652b44 100644 --- a/stytch/consumer/api/sessions.py +++ b/stytch/consumer/api/sessions.py @@ -15,6 +15,7 @@ AuthenticateResponse, GetJWKSResponse, GetResponse, + MigrateResponse, RevokeResponse, Session, ) @@ -194,6 +195,44 @@ async def revoke_async( res = await self.async_client.post(url, data, headers) return RevokeResponse.from_json(res.response.status, res.json) + def migrate( + self, + session_token: str, + session_duration_minutes: Optional[int] = None, + session_custom_claims: Optional[Dict[str, Any]] = None, + ) -> MigrateResponse: + headers: Dict[str, str] = {} + data: Dict[str, Any] = { + "session_token": session_token, + } + if session_duration_minutes is not None: + data["session_duration_minutes"] = session_duration_minutes + if session_custom_claims is not None: + data["session_custom_claims"] = session_custom_claims + + url = self.api_base.url_for("/v1/sessions/migrate", data) + res = self.sync_client.post(url, data, headers) + return MigrateResponse.from_json(res.response.status_code, res.json) + + async def migrate_async( + self, + session_token: str, + session_duration_minutes: Optional[int] = None, + session_custom_claims: Optional[Dict[str, Any]] = None, + ) -> MigrateResponse: + headers: Dict[str, str] = {} + data: Dict[str, Any] = { + "session_token": session_token, + } + if session_duration_minutes is not None: + data["session_duration_minutes"] = session_duration_minutes + if session_custom_claims is not None: + data["session_custom_claims"] = session_custom_claims + + url = self.api_base.url_for("/v1/sessions/migrate", data) + res = await self.async_client.post(url, data, headers) + return MigrateResponse.from_json(res.response.status, res.json) + def get_jwks( self, project_id: str, diff --git a/stytch/consumer/models/sessions.py b/stytch/consumer/models/sessions.py index 7572715..cecd64a 100644 --- a/stytch/consumer/models/sessions.py +++ b/stytch/consumer/models/sessions.py @@ -492,6 +492,14 @@ class GetResponse(ResponseBase): sessions: List[Session] +class MigrateResponse(ResponseBase): + user_id: str + session_token: str + session_jwt: str + user: User + session: Optional[Session] = None + + class RevokeResponse(ResponseBase): """Response type for `Sessions.revoke`. Fields: