Skip to content
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
4 changes: 1 addition & 3 deletions src/client.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ export interface Base44Client {
functions: FunctionsModule;
/** {@link IntegrationsModule | Integrations module} with elevated permissions. */
integrations: IntegrationsModule;
/** {@link SsoModule | SSO module} for generating SSO tokens.
* @internal
*/
/** {@link SsoModule | SSO module} for generating SSO tokens. */
sso: SsoModule;
/** Cleanup function to disconnect WebSocket connections. */
cleanup: () => void;
Expand Down
50 changes: 28 additions & 22 deletions src/modules/sso.types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* Response from SSO access token endpoint.
* @internal
*/
export interface SsoAccessTokenResponse {
access_token: string;
Expand All @@ -14,47 +13,54 @@ export interface SsoAccessTokenResponse {
* services.
*
* This module is only available to use with a client in service role authentication mode, which means it can only be used in backend environments.
*
* @internal
*
* @example
* ```typescript
* // Access SSO module with service role
* const response = await base44.asServiceRole.sso.getAccessToken('user_123');
* console.log(response.data.access_token);
* ```
*/
export interface SsoModule {
/**
* Gets SSO access token for a specific user.
* Gets an SSO access token for the user who made the current request.
*
* Retrieves a Single Sign-On access token that can be used to authenticate
* a user with external services or systems.
* Use this token to authenticate the user with external systems or services.
* This only works for that same user. Create the client with
* {@link createClientFromRequest} so it acts on behalf of the request's user,
* then pass that user's ID as `userid`. If `userid` is any other user, the
* call fails. An expired token is refreshed automatically when a refresh token
* is available.
*
* @param userid - The user ID to get the access token for.
* @param userid - The ID of the user who made the current request, such as the
* `id` returned by {@link AuthModule | base44.auth.me()}.
* @returns Promise resolving to the SSO access token response.
*
* @example
* ```typescript
* // Get SSO access token for a user
* const response = await base44.asServiceRole.sso.getAccessToken('user_123');
* console.log(response.access_token);
* // Get the user's SSO access token to call an external system
* import { createClientFromRequest } from 'npm:@base44/sdk';
*
* Deno.serve(async (req) => {
* const base44 = createClientFromRequest(req);
* const user = await base44.auth.me();
* const { access_token } = await base44.asServiceRole.sso.getAccessToken(user.id);
*
* return Response.json({ access_token });
* });
* ```
*/
getAccessToken(userid: string): Promise<SsoAccessTokenResponse>;

/**
* Gets the stored SSO OIDC ID token for the current app user.
* Gets the stored SSO OIDC ID token for the user who made the current request.
*
* The service-role client must include an on-behalf-of token for the same
* user specified by `userid`. This method returns the stored token as-is and
* does not refresh it.
* This only works for that same user, not for arbitrary users. Create the
* client with {@link createClientFromRequest} so it acts on behalf of the
* request's user, then pass that user's ID as `userid`. If `userid` is any
* other user, the call fails. The stored token is returned as-is and is never
* refreshed, so the call fails if the token has already expired.
*
* @param userid - The current app user's ID.
* @param userid - The ID of the user who made the current request, such as the
* `id` returned by {@link AuthModule | base44.auth.me()}.
* @returns Promise resolving to the raw ID-token string.
*
* @example
* ```typescript
* // Get the user's ID token to read identity claims such as email
* import { createClientFromRequest } from 'npm:@base44/sdk';
*
* Deno.serve(async (req) => {
Expand Down
Loading