diff --git a/src/Auth0Client.ts b/src/Auth0Client.ts index 4f94cbbba..ede6fa688 100644 --- a/src/Auth0Client.ts +++ b/src/Auth0Client.ts @@ -19,6 +19,20 @@ import { AuthenticationError } from './errors'; import * as ClientStorage from './storage'; import { DEFAULT_POPUP_CONFIG_OPTIONS } from './constants'; import version from './version'; +import { + Auth0ClientOptions, + BaseLoginOptions, + AuthorizeOptions, + PopupConfigOptions, + PopupLoginOptions, + GetUserOptions, + GetIdTokenClaimsOptions, + RedirectLoginOptions, + RedirectLoginResult, + GetTokenSilentlyOptions, + GetTokenWithPopupOptions, + LogoutOptions +} from './global'; /** * Auth0 SDK for Single Page Applications using [Authorization Code Grant Flow with PKCE](https://auth0.com/docs/api-auth/tutorials/authorization-code-grant-pkce). @@ -174,7 +188,7 @@ export default class Auth0Client { * @param options */ public async getIdTokenClaims( - options: getIdTokenClaimsOptions = { + options: GetIdTokenClaimsOptions = { audience: this.options.audience || 'default', scope: this.options.scope || this.DEFAULT_SCOPE } diff --git a/src/cache.ts b/src/cache.ts index 337e772e6..281fd42f4 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -1,3 +1,5 @@ +import { IdToken } from './global'; + interface CacheKeyData { audience: string; scope: string; diff --git a/src/constants.ts b/src/constants.ts index 710c5aa71..7d590b1e5 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,3 +1,5 @@ +import { PopupConfigOptions } from './global'; + /** * @ignore */ diff --git a/src/global.ts b/src/global.ts index 6360ac016..689efdc50 100644 --- a/src/global.ts +++ b/src/global.ts @@ -1,7 +1,7 @@ /** * @ignore */ -interface BaseLoginOptions { +export interface BaseLoginOptions { /** * - `'page'`: displays the UI with a full page view * - `'popup'`: displays the UI with a popup window @@ -61,7 +61,7 @@ interface BaseLoginOptions { [key: string]: any; } -interface Auth0ClientOptions extends BaseLoginOptions { +export interface Auth0ClientOptions extends BaseLoginOptions { /** * Your Auth0 account domain such as `'example.auth0.com'`, * `'example.eu.auth0.com'` or , `'example.mycompany.com'` @@ -90,7 +90,7 @@ interface Auth0ClientOptions extends BaseLoginOptions { /** * @ignore */ -interface AuthorizeOptions extends BaseLoginOptions { +export interface AuthorizeOptions extends BaseLoginOptions { response_type: string; response_mode: string; redirect_uri: string; @@ -101,7 +101,7 @@ interface AuthorizeOptions extends BaseLoginOptions { code_challenge_method: string; } -interface RedirectLoginOptions extends BaseLoginOptions { +export interface RedirectLoginOptions extends BaseLoginOptions { /** * The URL where Auth0 will redirect your browser to with * the authentication result. It must be whitelisted in @@ -115,16 +115,16 @@ interface RedirectLoginOptions extends BaseLoginOptions { appState?: any; } -interface RedirectLoginResult { +export interface RedirectLoginResult { /** * State stored when the redirect request was made */ appState?: any; } -interface PopupLoginOptions extends BaseLoginOptions {} +export interface PopupLoginOptions extends BaseLoginOptions {} -interface PopupConfigOptions { +export interface PopupConfigOptions { /** * The number of seconds to wait for a popup response before * throwing a timeout error. Defaults to 60s @@ -132,7 +132,7 @@ interface PopupConfigOptions { timeoutInSeconds?: number; } -interface GetUserOptions { +export interface GetUserOptions { /** * The scope that was used in the authentication request */ @@ -143,7 +143,7 @@ interface GetUserOptions { audience: string; } -interface getIdTokenClaimsOptions { +export interface GetIdTokenClaimsOptions { /** * The scope that was used in the authentication request */ @@ -154,7 +154,9 @@ interface getIdTokenClaimsOptions { audience: string; } -interface GetTokenSilentlyOptions extends GetUserOptions { +export type getIdTokenClaimsOptions = GetIdTokenClaimsOptions; + +export interface GetTokenSilentlyOptions extends GetUserOptions { /** * When `true`, ignores the cache and always sends a * request to Auth0. @@ -177,9 +179,10 @@ interface GetTokenSilentlyOptions extends GetUserOptions { */ [key: string]: any; } -interface GetTokenWithPopupOptions extends PopupLoginOptions {} -interface LogoutOptions { +export interface GetTokenWithPopupOptions extends PopupLoginOptions {} + +export interface LogoutOptions { /** * The URL where Auth0 will redirect your browser to after the logout. * @@ -209,7 +212,7 @@ interface LogoutOptions { /** * @ignore */ -interface AuthenticationResult { +export interface AuthenticationResult { state: string; code?: string; error?: string; @@ -219,7 +222,7 @@ interface AuthenticationResult { /** * @ignore */ -interface OAuthTokenOptions { +export interface OAuthTokenOptions { baseUrl: string; client_id: string; audience?: string; @@ -230,7 +233,7 @@ interface OAuthTokenOptions { /** * @ignore */ -interface JWTVerifyOptions { +export interface JWTVerifyOptions { iss: string; aud: string; id_token: string; @@ -241,7 +244,7 @@ interface JWTVerifyOptions { /** * @ignore */ -interface IdToken { +export interface IdToken { __raw: string; name?: string; given_name?: string; diff --git a/src/index.ts b/src/index.ts index 44a6d5018..e03a1a905 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,7 +9,7 @@ import Auth0Client from './Auth0Client'; import * as ClientStorage from './storage'; //this is necessary to export the type definitions used in this file -import './global'; +import { Auth0ClientOptions } from './global'; export default async function createAuth0Client(options: Auth0ClientOptions) { if (!window.crypto && (window).msCrypto) { @@ -44,3 +44,5 @@ export default async function createAuth0Client(options: Auth0ClientOptions) { } return auth0; } + +export * from './global'; diff --git a/src/jwt.ts b/src/jwt.ts index 1cce8fd0b..e51c5d1de 100644 --- a/src/jwt.ts +++ b/src/jwt.ts @@ -1,4 +1,5 @@ import { urlDecodeB64 } from './utils'; +import { JWTVerifyOptions, IdToken } from './global'; const idTokendecoded = [ 'iss', diff --git a/src/utils.ts b/src/utils.ts index cc73c84ad..2a37e0741 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,6 +1,11 @@ import fetch from 'unfetch'; import { DEFAULT_AUTHORIZE_TIMEOUT_IN_SECONDS } from './constants'; +import { + AuthenticationResult, + PopupConfigOptions, + OAuthTokenOptions +} from './global'; const dedupe = arr => arr.filter((x, i) => arr.indexOf(x) === i);