export type DisplayModesEnum = 'page' | 'popup' | 'touch' | 'mobile'; export type CodeChallengeMethodEnum = 'plain' | 'S256'; export type GetApiRestapiOauthAuthorizeArgs = {client_id: string, response_type: 'code', redirect_uri?: string | undefined, state?: string | undefined, scope?: string | undefined, display?: DisplayModesEnum | undefined, prompt?: string | undefined, ui_locales?: string | undefined, localeId?: 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}; export type GetApiRestapiOauthAuthorizeOptions = {baseUrl?: string | undefined, OAuth2?: string | undefined, fetch?: typeof fetch | undefined}; /** * OAuth 2.0 Authorization Endpoint * * GET /restapi/oauth/authorize */ export const getApiRestapiOauthAuthorize = async (args: GetApiRestapiOauthAuthorizeArgs, options?: GetApiRestapiOauthAuthorizeOptions) => { const {baseUrl = "https://platform.ringcentral.com", fetch: fetchFn = fetch, OAuth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.client_id != null) query.append("client_id", String(args.client_id)) if (args.response_type != null) query.append("response_type", String(args.response_type)) if (args.redirect_uri != null) query.append("redirect_uri", String(args.redirect_uri)) if (args.state != null) query.append("state", String(args.state)) if (args.scope != null) query.append("scope", String(args.scope)) if (args.display != null) query.append("display", String(args.display)) if (args.prompt != null) query.append("prompt", String(args.prompt)) if (args.ui_locales != null) query.append("ui_locales", String(args.ui_locales)) if (args.localeId != null) query.append("localeId", String(args.localeId)) if (args.code_challenge != null) query.append("code_challenge", String(args.code_challenge)) if (args.code_challenge_method != null) query.append("code_challenge_method", String(args.code_challenge_method)) if (args.nonce != null) query.append("nonce", String(args.nonce)) if (args.ui_options != null) query.append("ui_options", String(args.ui_options)) if (args.login_hint != null) query.append("login_hint", String(args.login_hint)) if (args.brand_id != null) query.append("brand_id", String(args.brand_id)) 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: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };