UNPKG

@auth0/auth0-spa-js

Version:

Auth0 SDK for Single Page Applications using Authorization Code Grant Flow with PKCE

43 lines (40 loc) 936 B
import { TokenEndpointOptions, TokenEndpointResponse } from './global'; import { DEFAULT_AUTH0_CLIENT } from './constants'; import { getJSON } from './http'; import { createQueryParams } from './utils'; export async function oauthToken( { baseUrl, timeout, audience, scope, auth0Client, useFormData, ...options }: TokenEndpointOptions, worker?: Worker ) { const body = useFormData ? createQueryParams(options) : JSON.stringify(options); return await getJSON<TokenEndpointResponse>( `${baseUrl}/oauth/token`, timeout, audience || 'default', scope, { method: 'POST', body, headers: { 'Content-Type': useFormData ? 'application/x-www-form-urlencoded' : 'application/json', 'Auth0-Client': btoa( JSON.stringify(auth0Client || DEFAULT_AUTH0_CLIENT) ) } }, worker, useFormData ); }