Skip to content

Commit

Permalink
[AUTH-3740] Sessions migrate endpoint (#212)
Browse files Browse the repository at this point in the history
* Retired Emails Changes

* Minor version bump.

* Remove OAuth tenant code.

* Include docs fix

* sessions migrate

* redo gen all

---------

Co-authored-by: Jack Cook <[email protected]>
Co-authored-by: Evelyn Taylor-McGregor <[email protected]>
  • Loading branch information
3 people authored Jul 29, 2024
1 parent e8b5ae9 commit 7aeefd1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
39 changes: 39 additions & 0 deletions stytch/consumer/api/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
AuthenticateResponse,
GetJWKSResponse,
GetResponse,
MigrateResponse,
RevokeResponse,
Session,
)
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions stytch/consumer/models/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7aeefd1

Please sign in to comment.