export type GetApiOauthPgAuthorizeArgs = {response_type: string, client_id: string, redirect_uri: string, code_challenge: string, code_challenge_method: string, scope: string, state?: (string | null) | undefined, nonce?: (string | null) | undefined, login_hint?: (string | null) | undefined, resource?: (string | null) | undefined}; export type GetApiOauthPgAuthorizeOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Authorize Endpoint * * GET /oauth/pg/authorize */ export const getApiOauthPgAuthorize = async (args: GetApiOauthPgAuthorizeArgs, options: GetApiOauthPgAuthorizeOptions) => { const {baseUrl, 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.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.scope != null) query.append("scope", String(args.scope)) if (args.state != null) query.append("state", String(args.state)) if (args.nonce != null) query.append("nonce", String(args.nonce)) if (args.login_hint != null) query.append("login_hint", String(args.login_hint)) if (args.resource != null) query.append("resource", String(args.resource)) const url = `${baseUrl.replace(/\/+$/, '')}/oauth/pg/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() };