export type GetApiWellKnownOauthAuthorizationServerOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Handler for OAuth 2.0 Authorization Server Metadata (Enterprise) * RFC 8414: https://datatracker.ietf.org/doc/html/rfc8414 * Public (no auth) — describes the Dex authorization server, 404 when Dex is off. * * GET /.well-known/oauth-authorization-server */ export const getApiWellKnownOauthAuthorizationServer = async (options: GetApiWellKnownOauthAuthorizationServerOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/.well-known/oauth-authorization-server${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 (await res.json()) as unknown };