export type DisplayModesEnum = 'page' | 'popup' | 'touch' | 'mobile'; export type CodeChallengeMethodEnum = 'plain' | 'S256'; export type AuthorizeRequest = {response_type: 'code', redirect_uri?: string | undefined, client_id: string, state?: string | undefined, scope?: string | undefined, display?: DisplayModesEnum | undefined, prompt?: string | undefined, ui_locales?: string | undefined, code_challenge?: string | undefined, code_challenge_method?: CodeChallengeMethodEnum | undefined, nonce?: string | undefined, ui_options?: string | undefined, login_hint?: string | undefined, brand_id?: string | undefined, accept_language?: string | undefined}; export type CreateApiRestapiOauthAuthorizeArgs = {body: AuthorizeRequest}; export type CreateApiRestapiOauthAuthorizeOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; /** * OAuth 2.0 Authorization Endpoint (POST) * * POST /restapi/oauth/authorize */ export const createApiRestapiOauthAuthorize = async (args: CreateApiRestapiOauthAuthorizeArgs, options?: CreateApiRestapiOauthAuthorizeOptions) => { const {baseUrl = "https://platform.ringcentral.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-www-form-urlencoded") if (OAuth2 !== undefined) headers.set('authorization', `Bearer ${OAuth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/restapi/oauth/authorize${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: new URLSearchParams(Object.entries(args.body).flatMap(([key, value]) => (value == null ? [] : [[key, String(value)]])))}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };