export type CreateApiAuthoriserTenantIdOauth2V20TokenArgs = {authoriserTenantId: string}; export type CreateApiAuthoriserTenantIdOauth2V20TokenOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * GetBearerTokenClientCreds * * POST /{authoriserTenantId}/oauth2/v2.0/token */ export const createApiAuthoriserTenantIdOauth2V20Token = async (args: CreateApiAuthoriserTenantIdOauth2V20TokenArgs, options?: CreateApiAuthoriserTenantIdOauth2V20TokenOptions) => { const {baseUrl = "https://login.microsoftonline.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/${encodeURIComponent(String(args.authoriserTenantId))}/oauth2/v2.0/token${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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 };