export type GetApiApiOauthAuthorizeArgs = {response_type: 'code', client_id: string, redirect_uri: string, scope: string, state: string, code_challenge?: string | undefined, code_challenge_method?: 'S256' | undefined, nonce?: string | undefined, response_mode?: ('query' | 'fragment' | 'form_post') | undefined, prompt?: string | undefined, max_age?: number | undefined, login_hint?: string | undefined}; export type GetApiApiOauthAuthorizeOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Start the OAuth authorization-code flow * * GET /api/oauth/authorize */ export const getApiApiOauthAuthorize = async (args: GetApiApiOauthAuthorizeArgs, options?: GetApiApiOauthAuthorizeOptions) => { const {baseUrl = "https://portal.eprospera.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/html") if (args.response_type != null) query.append("response_type", String(args.response_type)) if (args.client_id != null) query.append("client_id", String(args.client_id)) if (args.redirect_uri != null) query.append("redirect_uri", String(args.redirect_uri)) if (args.scope != null) query.append("scope", String(args.scope)) if (args.state != null) query.append("state", String(args.state)) 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.response_mode != null) query.append("response_mode", String(args.response_mode)) if (args.prompt != null) query.append("prompt", String(args.prompt)) if (args.max_age != null) query.append("max_age", String(args.max_age)) if (args.login_hint != null) query.append("login_hint", String(args.login_hint)) const url = `${baseUrl.replace(/\/+$/, '')}/api/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 res.text() };