// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../../core/resource'; import * as AuthAPI from './auth'; import * as StepUpAPI from '../users/verification/step-up'; import { APIPromise } from '../../core/api-promise'; import { buildHeaders } from '../../internal/headers'; import { RequestOptions } from '../../internal/request-options'; export class AdaptiveStepUp extends APIResource { /** * Resend the OTP for an in-progress adaptive authentication step-up challenge. * * Call this when the client wants a new code for a challenge issued by `direct_api_login`'s * `ADAPTIVE_AUTH_STEP_UP_REQUIRED`. There is no session yet at that point, so this re-derives * the user/organization from `username` the same way `verify_adaptive_auth_step_up` does, or from * the stashed pending login (direct-login or OAuth/SSO) when `username` is omitted. */ resend( params: AdaptiveStepUpResendParams, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat, ...body } = params; return this._client.post('/auth/adaptive-step-up/resend', { body, ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } /** * Complete an adaptive authentication step-up OTP challenge and finish the login. * * Call this after `direct_api_login` or the OAuth/SSO `/{type}/post-login` (type=oauth) returns * `ADAPTIVE_AUTH_STEP_UP_REQUIRED` (issues #11793/#11794: a login from a new country or device, * with MFA not enabled). There is no session yet at that point, so for a `direct_api_login` * challenge this endpoint re-derives the user/organization from `username` the same way that * endpoint itself does. `username` may be omitted for an OAuth/SSO `/post-login` challenge: the * client never learns the backend username, so the user/organization come from the pending * login stashed under `challenge_id`. `username` may likewise be omitted for a `direct_api_login` * challenge: the user/organization then come from the pending login stashed under `challenge_id`. * * On success, returns the same response the challenging endpoint would have: `PasswordLoginResponse` * (CurrentUser plus StackAuth tokens) for a `direct_api_login`-origin challenge, or `CurrentUser` * for an OAuth/SSO `/post-login`-origin challenge -- there is no need to resubmit either endpoint. */ verify( params: AdaptiveStepUpVerifyParams, options?: RequestOptions, ): APIPromise { const { 'Accept-Language': acceptLanguage, 'X-Error-Format': xErrorFormat, ...body } = params; return this._client.post('/auth/adaptive-step-up/verify', { body, ...options, headers: buildHeaders([ { ...(acceptLanguage != null ? { 'Accept-Language': acceptLanguage } : undefined), ...(xErrorFormat != null ? { 'X-Error-Format': xErrorFormat } : undefined), }, options?.headers, ]), }); } } /** * Backend-centralized password login response. * * Returned on successful login; includes CurrentUser and StackAuth tokens for * session use. */ export interface PasswordLoginResponse { /** * StackAuth access token for API calls */ access_token: string; /** * StackAuth refresh token */ refresh_token: string; /** * Current user with tenants, roles, and permissions */ user: AuthAPI.CurrentUserOutput; /** * Token type */ token_type?: string; } /** * Backend-centralized password login response. * * Returned on successful login; includes CurrentUser and StackAuth tokens for * session use. */ export type AdaptiveStepUpVerifyResponse = PasswordLoginResponse | AuthAPI.CurrentUserOutput | PasswordLoginResponse | AuthAPI.CurrentUserOutput; export interface AdaptiveStepUpResendParams { /** * Body param */ challenge_id: string; /** * Body param */ username?: string | null; /** * 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 AdaptiveStepUpVerifyParams { /** * Body param */ challenge_id: string; /** * Body param */ code: string; /** * Body param */ username?: string | null; /** * 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 AdaptiveStepUp { export { type PasswordLoginResponse as PasswordLoginResponse, type AdaptiveStepUpVerifyResponse as AdaptiveStepUpVerifyResponse, type AdaptiveStepUpResendParams as AdaptiveStepUpResendParams, type AdaptiveStepUpVerifyParams as AdaptiveStepUpVerifyParams, }; }