import type { TokenEndpointOptions, TokenEndpointResponse } from './global' import { DEFAULT_AUTHC_CLIENT } from './constants' import { getJSON } from './http' import { createQueryParams } from './utils' export async function oauthToken( { baseUrl, timeout, audience, scope, authcClient, useFormData, ...options }: TokenEndpointOptions, worker?: Worker, ) { const body = useFormData ? createQueryParams(options) : JSON.stringify(options) return await getJSON( `${baseUrl}/oauth/token`, timeout, audience || 'default', scope, { method: 'POST', body, headers: { 'Content-Type': useFormData ? 'application/x-www-form-urlencoded' : 'application/json', 'Authc-Client': btoa( JSON.stringify(authcClient || DEFAULT_AUTHC_CLIENT), ), }, }, worker, useFormData, ) }