// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../core/resource'; import * as AdaptiveStepUpAPI from './adaptive-step-up'; import { AdaptiveStepUp, AdaptiveStepUpResendParams, AdaptiveStepUpVerifyParams, AdaptiveStepUpVerifyResponse, PasswordLoginResponse, } from './adaptive-step-up'; import * as APIKeyAPI from './api-key'; import { APIKey, APIKeyRetrieveAPIKeyParams, APIKeyRotateParams, UserAPIKeyResponse } from './api-key'; import * as MobileAPI from './mobile'; import { Mobile, MobileCallbackParams, MobileCallbackResponse, MobileExchangeParams, MobileExchangeResponse, MobileLoginParams, MobileLoginResponse, } from './mobile'; import * as SessionsAPI from './sessions'; import { RevokeSessionsResponse, SessionDeleteAllParams, SessionDeleteParams, SessionListParams, SessionListResponse, Sessions, } from './sessions'; import * as SlackAPI from './slack'; import { Slack, SlackRegisterParams, SlackRegisterResponse, SlackUnregisterParams } from './slack'; import * as TokenAPI from './token'; import { Token, TokenValidateParams, TokenValidateResponse } from './token'; import * as V2API from './v2'; import { V2, V2RetrieveProvidersParams, V2RetrieveProvidersResponse } from './v2'; import * as WhatsappAPI from './whatsapp/whatsapp'; import { VerificationResponse, Whatsapp, WhatsappRegisterParams } from './whatsapp/whatsapp'; import { APIPromise } from '../../core/api-promise'; import { buildHeaders } from '../../internal/headers'; import { RequestOptions } from '../../internal/request-options'; import { path } from '../../internal/utils/path'; export class Auth extends APIResource { mobile: MobileAPI.Mobile = new MobileAPI.Mobile(this._client); token: TokenAPI.Token = new TokenAPI.Token(this._client); whatsapp: WhatsappAPI.Whatsapp = new WhatsappAPI.Whatsapp(this._client); slack: SlackAPI.Slack = new SlackAPI.Slack(this._client); apiKey: APIKeyAPI.APIKey = new APIKeyAPI.APIKey(this._client); sessions: SessionsAPI.Sessions = new SessionsAPI.Sessions(this._client); adaptiveStepUp: AdaptiveStepUpAPI.AdaptiveStepUp = new AdaptiveStepUpAPI.AdaptiveStepUp(this._client); v2: V2API.V2 = new V2API.V2(this._client); /** * Direct API login with StackAuth and backend post-login. * * This endpoint performs password sign-in against StackAuth, runs the post-login flow * (so the backend user is resolved and permissions/tenants are loaded), applies * account lockout based on failed attempts, and returns CurrentUser plus tokens. */ directAPILogin( params: AuthDirectAPILoginParams, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'User-Agent': userAgent, 'X-Error-Format': xErrorFormat, 'X-Forwarded-For': xForwardedFor, 'X-Real-IP': xRealIP, ...body } = params; return this._client.post('/auth/direct-api-login', { body, ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(userAgent != null ? { 'User-Agent': userAgent } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), ...(xForwardedFor != null ? { 'X-Forwarded-For': xForwardedFor } : undefined), ...(xRealIP != null ? { 'X-Real-IP': xRealIP } : undefined), }, options?.headers, ]), }); } /** * Return the organization the user owning an email address most recently landed * in, for the root login page before sign-in. Answers a cross-organization * question, so no X-Tenant-ID is required and any value sent is ignored. Returns * null when nothing matches. */ lastVisitedOrganization( params: AuthLastVisitedOrganizationParams, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat, ...body } = params; return this._client.post('/auth/last-visited-organization', { body, ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * Logout user */ logout( params: AuthLogoutParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat } = params ?? {}; return this._client.post('/auth/logout', { ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * Revoke all sessions for the current user across all stored accounts */ logoutAll( params: AuthLogoutAllParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat } = params ?? {}; return this._client.post('/auth/logout-all', { ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * Resolve an email to the organizations its owner actively belongs to, for the * root login page. Answers a cross-organization question, so no X-Tenant-ID is * required and any value sent is ignored. Returns an empty list when the address * matches no active membership. */ lookupEmail(params: AuthLookupEmailParams, options?: RequestOptions): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat, ...body } = params; return this._client.post('/auth/lookup-email', { body, ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * Get current authenticated user */ me(params: AuthMeParams | null | undefined = {}, options?: RequestOptions): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat } = params ?? {}; return this._client.get('/auth/me', { ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * Mandatory post-auth login endpoint to complete user registration in backend * database. * * This endpoint MUST be called after completing the OAuth/credential login flow with StackAuth to properly * store basic user data in the backend database and establish the link between StackAuth and * the backend user systems. This creates the necessary mapping for the application to function. * * OAuth Flow Sequence: * 1. Frontend initiates OAuth flow: {stackauth_url}/api/v1/auth/oauth/authorize/{provider} * 2. User completes OAuth authentication with the provider (Google, GitHub, etc.) * 3. StackAuth processes the OAuth callback and creates/updates user in StackAuth DB * 4. **THIS ENDPOINT** must be called to: * - Store basic user data in the backend database * - Create the mapping between StackAuth user ID and backend user ID * - Return the user profile for the frontend session * * Credential Flow Sequence: * 1. Frontend initiates credential login flow: {stackauth_url}/api/v1/auth/password/sign-in * 2. StackAuth processes the credential login * 3. **THIS ENDPOINT** must be called to: * - Fetch the user data from database based on the StackAuth user ID * - Return the user profile for the frontend session * * Why This Is Mandatory: * - StackAuth DB and Backend DB are separate systems * - Backend needs to store the StackAuth ID link for user identification * - RBAC (roles/permissions) remain in StackAuth and are checked there * - Required for proper user session management in the application */ postLogin( type: 'oauth' | 'credential', params: AuthPostLoginParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'User-Agent': userAgent, 'X-Error-Format': xErrorFormat, 'X-Forwarded-For': xForwardedFor, 'X-Real-IP': xRealIP, } = params ?? {}; return this._client.post(path`/auth/${type}/post-login`, { ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(userAgent != null ? { 'User-Agent': userAgent } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), ...(xForwardedFor != null ? { 'X-Forwarded-For': xForwardedFor } : undefined), ...(xRealIP != null ? { 'X-Real-IP': xRealIP } : undefined), }, options?.headers, ]), }); } /** * Resolve username */ resolveUsername( params: AuthResolveUsernameParams, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat, ...body } = params; return this._client.post('/auth/resolve-username', { body, ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * List OAuth provider IDs using the legacy response contract. * * Args: request (Request): The request object. service * (AdminHostLoginProviderService): The admin host login provider service. user * (CurrentUser): The authenticated user. env_service (AdminEnvService): The admin * environment variables service. * * Returns: list[str]: OAuth provider IDs. */ retrieveProviders( params: AuthRetrieveProvidersParams | null | undefined = {}, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat } = params ?? {}; return this._client.get('/auth/providers', { ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } } /** * 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. */ export interface CurrentUserOutput { id?: string | null; display_name?: string | null; email?: string | null; /** * Organization slug where user is global_admin, if any */ global_admin_slug?: string | null; is_guest?: boolean; /** * True for an organization API key (admin/org_api_key/\*) -- unlike is_sdk's * single deployment-wide BACKEND_SDK_SERVICE_API_KEY, this credential is * per-organization, created and revocable by that org's own admin via an * ADMIN_ACCESS-gated endpoint. */ is_org_api_key?: boolean; is_sdk?: boolean; is_slack?: boolean; is_verified?: boolean; is_whatsapp?: boolean; permissions?: Array; phone_number?: string | null; picture?: string | null; /** * Where a root-login sign-in should land. * * Attributes: action (RoutingAction): What to do with the result. organization * (RoutingOrganization | None): Set only when action is REDIRECT. organizations * (list[RoutingOrganization]): Set only when action is SELECT. */ post_login_routing?: PostLoginRouting | null; privacy_policy_consent?: boolean; /** * Authentication provider type */ provider?: string | null; requires_mfa?: boolean; roles?: Array; /** * Tenant model. */ selected_tenant?: Tenant | null; tenants?: Array; username?: string | null; } /** * Where a root-login sign-in should land. * * Attributes: action (RoutingAction): What to do with the result. organization * (RoutingOrganization | None): Set only when action is REDIRECT. organizations * (list[RoutingOrganization]): Set only when action is SELECT. */ export interface PostLoginRouting { /** * What the caller should do with a resolved post-login destination. * * REDIRECT: exactly one destination was resolved; send the user there. SELECT: * several are plausible and nothing distinguishes them; ask the user. NONE: the * user belongs to no organization; there is nowhere to send them. */ action: 'redirect' | 'select' | 'none'; /** * An organization the user may be routed to. * * Attributes: name (str): Display name. slug (str): URL slug the caller navigates * with (`/o/{slug}`). */ organization?: RoutingOrganization | null; organizations?: Array; } /** * An organization the user may be routed to. * * Attributes: name (str): Display name. slug (str): URL slug the caller navigates * with (`/o/{slug}`). */ export interface RoutingOrganization { name: string; slug: string; } /** * Tenant model. */ export interface Tenant { id: string; name: string; dark_icon_url?: string | null; light_icon_url?: string | null; slug?: string | null; } /** * Token model. */ export interface AuthDirectAPILoginResponse { access_token: string; /** * Token type */ token_type?: string; } /** * Last visited organization for an email. * * Attributes: organization (PublicOrganization | None): The organization, or None * when the address matches no user, that user has no recorded visit, or the visit * is no longer valid. */ export interface AuthLastVisitedOrganizationResponse { /** * An organization disclosed to an unauthenticated caller. * * Narrower than LastVisitedOrganization on purpose: the UUID is withheld because * this is served without a session, so it discloses only what is needed to * navigate. * * Attributes: name (str): Display name. slug (str): URL slug the UI navigates * with. */ organization?: AuthLastVisitedOrganizationResponse.Organization | null; } export namespace AuthLastVisitedOrganizationResponse { /** * An organization disclosed to an unauthenticated caller. * * Narrower than LastVisitedOrganization on purpose: the UUID is withheld because * this is served without a session, so it discloses only what is needed to * navigate. * * Attributes: name (str): Display name. slug (str): URL slug the UI navigates * with. */ export interface Organization { name: string; slug: string; } } export type AuthLogoutResponse = { [key: string]: string }; /** * Response for POST /auth/logout-all. */ export interface AuthLogoutAllResponse { message: string; revoked_sessions: number; } /** * Organizations the caller's email actively belongs to. * * `organizations` is empty when the address matches no active membership. That is * a normal outcome rather than an error: returning 404 for it would make the * status code itself an oracle for whether the address has an account at all. * * Attributes: organizations (list[OrganizationCandidate]): Matching organizations, * ordered by the membership's creation time (earliest assigned first). */ export interface AuthLookupEmailResponse { organizations?: Array; } export namespace AuthLookupEmailResponse { /** * An organization the caller's email actively belongs to. * * Carries only what the UI needs to render a choice: the slug to navigate to * `/o/{slug}`, the name to show, and the icons to show it with. The organization * UUID is deliberately withheld -- this endpoint answers an unauthenticated * caller, so it discloses the minimum rather than internal identifiers. * * The icons add nothing the caller could not already reach: GET /admin/company * accepts the same public API key and returns an organization's branding for any * slug, and the slug is in this response anyway. * * Both themes are returned because the caller picks between them client-side; * sending one would force the server to guess a theme it cannot see. * * Attributes: name (str): Display name. slug (str): URL slug the UI navigates * with. light_icon_url (str | None): Icon for light theme, presigned and * short-lived. dark_icon_url (str | None): Icon for dark theme, presigned and * short-lived. */ export interface Organization { name: string; slug: string; dark_icon_url?: string | null; light_icon_url?: string | null; } } /** * Response model for GET /auth/me. * * A CurrentUser subclass rather than a field added to CurrentUser itself, so the * GREETING_NAME_PREFERENCE lookup this endpoint does stays local to /auth/me and * isn't implied on every other endpoint that returns a bare CurrentUser (login, * post-login, ...). * * Attributes: greeting_name (str | None): The user's custom greeting name from * GREETING_NAME_PREFERENCE, for the welcome page. None when unset, when no tenant * is selected, or when the preference lookup fails; callers fall back to * display_name in that case. */ export interface AuthMeResponse { id?: string | null; display_name?: string | null; email?: string | null; /** * Organization slug where user is global_admin, if any */ global_admin_slug?: string | null; greeting_name?: string | null; is_guest?: boolean; /** * True for an organization API key (admin/org_api_key/\*) -- unlike is_sdk's * single deployment-wide BACKEND_SDK_SERVICE_API_KEY, this credential is * per-organization, created and revocable by that org's own admin via an * ADMIN_ACCESS-gated endpoint. */ is_org_api_key?: boolean; is_sdk?: boolean; is_slack?: boolean; is_verified?: boolean; is_whatsapp?: boolean; permissions?: Array; phone_number?: string | null; picture?: string | null; /** * Where a root-login sign-in should land. * * Attributes: action (RoutingAction): What to do with the result. organization * (RoutingOrganization | None): Set only when action is REDIRECT. organizations * (list[RoutingOrganization]): Set only when action is SELECT. */ post_login_routing?: PostLoginRouting | null; privacy_policy_consent?: boolean; /** * Authentication provider type */ provider?: string | null; requires_mfa?: boolean; roles?: Array; /** * Tenant model. */ selected_tenant?: Tenant | null; tenants?: Array; username?: string | null; } export type AuthResolveUsernameResponse = { [key: string]: string }; export type AuthRetrieveProvidersResponse = Array; export interface AuthDirectAPILoginParams { /** * Body param */ password: string; /** * Body param */ username: string; /** * Body param */ otp_verification_token?: string | null; /** * Header param */ 'Accept-Language'?: string; /** * Header param: Browser/client User-Agent. Parsed into device type, OS, and * browser for the Active Sessions page (FR-14) and adaptive-auth new-device * detection. */ 'User-Agent'?: 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; /** * Header param: Client IP as seen by the ingress/proxy (first hop is used). * Preferred over the raw socket address for masked-IP/location capture and * adaptive-auth new-country detection. */ 'X-Forwarded-For'?: string; /** * Header param: Fallback client IP, used only when `X-Forwarded-For` is absent. */ 'X-Real-IP'?: string; } export interface AuthLastVisitedOrganizationParams { /** * Body param */ email: 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 AuthLogoutParams { '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 AuthLogoutAllParams { '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 AuthLookupEmailParams { /** * Body param */ email: 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 AuthMeParams { '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 AuthPostLoginParams { 'Accept-Language'?: string; /** * Browser/client User-Agent. Parsed into device type, OS, and browser for the * Active Sessions page (FR-14) and adaptive-auth new-device detection. */ 'User-Agent'?: string; /** * Set to `structured` to receive errors in the structured envelope. Omit it to * keep the legacy error body. */ 'X-Error-Format'?: string; /** * Client IP as seen by the ingress/proxy (first hop is used). Preferred over the * raw socket address for masked-IP/location capture and adaptive-auth new-country * detection. */ 'X-Forwarded-For'?: string; /** * Fallback client IP, used only when `X-Forwarded-For` is absent. */ 'X-Real-IP'?: string; } export interface AuthResolveUsernameParams { /** * Body param */ identifier: 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 AuthRetrieveProvidersParams { '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; } Auth.Mobile = Mobile; Auth.Token = Token; Auth.Whatsapp = Whatsapp; Auth.Slack = Slack; Auth.APIKey = APIKey; Auth.Sessions = Sessions; Auth.AdaptiveStepUp = AdaptiveStepUp; Auth.V2 = V2; export declare namespace Auth { export { type CurrentUserOutput as CurrentUserOutput, type PostLoginRouting as PostLoginRouting, type RoutingOrganization as RoutingOrganization, type Tenant as Tenant, type AuthDirectAPILoginResponse as AuthDirectAPILoginResponse, type AuthLastVisitedOrganizationResponse as AuthLastVisitedOrganizationResponse, type AuthLogoutResponse as AuthLogoutResponse, type AuthLogoutAllResponse as AuthLogoutAllResponse, type AuthLookupEmailResponse as AuthLookupEmailResponse, type AuthMeResponse as AuthMeResponse, type AuthResolveUsernameResponse as AuthResolveUsernameResponse, type AuthRetrieveProvidersResponse as AuthRetrieveProvidersResponse, type AuthDirectAPILoginParams as AuthDirectAPILoginParams, type AuthLastVisitedOrganizationParams as AuthLastVisitedOrganizationParams, type AuthLogoutParams as AuthLogoutParams, type AuthLogoutAllParams as AuthLogoutAllParams, type AuthLookupEmailParams as AuthLookupEmailParams, type AuthMeParams as AuthMeParams, type AuthPostLoginParams as AuthPostLoginParams, type AuthResolveUsernameParams as AuthResolveUsernameParams, type AuthRetrieveProvidersParams as AuthRetrieveProvidersParams, }; export { Mobile as Mobile, type MobileCallbackResponse as MobileCallbackResponse, type MobileExchangeResponse as MobileExchangeResponse, type MobileLoginResponse as MobileLoginResponse, type MobileCallbackParams as MobileCallbackParams, type MobileExchangeParams as MobileExchangeParams, type MobileLoginParams as MobileLoginParams, }; export { Token as Token, type TokenValidateResponse as TokenValidateResponse, type TokenValidateParams as TokenValidateParams, }; export { Whatsapp as Whatsapp, type VerificationResponse as VerificationResponse, type WhatsappRegisterParams as WhatsappRegisterParams, }; export { Slack as Slack, type SlackRegisterResponse as SlackRegisterResponse, type SlackRegisterParams as SlackRegisterParams, type SlackUnregisterParams as SlackUnregisterParams, }; export { APIKey as APIKey, type UserAPIKeyResponse as UserAPIKeyResponse, type APIKeyRetrieveAPIKeyParams as APIKeyRetrieveAPIKeyParams, type APIKeyRotateParams as APIKeyRotateParams, }; export { Sessions as Sessions, type RevokeSessionsResponse as RevokeSessionsResponse, type SessionListResponse as SessionListResponse, type SessionListParams as SessionListParams, type SessionDeleteParams as SessionDeleteParams, type SessionDeleteAllParams as SessionDeleteAllParams, }; export { AdaptiveStepUp as AdaptiveStepUp, type PasswordLoginResponse as PasswordLoginResponse, type AdaptiveStepUpVerifyResponse as AdaptiveStepUpVerifyResponse, type AdaptiveStepUpResendParams as AdaptiveStepUpResendParams, type AdaptiveStepUpVerifyParams as AdaptiveStepUpVerifyParams, }; export { V2 as V2, type V2RetrieveProvidersResponse as V2RetrieveProvidersResponse, type V2RetrieveProvidersParams as V2RetrieveProvidersParams, }; }