// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../../core/resource'; import * as AuthAPI from '../../auth/auth'; import * as WhatsappAPI from '../../auth/whatsapp/whatsapp'; import { APIPromise } from '../../../core/api-promise'; import { buildHeaders } from '../../../internal/headers'; import { RequestOptions } from '../../../internal/request-options'; export class SSO extends APIResource { /** * Consume one-time token and create authenticated session. */ authenticate(params: SSOAuthenticateParams, options?: RequestOptions): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat, ...body } = params; return this._client.post('/api/v1/sso/authenticate', { body, ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * Send email OTP when linking an additional SSO provider (after resolve-account * pending verification). */ requestLinkEmailVerification( params: SSORequestLinkEmailVerificationParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat } = params ?? {}; return this._client.post('/api/v1/sso/request-link-email-verification', { ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * After authenticate, confirm IdP link to the current user or create a new tenant * user (deferred link only). */ resolveAccount( params: SSOResolveAccountParams, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat, ...body } = params; return this._client.post('/api/v1/sso/resolve-account', { body, ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * Validate partner signature and issue one-time SSO token. */ token(params: SSOTokenParams, options?: RequestOptions): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat, ...body } = params; return this._client.post('/api/v1/sso/token', { body, ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } } /** * Sanitized IdP context for the completed SSO token exchange (optional for older * clients). */ export interface SSOAuthContext { /** * How the backend resolved the StackAuth / tenant user for this exchange. */ auth_resolution: 'provision' | 'link_existing' | 'known_identity'; external_subject: string; identity_linked: boolean; /** * Partner-friendly next step; complements internal :class:`SsoAuthResolution` * (path name, not product copy). * * For `link_existing` with partner email: `account_decision` first * (`resolve-account`), then `verify_email` after `confirm_link` if the tenant user * is still not in-app verified. */ idp_onboarding: 'complete' | 'verify_email' | 'account_decision'; is_verified: boolean; provider_code: string; provider_type: string; /** * StackAuth sign-in snapshot for linking UX (existing tenant user / known identity * rows). */ account_sign_in?: SSOAuthContext.AccountSignIn | null; is_first_login_with_identity?: boolean; partner_name?: string | null; verification_id?: string | null; verified_at?: string | null; } export namespace SSOAuthContext { /** * StackAuth sign-in snapshot for linking UX (existing tenant user / known identity * rows). */ export interface AccountSignIn { /** * User has an email+password credential in StackAuth. */ has_password?: boolean; /** * Distinct StackAuth OAuth provider type ids (e.g. google), sorted. */ oauth_provider_types?: Array; } } /** * Response model for authenticate endpoint. */ export interface SSOAuthenticateResponse { access_token: string; /** * Sanitized IdP context for the completed SSO token exchange (optional for older * clients). */ auth_context: SSOAuthContext; refresh_token: string; /** * Current authenticated user model. * * Attributes: post_login_routing (PostLoginRouting | None): Where a root-login * sign-in should land. Populated only by the post-login endpoint, and only when * the request carried no X-Tenant-ID -- at an organization login the destination * is already known and selected_tenant says which. Every other producer of * CurrentUser leaves it None. */ user: AuthAPI.CurrentUserOutput; token_type?: string; } /** * Result of POST /sso/resolve-account. */ export interface SSOResolveAccountResponse { outcome: 'identity_linked' | 'new_account_provisioned' | 'confirm_link_pending_verification'; access_token?: string | null; /** * Sanitized IdP context for the completed SSO token exchange (optional for older * clients). */ auth_context?: SSOAuthContext | null; detail?: string | null; refresh_token?: string | null; token_type?: string; /** * Current authenticated user model. * * Attributes: post_login_routing (PostLoginRouting | None): Where a root-login * sign-in should land. Populated only by the post-login endpoint, and only when * the request carried no X-Tenant-ID -- at an organization login the destination * is already known and selected_tenant says which. Every other producer of * CurrentUser leaves it None. */ user?: AuthAPI.CurrentUserOutput | null; } /** * Response model for token issuance endpoint. */ export interface SSOTokenResponse { token: string; expires_in: number; } export interface SSOAuthenticateParams { /** * Body param */ token: string; /** * Header param */ 'Accept-Language'?: string; /** * Header param: Set to `structured` to receive errors in the structured envelope. * Omit it to keep the legacy error body. */ 'X-Error-Format'?: string; } export interface SSORequestLinkEmailVerificationParams { 'Accept-Language'?: string; /** * Set to `structured` to receive errors in the structured envelope. Omit it to * keep the legacy error body. */ 'X-Error-Format'?: string; } export interface SSOResolveAccountParams { /** * Body param */ action: 'confirm_link' | 'create_new'; /** * Body param */ external_subject: string; /** * Body param */ provider_code: string; /** * Header param */ 'Accept-Language'?: string; /** * Header param: Set to `structured` to receive errors in the structured envelope. * Omit it to keep the legacy error body. */ 'X-Error-Format'?: string; } export interface SSOTokenParams { /** * Body param */ consumer_key: string; /** * Body param: JSON string containing partner user payload */ payload: string; /** * Body param */ signature: string; /** * Body param: ISO-8601 timestamp from partner */ timestamp: string; /** * Header param */ 'Accept-Language'?: string; /** * Header param: Set to `structured` to receive errors in the structured envelope. * Omit it to keep the legacy error body. */ 'X-Error-Format'?: string; } export declare namespace SSO { export { type SSOAuthContext as SSOAuthContext, type SSOAuthenticateResponse as SSOAuthenticateResponse, type SSOResolveAccountResponse as SSOResolveAccountResponse, type SSOTokenResponse as SSOTokenResponse, type SSOAuthenticateParams as SSOAuthenticateParams, type SSORequestLinkEmailVerificationParams as SSORequestLinkEmailVerificationParams, type SSOResolveAccountParams as SSOResolveAccountParams, type SSOTokenParams as SSOTokenParams, }; }