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

[AUTH-3740] Sessions migrate endpoint #329

Merged
merged 8 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions dist/b2c/m2m.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions dist/b2c/sessions.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions lib/b2c/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ export type {
SessionsGetJWKSResponse,
SessionsGetRequest,
SessionsGetResponse,
SessionsMigrateRequest,
SessionsMigrateResponse,
SessionsRevokeRequest,
SessionsRevokeResponse,
} from "./sessions";
Expand Down
26 changes: 13 additions & 13 deletions lib/b2c/m2m.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,19 +241,19 @@ export class M2M {
// ADDIMPORT: import { performAuthorizationCheck, ScopeAuthorizationFunc } from "./m2m_local";
// ADDIMPORT: import { ClientError } from "../shared/errors";
/**
* Authenticate an access token issued by Stytch from the Token endpoint.
* M2M access tokens are JWTs signed with the project's JWKs, and can be validated locally using any Stytch client library.
* You may pass in an optional set of scopes that the JWT must contain in order to enforce permissions.
* You may also override the default scope authorization function to implement custom authorization logic.
*
* @param data {@link AuthenticateTokenRequest}
* @param scopeAuthorizationFunc {@link ScopeAuthorizationFunc} - A function that checks if the token has the required scopes.
The default function assumes scopes are either direct string matches or written in the form "action:resource". See the
documentation for {@link performAuthorizationCheck} for more information.
* @async
* @returns {@link AuthenticateTokenResponse}
* @throws {ClientError} when token can not be authenticated
*/
* Authenticate an access token issued by Stytch from the Token endpoint.
* M2M access tokens are JWTs signed with the project's JWKs, and can be validated locally using any Stytch client library.
* You may pass in an optional set of scopes that the JWT must contain in order to enforce permissions.
* You may also override the default scope authorization function to implement custom authorization logic.
*
* @param data {@link AuthenticateTokenRequest}
* @param scopeAuthorizationFunc {@link ScopeAuthorizationFunc} - A function that checks if the token has the required scopes.
The default function assumes scopes are either direct string matches or written in the form "action:resource". See the
documentation for {@link performAuthorizationCheck} for more information.
* @async
* @returns {@link AuthenticateTokenResponse}
* @throws {ClientError} when token can not be authenticated
*/
async authenticateToken(
data: AuthenticateTokenRequest,
scopeAuthorizationFunc: ScopeAuthorizationFunc = performAuthorizationCheck
Expand Down
33 changes: 33 additions & 0 deletions lib/b2c/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,22 @@ export interface SessionsGetResponse {
status_code: number;
}

export interface SessionsMigrateRequest {
session_token: string;
session_duration_minutes?: number;
session_custom_claims?: Record<string, any>; // eslint-disable-line @typescript-eslint/no-explicit-any
}

export interface SessionsMigrateResponse {
request_id: string;
user_id: string;
session_token: string;
session_jwt: string;
user: User;
status_code: number;
session?: Session;
}

// Request type for `sessions.revoke`.
export interface SessionsRevokeRequest {
// The `session_id` to revoke.
Expand Down Expand Up @@ -661,6 +677,23 @@ export class Sessions {
});
}

/**
* @param data {@link SessionsMigrateRequest}
* @returns {@link SessionsMigrateResponse}
* @async
* @throws A {@link StytchError} on a non-2xx response from the Stytch API
* @throws A {@link RequestError} when the Stytch API cannot be reached
*/
migrate(data: SessionsMigrateRequest): Promise<SessionsMigrateResponse> {
const headers: Record<string, string> = {};
return request<SessionsMigrateResponse>(this.fetchConfig, {
method: "POST",
url: `/v1/sessions/migrate`,
headers,
data,
});
}

/**
* Get the JSON Web Key Set (JWKS) for a project.
*
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion types/lib/b2c/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions types/lib/b2c/m2m.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions types/lib/b2c/sessions.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading