Skip to content

Commit

Permalink
customize token endpoint handler
Browse files Browse the repository at this point in the history
  • Loading branch information
abbaspour committed Oct 15, 2024
1 parent c4d2974 commit 765d48f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Auth0Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ import {
User,
IdToken,
GetTokenSilentlyVerboseResponse,
TokenEndpointResponse
TokenEndpointResponse,
TokenEndpointOptions
} from './global';

// @ts-ignore
Expand Down Expand Up @@ -123,6 +124,7 @@ export class Auth0Client {
private readonly isAuthenticatedCookieName: string;
private readonly nowProvider: () => number | Promise<number>;
private readonly httpTimeoutMs: number;
private readonly tokenEndpointHandler: (options: TokenEndpointOptions, worker?: Worker) => Promise<TokenEndpointResponse>;
private readonly options: Auth0ClientOptions & {
authorizationParams: AuthorizationParams;
};
Expand Down Expand Up @@ -213,6 +215,8 @@ export class Auth0Client {

this.nowProvider = this.options.nowProvider || DEFAULT_NOW_PROVIDER;

this.tokenEndpointHandler = this.options.tokenEndpointHandler || oauthToken;

this.cacheManager = new CacheManager(
cache,
!cache.allKeys
Expand Down Expand Up @@ -1101,7 +1105,7 @@ export class Auth0Client {
additionalParameters?: RequestTokenAdditionalParameters
) {
const { nonceIn, organization } = additionalParameters || {};
const authResult = await oauthToken(
const authResult = await this.tokenEndpointHandler(
{
baseUrl: this.domainUrl,
client_id: this.options.clientId,
Expand Down
7 changes: 7 additions & 0 deletions src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,13 @@ export interface Auth0ClientOptions extends BaseLoginOptions {
* **Note**: The worker is only used when `useRefreshTokens: true`, `cacheLocation: 'memory'`, and the `cache` is not custom.
*/
workerUrl?: string;

/**
* If provided, the SDK will use this method to communicate with token endpoint.
* @param options
* @param worker
*/
tokenEndpointHandler?: (options: TokenEndpointOptions, worker?: Worker) => Promise<TokenEndpointResponse>;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export async function createAuth0Client(options: Auth0ClientOptions) {

export { Auth0Client };

export { getJSON } from './http';

export {
GenericError,
AuthenticationError,
Expand Down

0 comments on commit 765d48f

Please sign in to comment.