@auth0/ai 4.0.1 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/cjs/authorizers/{ciba/CIBAAuthorizationRequest.js → async-authorization/AsyncAuthorizationRequest.js} +1 -1
- package/dist/cjs/authorizers/async-authorization/AsyncAuthorizationRequest.js.map +1 -0
- package/dist/cjs/authorizers/{ciba/CIBAAuthorizerBase.js → async-authorization/AsyncAuthorizerBase.js} +4 -4
- package/dist/cjs/authorizers/async-authorization/AsyncAuthorizerBase.js.map +1 -0
- package/dist/cjs/authorizers/{ciba/CIBAAuthorizerParams.js → async-authorization/AsyncAuthorizerParams.js} +1 -1
- package/dist/cjs/authorizers/async-authorization/AsyncAuthorizerParams.js.map +1 -0
- package/dist/cjs/authorizers/{ciba → async-authorization}/asyncLocalStorage.js +4 -4
- package/dist/cjs/authorizers/async-authorization/asyncLocalStorage.js.map +1 -0
- package/dist/cjs/authorizers/async-authorization/index.js +9 -0
- package/dist/cjs/authorizers/async-authorization/index.js.map +1 -0
- package/dist/cjs/authorizers/device-authorizer/asyncLocalStorage.js +1 -1
- package/dist/cjs/authorizers/device-authorizer/asyncLocalStorage.js.map +1 -1
- package/dist/cjs/authorizers/{federated-connections/FederatedConnectionAuthorizerBase.js → token-vault/TokenVaultAuthorizerBase.js} +14 -14
- package/dist/cjs/authorizers/token-vault/TokenVaultAuthorizerBase.js.map +1 -0
- package/dist/cjs/authorizers/{federated-connections/FederatedConnectionAuthorizerParams.js → token-vault/TokenVaultAuthorizerParams.js} +1 -1
- package/dist/cjs/authorizers/token-vault/TokenVaultAuthorizerParams.js.map +1 -0
- package/dist/cjs/authorizers/{federated-connections → token-vault}/asyncLocalStorage.js +9 -9
- package/dist/cjs/authorizers/token-vault/asyncLocalStorage.js.map +1 -0
- package/dist/cjs/authorizers/token-vault/index.js +12 -0
- package/dist/cjs/authorizers/token-vault/index.js.map +1 -0
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/interrupts/{CIBAInterrupts.js → AsyncAuthorizationInterrupt.js} +12 -12
- package/dist/cjs/interrupts/AsyncAuthorizationInterrupt.js.map +1 -0
- package/dist/cjs/interrupts/{FederatedConnectionInterrupt.js → TokenVaultInterrupt.js} +9 -9
- package/dist/cjs/interrupts/TokenVaultInterrupt.js.map +1 -0
- package/dist/cjs/interrupts/index.js +12 -12
- package/dist/cjs/interrupts/index.js.map +1 -1
- package/dist/cjs/stores/Store.js +1 -1
- package/dist/cjs/stores/Store.js.map +1 -1
- package/dist/esm/authorizers/{ciba/CIBAAuthorizationRequest.d.ts → async-authorization/AsyncAuthorizationRequest.d.ts} +2 -2
- package/dist/esm/authorizers/async-authorization/AsyncAuthorizationRequest.js +2 -0
- package/dist/esm/authorizers/async-authorization/AsyncAuthorizationRequest.js.map +1 -0
- package/dist/esm/authorizers/{ciba/CIBAAuthorizerBase.d.ts → async-authorization/AsyncAuthorizerBase.d.ts} +7 -7
- package/dist/esm/authorizers/{ciba/CIBAAuthorizerBase.js → async-authorization/AsyncAuthorizerBase.js} +2 -2
- package/dist/esm/authorizers/async-authorization/AsyncAuthorizerBase.js.map +1 -0
- package/dist/esm/authorizers/{ciba/CIBAAuthorizerParams.d.ts → async-authorization/AsyncAuthorizerParams.d.ts} +6 -6
- package/dist/esm/authorizers/async-authorization/AsyncAuthorizerParams.js +2 -0
- package/dist/esm/authorizers/async-authorization/AsyncAuthorizerParams.js.map +1 -0
- package/dist/esm/authorizers/{ciba → async-authorization}/asyncLocalStorage.d.ts +1 -1
- package/dist/esm/authorizers/{ciba → async-authorization}/asyncLocalStorage.js +2 -2
- package/dist/esm/authorizers/async-authorization/asyncLocalStorage.js.map +1 -0
- package/dist/esm/authorizers/async-authorization/index.d.ts +4 -0
- package/dist/esm/authorizers/async-authorization/index.js +3 -0
- package/dist/esm/authorizers/async-authorization/index.js.map +1 -0
- package/dist/esm/authorizers/device-authorizer/asyncLocalStorage.js +1 -1
- package/dist/esm/authorizers/device-authorizer/asyncLocalStorage.js.map +1 -1
- package/dist/esm/authorizers/{federated-connections/FederatedConnectionAuthorizerBase.d.ts → token-vault/TokenVaultAuthorizerBase.d.ts} +6 -6
- package/dist/esm/authorizers/{federated-connections/FederatedConnectionAuthorizerBase.js → token-vault/TokenVaultAuthorizerBase.js} +12 -12
- package/dist/esm/authorizers/token-vault/TokenVaultAuthorizerBase.js.map +1 -0
- package/dist/esm/authorizers/{federated-connections/FederatedConnectionAuthorizerParams.d.ts → token-vault/TokenVaultAuthorizerParams.d.ts} +8 -8
- package/dist/esm/authorizers/{federated-connections/FederatedConnectionAuthorizerParams.js → token-vault/TokenVaultAuthorizerParams.js} +1 -1
- package/dist/esm/authorizers/token-vault/TokenVaultAuthorizerParams.js.map +1 -0
- package/dist/esm/authorizers/{federated-connections → token-vault}/asyncLocalStorage.d.ts +6 -6
- package/dist/esm/authorizers/{federated-connections → token-vault}/asyncLocalStorage.js +7 -7
- package/dist/esm/authorizers/token-vault/asyncLocalStorage.js.map +1 -0
- package/dist/esm/authorizers/token-vault/index.d.ts +6 -0
- package/dist/esm/authorizers/token-vault/index.js +4 -0
- package/dist/esm/authorizers/token-vault/index.js.map +1 -0
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interrupts/{CIBAInterrupts.d.ts → AsyncAuthorizationInterrupt.d.ts} +21 -21
- package/dist/esm/interrupts/{CIBAInterrupts.js → AsyncAuthorizationInterrupt.js} +10 -10
- package/dist/esm/interrupts/AsyncAuthorizationInterrupt.js.map +1 -0
- package/dist/esm/interrupts/{FederatedConnectionInterrupt.d.ts → TokenVaultInterrupt.d.ts} +5 -5
- package/dist/esm/interrupts/{FederatedConnectionInterrupt.js → TokenVaultInterrupt.js} +6 -6
- package/dist/esm/interrupts/TokenVaultInterrupt.js.map +1 -0
- package/dist/esm/interrupts/index.d.ts +2 -2
- package/dist/esm/interrupts/index.js +2 -2
- package/dist/esm/interrupts/index.js.map +1 -1
- package/dist/esm/stores/Store.d.ts +1 -1
- package/dist/esm/stores/Store.js +1 -1
- package/dist/esm/stores/Store.js.map +1 -1
- package/package.json +9 -9
- package/dist/cjs/authorizers/ciba/CIBAAuthorizationRequest.js.map +0 -1
- package/dist/cjs/authorizers/ciba/CIBAAuthorizerBase.js.map +0 -1
- package/dist/cjs/authorizers/ciba/CIBAAuthorizerParams.js.map +0 -1
- package/dist/cjs/authorizers/ciba/asyncLocalStorage.js.map +0 -1
- package/dist/cjs/authorizers/ciba/index.js +0 -9
- package/dist/cjs/authorizers/ciba/index.js.map +0 -1
- package/dist/cjs/authorizers/federated-connections/FederatedConnectionAuthorizerBase.js.map +0 -1
- package/dist/cjs/authorizers/federated-connections/FederatedConnectionAuthorizerParams.js.map +0 -1
- package/dist/cjs/authorizers/federated-connections/asyncLocalStorage.js.map +0 -1
- package/dist/cjs/authorizers/federated-connections/index.js +0 -12
- package/dist/cjs/authorizers/federated-connections/index.js.map +0 -1
- package/dist/cjs/interrupts/CIBAInterrupts.js.map +0 -1
- package/dist/cjs/interrupts/FederatedConnectionInterrupt.js.map +0 -1
- package/dist/esm/authorizers/ciba/CIBAAuthorizationRequest.js +0 -2
- package/dist/esm/authorizers/ciba/CIBAAuthorizationRequest.js.map +0 -1
- package/dist/esm/authorizers/ciba/CIBAAuthorizerBase.js.map +0 -1
- package/dist/esm/authorizers/ciba/CIBAAuthorizerParams.js +0 -2
- package/dist/esm/authorizers/ciba/CIBAAuthorizerParams.js.map +0 -1
- package/dist/esm/authorizers/ciba/asyncLocalStorage.js.map +0 -1
- package/dist/esm/authorizers/ciba/index.d.ts +0 -4
- package/dist/esm/authorizers/ciba/index.js +0 -3
- package/dist/esm/authorizers/ciba/index.js.map +0 -1
- package/dist/esm/authorizers/federated-connections/FederatedConnectionAuthorizerBase.js.map +0 -1
- package/dist/esm/authorizers/federated-connections/FederatedConnectionAuthorizerParams.js.map +0 -1
- package/dist/esm/authorizers/federated-connections/asyncLocalStorage.js.map +0 -1
- package/dist/esm/authorizers/federated-connections/index.d.ts +0 -6
- package/dist/esm/authorizers/federated-connections/index.js +0 -4
- package/dist/esm/authorizers/federated-connections/index.js.map +0 -1
- package/dist/esm/interrupts/CIBAInterrupts.js.map +0 -1
- package/dist/esm/interrupts/FederatedConnectionInterrupt.js.map +0 -1
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ We appreciate feedback and contribution to this repo! Before you get started, pl
|
|
|
24
24
|
|
|
25
25
|
### Raise an issue
|
|
26
26
|
|
|
27
|
-
To provide feedback or report a bug, please [raise an issue on our issue tracker](https://github.com/auth0
|
|
27
|
+
To provide feedback or report a bug, please [raise an issue on our issue tracker](https://github.com/auth0/auth0-ai-js/issues).
|
|
28
28
|
|
|
29
29
|
### Vulnerability Reporting
|
|
30
30
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AsyncAuthorizationRequest.js","sourceRoot":"","sources":["../../../../src/authorizers/async-authorization/AsyncAuthorizationRequest.ts"],"names":[],"mappings":"","sourcesContent":["export type AsyncAuthorizationRequest = {\n /**\n * The authorization request ID.\n * Use this ID to check the status of the authorization request.\n */\n id: string;\n\n /**\n * The time the authorization request was made.\n */\n requestedAt: number;\n\n /**\n * The time in seconds for the authorization request to expire.\n */\n expiresIn: number;\n\n /**\n * The interval in seconds to use when polling the status.\n */\n interval: number;\n};\n"]}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.AsyncAuthorizerBase = void 0;
|
|
7
7
|
const auth0_1 = require("auth0");
|
|
8
8
|
const crypto_1 = __importDefault(require("crypto"));
|
|
9
9
|
const stable_hash_1 = __importDefault(require("stable-hash"));
|
|
@@ -22,7 +22,7 @@ function ensureOpenIdScope(scopes) {
|
|
|
22
22
|
* Requests authorization by prompting the user via an out-of-band channel from
|
|
23
23
|
* the backend.
|
|
24
24
|
*/
|
|
25
|
-
class
|
|
25
|
+
class AsyncAuthorizerBase {
|
|
26
26
|
constructor(auth0, params) {
|
|
27
27
|
this.auth0 = new auth0_1.AuthenticationClient(types_1.Auth0ClientSchema.parse(auth0));
|
|
28
28
|
this.params = {
|
|
@@ -237,5 +237,5 @@ class CIBAAuthorizerBase {
|
|
|
237
237
|
throw err;
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
|
-
exports.
|
|
241
|
-
//# sourceMappingURL=
|
|
240
|
+
exports.AsyncAuthorizerBase = AsyncAuthorizerBase;
|
|
241
|
+
//# sourceMappingURL=AsyncAuthorizerBase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AsyncAuthorizerBase.js","sourceRoot":"","sources":["../../../../src/authorizers/async-authorization/AsyncAuthorizerBase.ts"],"names":[],"mappings":";;;;;;AAAA,iCAA6C;AAC7C,oDAA4B;AAC5B,8DAAqC;AAErC,mDAAwE;AACxE,iDAO0B;AAC1B,iDAAoD;AACpD,yCAAwC;AAExC,wCAA0D;AAC1D,oCAAgE;AAGhE,2DAA2E;AAE3E,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAChF,SAAS,iBAAiB,CAAC,MAAgB;IACzC,OAAO,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,GAAG,MAAM,CAAC,CAAC;AACpE,CAAC;AACD;;;GAGG;AACH,MAAa,mBAAmB;IAU9B,YACE,KAAiC,EACjC,MAA8C;QAE9C,IAAI,CAAC,KAAK,GAAG,IAAI,4BAA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AAC;yBAAM,CAAC;wBACN,MAAM,IAAI,CAAC,iBAAiB,EAAE,CAAC;wBAC/B,IAAI,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,KAAK,UAAU,EAAE,CAAC;4BACrD,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,GAAY,EAAE,GAAG,IAAI,CAAC,CAAC;wBAC3D,CAAC;6BAAM,CAAC;4BACN,OAAO,GAAG,CAAC;wBACb,CAAC;oBACH,CAAC;gBACH,CAAC;gBACD,UAAU,CAAC,WAAW,GAAG,WAAW,CAAC;gBACrC,OAAO,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;YAC1B,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;IAES,KAAK,CAAC,6BAA6B,CAC3C,GAAkE;QAElE,IAAI,IAAI,CAAC,MAAM,CAAC,wBAAwB,EAAE,CAAC;YACzC,MAAM,KAAK,GAAG,qCAAiB,CAAC,QAAQ,EAAE,CAAC;YAC3C,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;YACtE,CAAC;YACD,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;YAC1B,MAAM,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAC3D,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;CACF;AAjTD,kDAiTC","sourcesContent":["import { AuthenticationClient } from \"auth0\";\nimport crypto from \"crypto\";\nimport stableHash from \"stable-hash\";\n\nimport { TokenSet, tokenSetFromTokenResponse } from \"../../credentials\";\nimport {\n AccessDeniedInterrupt,\n AuthorizationPendingInterrupt,\n AuthorizationPollingInterrupt,\n AuthorizationRequestExpiredInterrupt,\n InvalidGrantInterrupt,\n UserDoesNotHavePushNotificationsInterrupt,\n} from \"../../interrupts\";\nimport { resolveParameter } from \"../../parameters\";\nimport { SubStore } from \"../../stores\";\nimport { RequireFields } from \"../../util\";\nimport { ContextGetter, nsFromContext } from \"../context\";\nimport { Auth0ClientParams, Auth0ClientSchema } from \"../types\";\nimport { AsyncAuthorizationRequest } from \"./AsyncAuthorizationRequest\";\nimport { AsyncAuthorizerParams } from \"./AsyncAuthorizerParams\";\nimport { asyncLocalStorage, AsyncStorageValue } from \"./asyncLocalStorage\";\n\nconst sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));\nfunction ensureOpenIdScope(scopes: string[]): string[] {\n return scopes.includes(\"openid\") ? scopes : [\"openid\", ...scopes];\n}\n/**\n * Requests authorization by prompting the user via an out-of-band channel from\n * the backend.\n */\nexport class AsyncAuthorizerBase<ToolExecuteArgs extends any[]> {\n private readonly auth0: AuthenticationClient;\n private readonly authResponseStore: SubStore | undefined;\n private readonly credentialsStore: SubStore<TokenSet> | undefined;\n\n private readonly params: RequireFields<\n AsyncAuthorizerParams<ToolExecuteArgs>,\n \"credentialsContext\"\n >;\n\n constructor(\n auth0: Partial<Auth0ClientParams>,\n params: AsyncAuthorizerParams<ToolExecuteArgs>\n ) {\n this.auth0 = new AuthenticationClient(Auth0ClientSchema.parse(auth0));\n this.params = {\n credentialsContext: \"tool-call\",\n ...params,\n };\n\n this.authResponseStore = new SubStore<AsyncAuthorizationRequest>(\n params.store,\n {\n getTTL: (authResponse) =>\n authResponse.expiresIn ? authResponse.expiresIn * 1000 : undefined,\n }\n );\n\n this.credentialsStore = new SubStore<TokenSet>(params.store, {\n getTTL: (credentials) =>\n credentials.expiresIn ? credentials.expiresIn * 1000 : undefined,\n });\n }\n\n private getInstanceID(authorizeParams: any): string {\n const props = {\n auth0: this.auth0,\n params: authorizeParams,\n };\n const sh = stableHash(props);\n return crypto.createHash(\"MD5\").update(sh).digest(\"hex\");\n }\n\n private async start(authorizeParams: any): Promise<AsyncAuthorizationRequest> {\n const requestedAt = Date.now() / 1000;\n\n try {\n const response = await this.auth0.backchannel.authorize(authorizeParams);\n\n return {\n id: response.auth_req_id,\n requestedAt: requestedAt,\n expiresIn: response.expires_in,\n interval: response.interval,\n };\n } catch (err: any) {\n if (err.error == \"invalid_request\") {\n throw new UserDoesNotHavePushNotificationsInterrupt(\n err.error_description\n );\n }\n throw err;\n }\n }\n\n private async getAuthorizeParams(toolContext: ToolExecuteArgs) {\n const authParams: Record<string, any> = {\n scope: ensureOpenIdScope(this.params.scopes).join(\" \"),\n audience: this.params.audience || \"\",\n requested_expiry: (this.params.requestedExpiry ?? 300).toString(),\n binding_message:\n (await resolveParameter(this.params.bindingMessage, toolContext)) ?? \"\",\n userId: (await resolveParameter(this.params.userID, toolContext)) ?? \"\",\n };\n\n const authorizationDetails = await resolveParameter(\n this.params.authorizationDetails,\n toolContext\n );\n\n // If authorizationDetails is an array, we need to convert it to a string\n // because the auth0 library expects a valid JSON string.\n if (authorizationDetails !== undefined) {\n authParams.authorization_details = JSON.stringify(authorizationDetails);\n }\n\n // Remove undefined values from the authParams object\n return Object.fromEntries(\n Object.entries(authParams).filter(([, value]) => value !== undefined)\n );\n }\n\n private async getCredentialsInternal(\n authRequest: AsyncAuthorizationRequest\n ): Promise<TokenSet | undefined> {\n try {\n const elapsedSeconds = Date.now() / 1000 - authRequest.requestedAt;\n\n if (elapsedSeconds >= authRequest.expiresIn) {\n throw new AuthorizationRequestExpiredInterrupt(\n \"The authorization request has expired.\",\n authRequest\n );\n }\n\n const response = await this.auth0.backchannel.backchannelGrant({\n auth_req_id: authRequest.id,\n });\n\n const credentials = tokenSetFromTokenResponse(response);\n\n return credentials;\n } catch (e: any) {\n if (e.error === \"authorization_pending\") {\n throw new AuthorizationPendingInterrupt(\n e.error_description,\n authRequest\n );\n }\n\n if (e.error === \"slow_down\") {\n throw new AuthorizationPollingInterrupt(\n e.error_description,\n authRequest,\n Number(e.headers.get('retry-after'))\n );\n }\n\n if (e.error == \"invalid_grant\") {\n throw new InvalidGrantInterrupt(e.error_description, authRequest);\n }\n\n if (e.error == \"invalid_request\") {\n throw new UserDoesNotHavePushNotificationsInterrupt(\n e.error_description\n );\n }\n\n if (e.error == \"access_denied\") {\n throw new AccessDeniedInterrupt(e.error_description, authRequest);\n }\n\n throw e;\n }\n }\n\n protected async getCredentials(authRequest: AsyncAuthorizationRequest) {\n return this.getCredentialsInternal(authRequest);\n }\n\n protected async getCredentialsPolling(\n authRequest: AsyncAuthorizationRequest\n ): Promise<TokenSet | undefined> {\n let credentials: TokenSet | undefined = undefined;\n\n do {\n try {\n credentials = await this.getCredentialsInternal(authRequest);\n } catch (err) {\n if (\n err instanceof AuthorizationPendingInterrupt ||\n err instanceof AuthorizationPollingInterrupt\n ) {\n await sleep(err.nextRetryInterval() * 1000);\n } else {\n throw err;\n }\n }\n } while (!credentials);\n\n return credentials;\n }\n\n protected deleteAuthRequest() {\n const store = asyncLocalStorage.getStore();\n if (!store) {\n throw new Error(\"This method should be called from within a tool.\");\n }\n const { authResponseNS } = store;\n return this.authResponseStore?.delete(authResponseNS, \"authResponse\");\n }\n\n /**\n *\n * Wraps the execute method of a AI tool to handle CIBA authorization.\n *\n * @param getContext - A function that returns the context of the tool execution.\n * @param execute - The tool execute method.\n * @returns The wrapped execute method.\n */\n protect(\n getContext: ContextGetter<ToolExecuteArgs>,\n execute: (...args: ToolExecuteArgs) => any\n ): (...args: ToolExecuteArgs) => any {\n return async (...args: ToolExecuteArgs) => {\n let authResponse: AsyncAuthorizationRequest | undefined;\n if (asyncLocalStorage.getStore()) {\n throw new Error(\n \"Cannot nest tool calls that require CIBA authorization.\"\n );\n }\n\n const context = getContext(...args);\n const authorizeParams = await this.getAuthorizeParams(args);\n const instanceID = this.getInstanceID(authorizeParams);\n const authResponseNS = [\n instanceID,\n \"AuthResponses\",\n ...nsFromContext(\"tool-call\", context),\n ];\n const credentialsNS = [\n instanceID,\n \"Credentials\",\n ...nsFromContext(this.params.credentialsContext, context),\n ];\n\n const storeValue: AsyncStorageValue<any> = {\n args,\n context,\n authResponseNS,\n };\n\n return asyncLocalStorage.run(storeValue, async () => {\n let credentials: TokenSet | undefined;\n\n const interruptMode =\n typeof this.params.onAuthorizationRequest === \"undefined\" ||\n this.params.onAuthorizationRequest === \"interrupt\";\n\n try {\n credentials = await this.credentialsStore?.get(\n credentialsNS,\n \"credential\"\n );\n if (!credentials) {\n if (interruptMode) {\n authResponse = await this.authResponseStore?.get(\n authResponseNS,\n \"authResponse\"\n );\n if (!authResponse) {\n //Initial request\n authResponse = await this.start(authorizeParams);\n await this.authResponseStore?.put(\n authResponseNS,\n \"authResponse\",\n authResponse\n );\n }\n credentials = await this.getCredentials(authResponse);\n } else {\n authResponse = await this.start(authorizeParams);\n const credentialsPromise =\n this.getCredentialsPolling(authResponse);\n if (typeof this.params.onAuthorizationRequest === \"function\") {\n await this.params.onAuthorizationRequest(\n authResponse,\n credentialsPromise\n );\n }\n credentials = await credentialsPromise;\n }\n await this.deleteAuthRequest();\n if (typeof credentials !== \"undefined\") {\n this.credentialsStore?.put(\n credentialsNS,\n \"credential\",\n credentials\n );\n }\n }\n } catch (err) {\n const shouldInterrupt =\n err instanceof AuthorizationPendingInterrupt ||\n err instanceof AuthorizationPollingInterrupt;\n if (shouldInterrupt) {\n return this.handleAuthorizationInterrupts(err);\n } else {\n await this.deleteAuthRequest();\n if (typeof this.params.onUnauthorized === \"function\") {\n return this.params.onUnauthorized(err as Error, ...args);\n } else {\n return err;\n }\n }\n }\n storeValue.credentials = credentials;\n return execute(...args);\n });\n };\n }\n\n protected async handleAuthorizationInterrupts(\n err: AuthorizationPendingInterrupt | AuthorizationPollingInterrupt\n ) {\n if (this.params.onAuthorizationInterrupt) {\n const store = asyncLocalStorage.getStore();\n if (!store) {\n throw new Error(\"This method should be called from within a tool.\");\n }\n const { context } = store;\n await this.params.onAuthorizationInterrupt(err, context);\n }\n throw err;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AsyncAuthorizerParams.js","sourceRoot":"","sources":["../../../../src/authorizers/async-authorization/AsyncAuthorizerParams.ts"],"names":[],"mappings":"","sourcesContent":["import { AuthorizationDetails, TokenSet } from \"../../credentials\";\nimport {\n AsyncAuthorizationInterrupt,\n AuthorizationPendingInterrupt,\n AuthorizationPollingInterrupt,\n} from \"../../interrupts\";\nimport { AuthorizerToolParameter } from \"../../parameters\";\nimport { Store } from \"../../stores\";\nimport { AuthContext, ToolCallContext } from \"../context\";\nimport { OnAuthorizationRequest } from \"../types\";\nimport { AsyncAuthorizationRequest } from \"./AsyncAuthorizationRequest\";\n\nexport type AsyncAuthorizerParams<ToolExecuteArgs extends any[]> = {\n /**\n * The scope to request authorization for.\n */\n scopes: string[];\n\n /**\n * The user ID to request authorization for.\n */\n userID: AuthorizerToolParameter<ToolExecuteArgs>;\n\n /**\n * The binding message to send to the user.\n */\n bindingMessage: AuthorizerToolParameter<ToolExecuteArgs>;\n\n /**\n * The authorization parameters for RAR request.\n */\n authorizationDetails?: AuthorizerToolParameter<\n ToolExecuteArgs,\n AuthorizationDetails[]\n >;\n\n /**\n * The audience to request authorization for.\n */\n audience?: string;\n\n /**\n * The time in seconds for the authorization request to expire.\n *\n * Defaults to 300 (5 minutes).\n */\n requestedExpiry?: number;\n\n /**\n * The behavior when the authorization request is made.\n *\n * - `block`: The tool execution is blocked until the user completes the authorization.\n * - `interrupt`: The tool execution is interrupted until the user completes the authorization.\n * - a callback: Same as \"block\" but give access to the auth request and executing logic.\n *\n * Defaults to `interrupt`.\n * Note: The block mode is only useful for development purposes and should not be used in production.\n */\n onAuthorizationRequest?:\n | OnAuthorizationRequest\n | ((\n authReq: AsyncAuthorizationRequest,\n poll: Promise<TokenSet | undefined>\n ) => Promise<void>);\n\n /**\n * AuthContext defines the scope of credential sharing:\n * - \"tool-call\": Credentials are valid only for a single invocation of the tool.\n * - \"tool\": Credentials are shared across multiple calls to the same tool within the same thread.\n * - \"thread\": Credentials are shared across all tools using the same authorizer within the current thread.\n * - \"agent\": Credentials are shared globally across all threads and tools in the agent.\n *\n * @default \"tool-call\"\n */\n credentialsContext?: AuthContext;\n\n /**\n *\n * Optional callback to generate a tool result when the invocation is not authorized.\n *\n * By default it will return the instance of the Error.\n *\n * @param args - The tool execution arguments.\n * @returns The response to return when the invocation is not authorized.\n */\n onUnauthorized?: (\n err: Error | AsyncAuthorizationInterrupt,\n ...args: ToolExecuteArgs\n ) => any;\n\n /**\n * Callback called before the authorization interrupt is thrown.\n * This callback is useful to setup CIBA pollers.\n *\n * @param interrupt - The interrupt that is about to be thrown.\n * @param args - The tool execution arguments.\n */\n onAuthorizationInterrupt?: (\n interrupt: AuthorizationPendingInterrupt | AuthorizationPollingInterrupt,\n context: ToolCallContext,\n ) => void | Promise<void>;\n\n /**\n * An store used to temporarly store the authorization response data\n * while the user is completing the authorization in another device.\n */\n store: Store;\n};\n"]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getAsyncAuthorizationCredentials = exports.asyncLocalStorage = void 0;
|
|
4
4
|
const async_hooks_1 = require("async_hooks");
|
|
5
5
|
exports.asyncLocalStorage = new async_hooks_1.AsyncLocalStorage();
|
|
6
|
-
const
|
|
6
|
+
const getAsyncAuthorizationCredentials = () => {
|
|
7
7
|
const t = exports.asyncLocalStorage.getStore();
|
|
8
8
|
if (typeof t === "undefined") {
|
|
9
|
-
throw new Error("The tool must be wrapped with the
|
|
9
|
+
throw new Error("The tool must be wrapped with the withAsyncAuthorization function.");
|
|
10
10
|
}
|
|
11
11
|
return t.credentials;
|
|
12
12
|
};
|
|
13
|
-
exports.
|
|
13
|
+
exports.getAsyncAuthorizationCredentials = getAsyncAuthorizationCredentials;
|
|
14
14
|
//# sourceMappingURL=asyncLocalStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asyncLocalStorage.js","sourceRoot":"","sources":["../../../../src/authorizers/async-authorization/asyncLocalStorage.ts"],"names":[],"mappings":";;;AAAA,6CAAgD;AAuBnC,QAAA,iBAAiB,GAAG,IAAI,+BAAiB,EAEnD,CAAC;AAEG,MAAM,gCAAgC,GAAG,GAAG,EAAE;IACnD,MAAM,CAAC,GAAG,yBAAiB,CAAC,QAAQ,EAAE,CAAC;IACvC,IAAI,OAAO,CAAC,KAAK,WAAW,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;IACJ,CAAC;IACD,OAAO,CAAC,CAAC,WAAW,CAAC;AACvB,CAAC,CAAC;AARW,QAAA,gCAAgC,oCAQ3C","sourcesContent":["import { AsyncLocalStorage } from \"async_hooks\";\n\nimport { TokenSet } from \"../../credentials\";\n\nexport type AsyncStorageValue<TContext> = {\n credentials?: TokenSet;\n\n /**\n * The tool execution context.\n */\n context: TContext;\n\n /**\n * The tool execution arguments.\n */\n args: any[];\n\n /**\n * The namespace in the Store for the CIBA authorization response.\n */\n authResponseNS: string[];\n};\n\nexport const asyncLocalStorage = new AsyncLocalStorage<\n AsyncStorageValue<any>\n>();\n\nexport const getAsyncAuthorizationCredentials = () => {\n const t = asyncLocalStorage.getStore();\n if (typeof t === \"undefined\") {\n throw new Error(\n \"The tool must be wrapped with the withAsyncAuthorization function.\"\n );\n }\n return t.credentials;\n};\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AsyncAuthorizerBase = exports.getAsyncAuthorizationCredentials = exports.asyncLocalStorage = void 0;
|
|
4
|
+
var asyncLocalStorage_1 = require("./asyncLocalStorage");
|
|
5
|
+
Object.defineProperty(exports, "asyncLocalStorage", { enumerable: true, get: function () { return asyncLocalStorage_1.asyncLocalStorage; } });
|
|
6
|
+
Object.defineProperty(exports, "getAsyncAuthorizationCredentials", { enumerable: true, get: function () { return asyncLocalStorage_1.getAsyncAuthorizationCredentials; } });
|
|
7
|
+
var AsyncAuthorizerBase_1 = require("./AsyncAuthorizerBase");
|
|
8
|
+
Object.defineProperty(exports, "AsyncAuthorizerBase", { enumerable: true, get: function () { return AsyncAuthorizerBase_1.AsyncAuthorizerBase; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/authorizers/async-authorization/index.ts"],"names":[],"mappings":";;;AAAA,yDAA0F;AAAjF,sHAAA,iBAAiB,OAAA;AAAE,qIAAA,gCAAgC,OAAA;AAI5D,6DAA4D;AAAnD,0HAAA,mBAAmB,OAAA","sourcesContent":["export { asyncLocalStorage, getAsyncAuthorizationCredentials } from \"./asyncLocalStorage\";\n\nexport type { AsyncAuthorizationRequest } from \"./AsyncAuthorizationRequest\";\n\nexport { AsyncAuthorizerBase } from \"./AsyncAuthorizerBase\";\n"]}
|
|
@@ -6,7 +6,7 @@ exports.asyncLocalStorage = new async_hooks_1.AsyncLocalStorage();
|
|
|
6
6
|
const getDeviceAuthorizerCredentials = () => {
|
|
7
7
|
const t = exports.asyncLocalStorage.getStore();
|
|
8
8
|
if (typeof t === "undefined") {
|
|
9
|
-
throw new Error("The tool must be wrapped with the
|
|
9
|
+
throw new Error("The tool must be wrapped with the withAsyncAuthorization function.");
|
|
10
10
|
}
|
|
11
11
|
return t.credentials;
|
|
12
12
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asyncLocalStorage.js","sourceRoot":"","sources":["../../../../src/authorizers/device-authorizer/asyncLocalStorage.ts"],"names":[],"mappings":";;;AAAA,6CAAgD;AAkBnC,QAAA,iBAAiB,GAAG,IAAI,+BAAiB,EAEnD,CAAC;AAEG,MAAM,8BAA8B,GAAG,GAAG,EAAE;IACjD,MAAM,CAAC,GAAG,yBAAiB,CAAC,QAAQ,EAAE,CAAC;IACvC,IAAI,OAAO,CAAC,KAAK,WAAW,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CACb,
|
|
1
|
+
{"version":3,"file":"asyncLocalStorage.js","sourceRoot":"","sources":["../../../../src/authorizers/device-authorizer/asyncLocalStorage.ts"],"names":[],"mappings":";;;AAAA,6CAAgD;AAkBnC,QAAA,iBAAiB,GAAG,IAAI,+BAAiB,EAEnD,CAAC;AAEG,MAAM,8BAA8B,GAAG,GAAG,EAAE;IACjD,MAAM,CAAC,GAAG,yBAAiB,CAAC,QAAQ,EAAE,CAAC;IACvC,IAAI,OAAO,CAAC,KAAK,WAAW,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CACb,oEAAoE,CACrE,CAAC;IACJ,CAAC;IACD,OAAO,CAAC,CAAC,WAAW,CAAC;AACvB,CAAC,CAAC;AARW,QAAA,8BAA8B,kCAQzC","sourcesContent":["import { AsyncLocalStorage } from \"async_hooks\";\n\nimport { TokenSet } from \"../../credentials\";\n\nexport type AsyncStorageValue<TContext> = {\n credentials?: TokenSet;\n\n /**\n * The tool execution context.\n */\n context: TContext;\n\n /**\n * The tool execution arguments.\n */\n args: any[];\n};\n\nexport const asyncLocalStorage = new AsyncLocalStorage<\n AsyncStorageValue<any>\n>();\n\nexport const getDeviceAuthorizerCredentials = () => {\n const t = asyncLocalStorage.getStore();\n if (typeof t === \"undefined\") {\n throw new Error(\n \"The tool must be wrapped with the withAsyncAuthorization function.\"\n );\n }\n return t.credentials;\n};\n"]}
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.TokenVaultAuthorizerBase = void 0;
|
|
7
7
|
const crypto_1 = __importDefault(require("crypto"));
|
|
8
8
|
const stable_hash_1 = __importDefault(require("stable-hash"));
|
|
9
9
|
const credentials_1 = require("../../credentials");
|
|
@@ -14,11 +14,11 @@ const util_1 = require("../../util");
|
|
|
14
14
|
const context_1 = require("../context");
|
|
15
15
|
const types_1 = require("../types");
|
|
16
16
|
const asyncLocalStorage_1 = require("./asyncLocalStorage");
|
|
17
|
-
const
|
|
17
|
+
const TokenVaultAuthorizerParams_1 = require("./TokenVaultAuthorizerParams");
|
|
18
18
|
/**
|
|
19
|
-
* Requests authorization to a third party service via
|
|
19
|
+
* Requests authorization to a third party service via Token Vault.
|
|
20
20
|
*/
|
|
21
|
-
class
|
|
21
|
+
class TokenVaultAuthorizerBase {
|
|
22
22
|
constructor(auth0, params) {
|
|
23
23
|
this.auth0 = types_1.Auth0ClientSchema.parse(auth0);
|
|
24
24
|
this.params = {
|
|
@@ -43,7 +43,7 @@ class FederatedConnectionAuthorizerBase {
|
|
|
43
43
|
// Validate resource server client credentials when using access tokens for token exchange w/ Token Vault
|
|
44
44
|
if (hasAccessToken &&
|
|
45
45
|
hasSubjectTokenType &&
|
|
46
|
-
params.subjectTokenType ===
|
|
46
|
+
params.subjectTokenType === TokenVaultAuthorizerParams_1.SUBJECT_TOKEN_TYPES.SUBJECT_TYPE_ACCESS_TOKEN) {
|
|
47
47
|
if (!this.auth0.clientId || !this.auth0.clientSecret) {
|
|
48
48
|
throw new Error("clientId and clientSecret must currently be provided when using accessToken for token exchange with Token Vault.");
|
|
49
49
|
}
|
|
@@ -73,7 +73,7 @@ class FederatedConnectionAuthorizerBase {
|
|
|
73
73
|
}
|
|
74
74
|
const { scopes, connection } = store;
|
|
75
75
|
if (!tokenResponse) {
|
|
76
|
-
throw new interrupts_1.
|
|
76
|
+
throw new interrupts_1.TokenVaultInterrupt(`Authorization required to access the Token Vault: ${this.params.connection}`, connection, scopes, scopes);
|
|
77
77
|
}
|
|
78
78
|
const currentScopes = ((_a = tokenResponse.scope) !== null && _a !== void 0 ? _a : "")
|
|
79
79
|
.replace(/,/g, " ")
|
|
@@ -81,7 +81,7 @@ class FederatedConnectionAuthorizerBase {
|
|
|
81
81
|
const missingScopes = scopes.filter((s) => !currentScopes.includes(s));
|
|
82
82
|
store.currentScopes = currentScopes;
|
|
83
83
|
if (missingScopes.length > 0) {
|
|
84
|
-
throw new interrupts_1.
|
|
84
|
+
throw new interrupts_1.TokenVaultInterrupt(`Authorization required to access the Token Vault: ${this.params.connection}. Missing scopes: ${missingScopes.join(", ")}`, connection, scopes, [...currentScopes, ...scopes]);
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
async getAccessTokenImpl(...toolContext) {
|
|
@@ -144,7 +144,7 @@ class FederatedConnectionAuthorizerBase {
|
|
|
144
144
|
if (typeof this.params.refreshToken === "function" ||
|
|
145
145
|
(typeof this.params.accessToken !== "undefined" &&
|
|
146
146
|
this.params.subjectTokenType ===
|
|
147
|
-
|
|
147
|
+
TokenVaultAuthorizerParams_1.SUBJECT_TOKEN_TYPES.SUBJECT_TYPE_ACCESS_TOKEN)) {
|
|
148
148
|
tokenResponse = await this.getAccessTokenImpl(...toolContext);
|
|
149
149
|
}
|
|
150
150
|
else {
|
|
@@ -162,7 +162,7 @@ class FederatedConnectionAuthorizerBase {
|
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
164
|
*
|
|
165
|
-
* Wraps the execute method of an AI tool to handle
|
|
165
|
+
* Wraps the execute method of an AI tool to handle Token Vaults authorization.
|
|
166
166
|
*
|
|
167
167
|
* @param getContext - A function that returns the context of the tool execution.
|
|
168
168
|
* @param execute - The tool execute method.
|
|
@@ -177,7 +177,7 @@ class FederatedConnectionAuthorizerBase {
|
|
|
177
177
|
connection: this.params.connection,
|
|
178
178
|
};
|
|
179
179
|
if (asyncLocalStorage_1.asyncLocalStorage.getStore()) {
|
|
180
|
-
throw new Error("Cannot nest tool calls that require
|
|
180
|
+
throw new Error("Cannot nest tool calls that require Token Vault authorization.");
|
|
181
181
|
}
|
|
182
182
|
return asyncLocalStorage_1.asyncLocalStorage.run(asyncStore, async () => {
|
|
183
183
|
const credentialsNS = (0, context_1.nsFromContext)(this.params.credentialsContext, context);
|
|
@@ -191,9 +191,9 @@ class FederatedConnectionAuthorizerBase {
|
|
|
191
191
|
return await execute(...args);
|
|
192
192
|
}
|
|
193
193
|
catch (err) {
|
|
194
|
-
if (err instanceof interrupts_1.
|
|
194
|
+
if (err instanceof interrupts_1.TokenVaultError) {
|
|
195
195
|
this.credentialsStore.delete(credentialsNS, "credential");
|
|
196
|
-
const interrupt = new interrupts_1.
|
|
196
|
+
const interrupt = new interrupts_1.TokenVaultInterrupt(err.message, asyncStore.connection, asyncStore.scopes, asyncStore.scopes);
|
|
197
197
|
return this.handleAuthorizationInterrupts(interrupt);
|
|
198
198
|
}
|
|
199
199
|
if (err instanceof interrupts_1.Auth0Interrupt) {
|
|
@@ -206,5 +206,5 @@ class FederatedConnectionAuthorizerBase {
|
|
|
206
206
|
};
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
|
-
exports.
|
|
210
|
-
//# sourceMappingURL=
|
|
209
|
+
exports.TokenVaultAuthorizerBase = TokenVaultAuthorizerBase;
|
|
210
|
+
//# sourceMappingURL=TokenVaultAuthorizerBase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenVaultAuthorizerBase.js","sourceRoot":"","sources":["../../../../src/authorizers/token-vault/TokenVaultAuthorizerBase.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,8DAAqC;AAErC,mDAAuF;AACvF,iDAAwF;AACxF,iDAAoD;AACpD,yCAAwC;AACxC,qCAAiD;AACjD,wCAA0D;AAC1D,oCAAgE;AAChE,2DAA2E;AAC3E,6EAA+F;AAE/F;;GAEG;AAEH,MAAa,wBAAwB;IAQnC,YACE,KAAiC,EACjC,MAAmD;QAEnD,IAAI,CAAC,KAAK,GAAG,yBAAiB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM,GAAG;YACZ,kBAAkB,EAAE,QAAQ;YAC5B,GAAG,MAAM;SACV,CAAC;QAEF,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,EAAE,CAAC;QAExC,IAAI,CAAC,gBAAgB,GAAG,IAAI,iBAAQ,C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AAG,IAAI,CAAC,CAAC;wBACjD,MAAM,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAC7B,aAAa,EACb,YAAY,EACZ,WAAW,CACZ,CAAC;oBACJ,CAAC;oBACD,UAAU,CAAC,WAAW,GAAG,WAAW,CAAC;oBACrC,OAAO,MAAM,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;gBAChC,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,IAAI,GAAG,YAAY,4BAAe,EAAE,CAAC;wBACnC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;wBAC1D,MAAM,SAAS,GAAG,IAAI,gCAAmB,CACvC,GAAG,CAAC,OAAO,EACX,UAAU,CAAC,UAAU,EACrB,UAAU,CAAC,MAAM,EACjB,UAAU,CAAC,MAAM,CAClB,CAAC;wBACF,OAAO,IAAI,CAAC,6BAA6B,CAAC,SAAS,CAAC,CAAC;oBACvD,CAAC;oBACD,IAAI,GAAG,YAAY,2BAAc,EAAE,CAAC;wBAClC,IAAI,CAAC,gBAAgB,CAAC,MAAM,CAAC,aAAa,EAAE,YAAY,CAAC,CAAC;wBAC1D,OAAO,IAAI,CAAC,6BAA6B,CAAC,GAAG,CAAC,CAAC;oBACjD,CAAC;oBACD,MAAM,GAAG,CAAC;gBACZ,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;IACJ,CAAC;CACF;AAvRD,4DAuRC","sourcesContent":["import crypto from \"crypto\";\nimport stableHash from \"stable-hash\";\n\nimport { TokenResponse, TokenSet, tokenSetFromTokenResponse } from \"../../credentials\";\nimport { Auth0Interrupt, TokenVaultError, TokenVaultInterrupt } from \"../../interrupts\";\nimport { resolveParameter } from \"../../parameters\";\nimport { SubStore } from \"../../stores\";\nimport { omit, RequireFields } from \"../../util\";\nimport { ContextGetter, nsFromContext } from \"../context\";\nimport { Auth0ClientParams, Auth0ClientSchema } from \"../types\";\nimport { asyncLocalStorage, AsyncStorageValue } from \"./asyncLocalStorage\";\nimport { SUBJECT_TOKEN_TYPES, TokenVaultAuthorizerParams } from \"./TokenVaultAuthorizerParams\";\n\n/**\n * Requests authorization to a third party service via Token Vault.\n */\n\nexport class TokenVaultAuthorizerBase<ToolExecuteArgs extends any[]> {\n private readonly auth0: Auth0ClientParams;\n private readonly params: RequireFields<\n TokenVaultAuthorizerParams<ToolExecuteArgs>,\n \"credentialsContext\"\n >;\n private readonly credentialsStore: SubStore<TokenSet>;\n\n constructor(\n auth0: Partial<Auth0ClientParams>,\n params: TokenVaultAuthorizerParams<ToolExecuteArgs>\n ) {\n this.auth0 = Auth0ClientSchema.parse(auth0);\n this.params = {\n credentialsContext: \"thread\",\n ...params,\n };\n\n const instanceID = this.getInstanceID();\n\n this.credentialsStore = new SubStore<TokenSet>(params.store, {\n baseNamespace: [instanceID, \"Credentials\"],\n getTTL: (credentials) =>\n credentials.expiresIn ? credentials.expiresIn * 1000 : undefined,\n });\n\n // Validate that exactly one token source is provided\n const hasRefreshToken = typeof params.refreshToken !== \"undefined\";\n const hasAccessToken = typeof params.accessToken !== \"undefined\";\n const hasSubjectTokenType = typeof params.subjectTokenType !== \"undefined\";\n\n if (!hasRefreshToken && !hasAccessToken) {\n throw new Error(\n \"Either refreshToken or accessToken must be provided to initialize the Authorizer.\"\n );\n }\n\n if (hasRefreshToken && hasAccessToken) {\n throw new Error(\n \"Only one of refreshToken or accessToken can be provided to initialize the Authorizer.\"\n );\n }\n\n // Validate resource server client credentials when using access tokens for token exchange w/ Token Vault\n if (\n hasAccessToken &&\n hasSubjectTokenType &&\n params.subjectTokenType === SUBJECT_TOKEN_TYPES.SUBJECT_TYPE_ACCESS_TOKEN\n ) {\n if (!this.auth0.clientId || !this.auth0.clientSecret) {\n throw new Error(\n \"clientId and clientSecret must currently be provided when using accessToken for token exchange with Token Vault.\"\n );\n }\n }\n }\n\n private getInstanceID(): string {\n const props = {\n auth0: this.auth0,\n params: omit(this.params, [\n \"store\",\n \"refreshToken\",\n \"accessToken\",\n \"loginHint\",\n ]),\n };\n const sh = stableHash(props);\n return crypto.createHash(\"MD5\").update(sh).digest(\"hex\");\n }\n\n protected handleAuthorizationInterrupts(err: Auth0Interrupt) {\n throw err;\n }\n\n protected validateToken(tokenResponse?: TokenResponse) {\n const store = asyncLocalStorage.getStore();\n if (!store) {\n throw new Error(\n \"The tool must be wrapped with the FederationConnectionAuthorizer.\"\n );\n }\n\n const { scopes, connection } = store;\n\n if (!tokenResponse) {\n throw new TokenVaultInterrupt(\n `Authorization required to access the Token Vault: ${this.params.connection}`,\n connection,\n scopes,\n scopes\n );\n }\n\n const currentScopes = (tokenResponse.scope ?? \"\")\n .replace(/,/g, \" \")\n .split(\" \");\n const missingScopes = scopes.filter((s) => !currentScopes.includes(s));\n store.currentScopes = currentScopes;\n\n if (missingScopes.length > 0) {\n throw new TokenVaultInterrupt(\n `Authorization required to access the Token Vault: ${this.params.connection}. Missing scopes: ${missingScopes.join(\", \")}`,\n connection,\n scopes,\n [...currentScopes, ...scopes]\n );\n }\n }\n\n private async getAccessTokenImpl(\n ...toolContext: ToolExecuteArgs\n ): Promise<TokenResponse | undefined> {\n const store = asyncLocalStorage.getStore();\n if (!store) {\n throw new Error(\n \"The tool must be wrapped with the FederationConnectionAuthorizer.\"\n );\n }\n\n const { connection } = store;\n\n // Determine which token type to use and get the appropriate subject token\n let subjectToken: string | undefined;\n let subjectTokenType: string;\n\n if (typeof this.params.refreshToken === \"function\") {\n subjectToken = await this.getRefreshToken(...toolContext);\n subjectTokenType = \"urn:ietf:params:oauth:token-type:refresh_token\";\n } else if (typeof this.params.accessToken === \"function\") {\n subjectToken = (await this.getAccessTokenWithToolContext(\n ...toolContext\n )) as string;\n subjectTokenType = \"urn:ietf:params:oauth:token-type:access_token\";\n } else if (typeof this.params.accessToken === \"string\") {\n subjectToken = this.params.accessToken;\n subjectTokenType = \"urn:ietf:params:oauth:token-type:access_token\";\n } else {\n // This should never happen due to constructor validation, but TypeScript needs this\n throw new Error(\"Either refreshToken or accessToken must be configured\");\n }\n\n if (!subjectToken) {\n return;\n }\n\n // Get optional login hint if provided\n const loginHint =\n typeof this.params.loginHint === \"function\"\n ? await resolveParameter(this.params.loginHint, toolContext)\n : undefined;\n\n const exchangeParams = {\n grant_type:\n \"urn:auth0:params:oauth:grant-type:token-exchange:federated-connection-access-token\",\n client_id: this.auth0.clientId,\n client_secret: this.auth0.clientSecret,\n subject_token_type: subjectTokenType,\n subject_token: subjectToken,\n login_hint: loginHint,\n connection: connection,\n requested_token_type:\n \"http://auth0.com/oauth/token-type/federated-connection-access-token\",\n };\n\n const res = await fetch(`https://${this.auth0.domain}/oauth/token`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(exchangeParams),\n });\n\n if (!res.ok) {\n //TODO: handle all type of response errors.\n return;\n }\n\n const tokenResponse: TokenResponse = await res.json();\n return tokenResponse;\n }\n\n protected async getAccessToken(\n ...toolContext: ToolExecuteArgs\n ): Promise<TokenSet> {\n let tokenResponse: TokenResponse | undefined;\n // Use token exchange for both refresh tokens and access tokens when subjectTokenType is provided\n if (\n typeof this.params.refreshToken === \"function\" ||\n (typeof this.params.accessToken !== \"undefined\" &&\n this.params.subjectTokenType ===\n SUBJECT_TOKEN_TYPES.SUBJECT_TYPE_ACCESS_TOKEN)\n ) {\n tokenResponse = await this.getAccessTokenImpl(...toolContext);\n } else {\n // fallback to existing behavior, where third party accessToken can be provided directly\n tokenResponse = (await resolveParameter(\n this.params.accessToken!,\n toolContext\n )) as TokenResponse;\n }\n this.validateToken(tokenResponse);\n return tokenSetFromTokenResponse(tokenResponse!);\n }\n\n protected async getRefreshToken(...toolContext: ToolExecuteArgs) {\n return await resolveParameter(this.params.refreshToken, toolContext);\n }\n\n protected async getAccessTokenWithToolContext(\n ...toolContext: ToolExecuteArgs\n ) {\n return await resolveParameter(this.params.accessToken, toolContext);\n }\n\n /**\n *\n * Wraps the execute method of an AI tool to handle Token Vaults authorization.\n *\n * @param getContext - A function that returns the context of the tool execution.\n * @param execute - The tool execute method.\n * @returns The wrapped execute method.\n */\n protect(\n getContext: ContextGetter<ToolExecuteArgs>,\n execute: (...args: ToolExecuteArgs) => any\n ): (...args: ToolExecuteArgs) => any {\n return async (...args: ToolExecuteArgs) => {\n const context = getContext(...args);\n const asyncStore: AsyncStorageValue = {\n context: context,\n scopes: this.params.scopes,\n connection: this.params.connection,\n };\n\n if (asyncLocalStorage.getStore()) {\n throw new Error(\n \"Cannot nest tool calls that require Token Vault authorization.\"\n );\n }\n\n return asyncLocalStorage.run(asyncStore, async () => {\n const credentialsNS = nsFromContext(\n this.params.credentialsContext,\n context\n );\n try {\n let credentials: TokenSet = await this.credentialsStore.get(\n credentialsNS,\n \"credential\"\n );\n if (!credentials) {\n credentials = await this.getAccessToken(...args);\n await this.credentialsStore.put(\n credentialsNS,\n \"credential\",\n credentials\n );\n }\n asyncStore.credentials = credentials;\n return await execute(...args);\n } catch (err) {\n if (err instanceof TokenVaultError) {\n this.credentialsStore.delete(credentialsNS, \"credential\");\n const interrupt = new TokenVaultInterrupt(\n err.message,\n asyncStore.connection,\n asyncStore.scopes,\n asyncStore.scopes\n );\n return this.handleAuthorizationInterrupts(interrupt);\n }\n if (err instanceof Auth0Interrupt) {\n this.credentialsStore.delete(credentialsNS, \"credential\");\n return this.handleAuthorizationInterrupts(err);\n }\n throw err;\n }\n });\n };\n }\n}\n"]}
|
|
@@ -16,4 +16,4 @@ var SUBJECT_TOKEN_TYPES;
|
|
|
16
16
|
*/
|
|
17
17
|
SUBJECT_TOKEN_TYPES["SUBJECT_TYPE_ACCESS_TOKEN"] = "urn:ietf:params:oauth:token-type:access_token";
|
|
18
18
|
})(SUBJECT_TOKEN_TYPES || (exports.SUBJECT_TOKEN_TYPES = SUBJECT_TOKEN_TYPES = {}));
|
|
19
|
-
//# sourceMappingURL=
|
|
19
|
+
//# sourceMappingURL=TokenVaultAuthorizerParams.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenVaultAuthorizerParams.js","sourceRoot":"","sources":["../../../../src/authorizers/token-vault/TokenVaultAuthorizerParams.ts"],"names":[],"mappings":";;;AAKA,IAAY,mBAcX;AAdD,WAAY,mBAAmB;IAC7B;;;;OAIG;IACH,oGAA6E,CAAA;IAE7E;;;;OAIG;IACH,kGAA2E,CAAA;AAC7E,CAAC,EAdW,mBAAmB,mCAAnB,mBAAmB,QAc9B","sourcesContent":["import { TokenResponse } from \"../../credentials\";\nimport { AuthorizerToolParameter } from \"../../parameters\";\nimport { Store } from \"../../stores\";\nimport { AuthContext } from \"../context\";\n\nexport enum SUBJECT_TOKEN_TYPES {\n /**\n * Indicates that the token is an OAuth 2.0 refresh token issued by the given authorization server.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc8693#section-3-3.4 RFC 8693 Section 3-3.4}\n */\n SUBJECT_TYPE_REFRESH_TOKEN = \"urn:ietf:params:oauth:token-type:refresh_token\",\n\n /**\n * Indicates that the token is an OAuth 2.0 access token issued by the given authorization server.\n *\n * @see {@link https://datatracker.ietf.org/doc/html/rfc8693#section-3-3.2 RFC 8693 Section 3-3.2}\n */\n SUBJECT_TYPE_ACCESS_TOKEN = \"urn:ietf:params:oauth:token-type:access_token\",\n}\n\nexport type TokenVaultAuthorizerParams<ToolExecuteArgs extends any[]> =\n {\n /**\n * The Auth0 refresh token to exchange for an Token Vault access token.\n */\n refreshToken?: AuthorizerToolParameter<ToolExecuteArgs, string | undefined>;\n\n /**\n * The Token Vault access token if available in the tool context.\n * This can also be provided as a string exchange when exchanging an access token for a Token Vault access token.\n */\n accessToken?:\n | AuthorizerToolParameter<\n ToolExecuteArgs,\n TokenResponse | string | undefined\n >\n | string\n | undefined;\n\n /**\n * This is used to specify the type of token being requested from Auth0 during the OAuth 2.0 token exchange request.\n */\n subjectTokenType?: SUBJECT_TOKEN_TYPES | undefined;\n\n /**\n * Optional login hint to provide when exchanging an access or refresh token for a Token Vault access token.\n */\n loginHint?: AuthorizerToolParameter<ToolExecuteArgs, string | undefined>;\n\n /**\n * The scopes required in the access token of the token vault provider.\n */\n scopes: string[];\n\n /**\n * The connection name of the token vault provider.\n */\n connection: string;\n\n /**\n * AuthContext defines the scope of credential sharing:\n * - \"tool-call\": Credentials are valid only for a single invocation of the tool.\n * - \"tool\": Credentials are shared across multiple calls to the same tool within the same thread.\n * - \"thread\": Credentials are shared across all tools using the same authorizer within the current thread.\n * - \"agent\": Credentials are shared globally across all threads and tools in the agent.\n *\n * @default \"thread\"\n */\n credentialsContext?: AuthContext;\n\n /**\n * An store used to store the authorization credentials according\n * to the `credentialsContext` scope.\n */\n store: Store;\n };\n"]}
|
|
@@ -1,36 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getAccessTokenFromTokenVault = exports.getCredentialsFromTokenVault = exports.asyncLocalStorage = void 0;
|
|
4
4
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
5
5
|
const interrupts_1 = require("../../interrupts");
|
|
6
6
|
exports.asyncLocalStorage = new node_async_hooks_1.AsyncLocalStorage();
|
|
7
7
|
/**
|
|
8
8
|
* Returns the entire tokenset for the current connection.
|
|
9
9
|
*
|
|
10
|
-
* Use `
|
|
10
|
+
* Use `getAccessTokenFromTokenVault` if you only need the access token.
|
|
11
11
|
*
|
|
12
12
|
* @returns {TokenSet} The current token set.
|
|
13
13
|
*/
|
|
14
|
-
const
|
|
14
|
+
const getCredentialsFromTokenVault = () => {
|
|
15
15
|
const store = exports.asyncLocalStorage.getStore();
|
|
16
16
|
if (typeof store === "undefined") {
|
|
17
|
-
throw new Error("The tool must be wrapped with the
|
|
17
|
+
throw new Error("The tool must be wrapped with the withTokenVault function.");
|
|
18
18
|
}
|
|
19
19
|
return store === null || store === void 0 ? void 0 : store.credentials;
|
|
20
20
|
};
|
|
21
|
-
exports.
|
|
21
|
+
exports.getCredentialsFromTokenVault = getCredentialsFromTokenVault;
|
|
22
22
|
/**
|
|
23
23
|
*
|
|
24
24
|
* Get the access token for the current connection.
|
|
25
25
|
*
|
|
26
26
|
* @returns The access token for the current connection.
|
|
27
27
|
*/
|
|
28
|
-
const
|
|
29
|
-
const credentials = (0, exports.
|
|
28
|
+
const getAccessTokenFromTokenVault = () => {
|
|
29
|
+
const credentials = (0, exports.getCredentialsFromTokenVault)();
|
|
30
30
|
if (!credentials || !credentials.accessToken) {
|
|
31
|
-
throw new interrupts_1.
|
|
31
|
+
throw new interrupts_1.TokenVaultError("No credentials found");
|
|
32
32
|
}
|
|
33
33
|
return credentials.accessToken;
|
|
34
34
|
};
|
|
35
|
-
exports.
|
|
35
|
+
exports.getAccessTokenFromTokenVault = getAccessTokenFromTokenVault;
|
|
36
36
|
//# sourceMappingURL=asyncLocalStorage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asyncLocalStorage.js","sourceRoot":"","sources":["../../../../src/authorizers/token-vault/asyncLocalStorage.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;AAGrD,iDAAmD;AA8BtC,QAAA,iBAAiB,GAAG,IAAI,oCAAiB,EAAqB,CAAC;AAE5E;;;;;;GAMG;AACI,MAAM,4BAA4B,GAAG,GAAG,EAAE;IAC/C,MAAM,KAAK,GAAG,yBAAiB,CAAC,QAAQ,EAAE,CAAC;IAC3C,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CACb,4DAA4D,CAC7D,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,WAAW,CAAC;AAC5B,CAAC,CAAC;AARW,QAAA,4BAA4B,gCAQvC;AAEF;;;;;GAKG;AACI,MAAM,4BAA4B,GAAG,GAAG,EAAE;IAC/C,MAAM,WAAW,GAAG,IAAA,oCAA4B,GAAE,CAAC;IACnD,IAAI,CAAC,WAAW,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,CAAC;QAC7C,MAAM,IAAI,4BAAe,CAAC,sBAAsB,CAAC,CAAC;IACpD,CAAC;IACD,OAAO,WAAW,CAAC,WAAW,CAAC;AACjC,CAAC,CAAC;AANW,QAAA,4BAA4B,gCAMvC","sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport { TokenSet } from \"../../credentials\";\nimport { TokenVaultError } from \"../../interrupts\";\nimport { ToolCallContext } from \"../context\";\n\nexport type AsyncStorageValue = {\n /**\n * The Token Vault access token.\n */\n credentials?: TokenSet;\n\n /**\n * The tool execution context.\n */\n context: ToolCallContext;\n\n /**\n * The token vault name.\n */\n connection: string;\n\n /**\n * The scopes required to access the token vault.\n */\n scopes: string[];\n\n /**\n * The scopes that the current access token has.\n */\n currentScopes?: string[];\n};\n\nexport const asyncLocalStorage = new AsyncLocalStorage<AsyncStorageValue>();\n\n/**\n * Returns the entire tokenset for the current connection.\n *\n * Use `getAccessTokenFromTokenVault` if you only need the access token.\n *\n * @returns {TokenSet} The current token set.\n */\nexport const getCredentialsFromTokenVault = () => {\n const store = asyncLocalStorage.getStore();\n if (typeof store === \"undefined\") {\n throw new Error(\n \"The tool must be wrapped with the withTokenVault function.\"\n );\n }\n return store?.credentials;\n};\n\n/**\n *\n * Get the access token for the current connection.\n *\n * @returns The access token for the current connection.\n */\nexport const getAccessTokenFromTokenVault = () => {\n const credentials = getCredentialsFromTokenVault();\n if (!credentials || !credentials.accessToken) {\n throw new TokenVaultError(\"No credentials found\");\n }\n return credentials.accessToken;\n};\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SUBJECT_TOKEN_TYPES = exports.TokenVaultAuthorizerBase = exports.getAccessTokenFromTokenVault = exports.getCredentialsFromTokenVault = exports.asyncLocalStorage = void 0;
|
|
4
|
+
var asyncLocalStorage_1 = require("./asyncLocalStorage");
|
|
5
|
+
Object.defineProperty(exports, "asyncLocalStorage", { enumerable: true, get: function () { return asyncLocalStorage_1.asyncLocalStorage; } });
|
|
6
|
+
Object.defineProperty(exports, "getCredentialsFromTokenVault", { enumerable: true, get: function () { return asyncLocalStorage_1.getCredentialsFromTokenVault; } });
|
|
7
|
+
Object.defineProperty(exports, "getAccessTokenFromTokenVault", { enumerable: true, get: function () { return asyncLocalStorage_1.getAccessTokenFromTokenVault; } });
|
|
8
|
+
var TokenVaultAuthorizerBase_1 = require("./TokenVaultAuthorizerBase");
|
|
9
|
+
Object.defineProperty(exports, "TokenVaultAuthorizerBase", { enumerable: true, get: function () { return TokenVaultAuthorizerBase_1.TokenVaultAuthorizerBase; } });
|
|
10
|
+
var TokenVaultAuthorizerParams_1 = require("./TokenVaultAuthorizerParams");
|
|
11
|
+
Object.defineProperty(exports, "SUBJECT_TOKEN_TYPES", { enumerable: true, get: function () { return TokenVaultAuthorizerParams_1.SUBJECT_TOKEN_TYPES; } });
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/authorizers/token-vault/index.ts"],"names":[],"mappings":";;;AAEA,yDAI6B;AAH3B,sHAAA,iBAAiB,OAAA;AACjB,iIAAA,4BAA4B,OAAA;AAC5B,iIAAA,4BAA4B,OAAA;AAG9B,uEAAsE;AAA7D,oIAAA,wBAAwB,OAAA;AAIjC,2EAAmE;AAA1D,iIAAA,mBAAmB,OAAA","sourcesContent":["export type { AsyncStorageValue } from \"./asyncLocalStorage\";\n\nexport {\n asyncLocalStorage,\n getCredentialsFromTokenVault,\n getAccessTokenFromTokenVault,\n} from \"./asyncLocalStorage\";\n\nexport { TokenVaultAuthorizerBase } from \"./TokenVaultAuthorizerBase\";\n\nexport type { TokenVaultAuthorizerParams } from \"./TokenVaultAuthorizerParams\";\n\nexport { SUBJECT_TOKEN_TYPES } from \"./TokenVaultAuthorizerParams\";\n"]}
|
package/dist/cjs/index.js
CHANGED
|
@@ -16,8 +16,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.SUBJECT_TOKEN_TYPES = void 0;
|
|
18
18
|
__exportStar(require("./errors"), exports);
|
|
19
|
-
var
|
|
20
|
-
Object.defineProperty(exports, "SUBJECT_TOKEN_TYPES", { enumerable: true, get: function () { return
|
|
19
|
+
var token_vault_1 = require("./authorizers/token-vault");
|
|
20
|
+
Object.defineProperty(exports, "SUBJECT_TOKEN_TYPES", { enumerable: true, get: function () { return token_vault_1.SUBJECT_TOKEN_TYPES; } });
|
|
21
21
|
__exportStar(require("./authorizers/fga/fga-filter"), exports);
|
|
22
22
|
__exportStar(require("./authorizers/fga/fga-client"), exports);
|
|
23
23
|
__exportStar(require("./parameters"), exports);
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAEA,2CAAyB;AACzB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAEA,2CAAyB;AACzB,yDAAgE;AAAvD,kHAAA,mBAAmB,OAAA;AAC5B,+DAA6C;AAC7C,+DAA6C;AAC7C,+CAA6B","sourcesContent":["export type { AuthParams, Auth0ClientParams } from \"./authorizers/types\";\nexport type * from \"./credentials\";\nexport * from \"./errors\";\nexport { SUBJECT_TOKEN_TYPES } from \"./authorizers/token-vault\";\nexport * from \"./authorizers/fga/fga-filter\";\nexport * from \"./authorizers/fga/fga-client\";\nexport * from \"./parameters\";\n"]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.InvalidGrantInterrupt = exports.AuthorizationPollingInterrupt = exports.AuthorizationPendingInterrupt = exports.AuthorizationRequestExpiredInterrupt = exports.UserDoesNotHavePushNotificationsInterrupt = exports.AccessDeniedInterrupt = exports.
|
|
3
|
+
exports.InvalidGrantInterrupt = exports.AuthorizationPollingInterrupt = exports.AuthorizationPendingInterrupt = exports.AuthorizationRequestExpiredInterrupt = exports.UserDoesNotHavePushNotificationsInterrupt = exports.AccessDeniedInterrupt = exports.AsyncAuthorizationInterrupt = void 0;
|
|
4
4
|
const Auth0Interrupt_1 = require("./Auth0Interrupt");
|
|
5
5
|
/**
|
|
6
|
-
* Base class for
|
|
6
|
+
* Base class for Async Authorization interrupts.
|
|
7
7
|
*/
|
|
8
|
-
class
|
|
8
|
+
class AsyncAuthorizationInterrupt extends Auth0Interrupt_1.Auth0Interrupt {
|
|
9
9
|
constructor(message, code) {
|
|
10
10
|
super(message, code);
|
|
11
11
|
}
|
|
@@ -17,14 +17,14 @@ class CIBAInterrupt extends Auth0Interrupt_1.Auth0Interrupt {
|
|
|
17
17
|
(!this.code && interrupt.code.startsWith("CIBA_"))));
|
|
18
18
|
}
|
|
19
19
|
static hasRequestData(interrupt) {
|
|
20
|
-
return
|
|
20
|
+
return AsyncAuthorizationInterrupt.isInterrupt(interrupt) && "request" in interrupt;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
-
exports.
|
|
23
|
+
exports.AsyncAuthorizationInterrupt = AsyncAuthorizationInterrupt;
|
|
24
24
|
/**
|
|
25
25
|
* An interrupt that is thrown when the user denies the authorization request.
|
|
26
26
|
*/
|
|
27
|
-
class AccessDeniedInterrupt extends
|
|
27
|
+
class AccessDeniedInterrupt extends AsyncAuthorizationInterrupt {
|
|
28
28
|
constructor(message, request) {
|
|
29
29
|
super(message, AccessDeniedInterrupt.code);
|
|
30
30
|
this.request = request;
|
|
@@ -35,7 +35,7 @@ AccessDeniedInterrupt.code = "CIBA_ACCESS_DENIED";
|
|
|
35
35
|
/**
|
|
36
36
|
* An interrupt that is thrown when the user does not have push notifications enabled.
|
|
37
37
|
*/
|
|
38
|
-
class UserDoesNotHavePushNotificationsInterrupt extends
|
|
38
|
+
class UserDoesNotHavePushNotificationsInterrupt extends AsyncAuthorizationInterrupt {
|
|
39
39
|
constructor(message) {
|
|
40
40
|
super(message, UserDoesNotHavePushNotificationsInterrupt.code);
|
|
41
41
|
}
|
|
@@ -45,7 +45,7 @@ UserDoesNotHavePushNotificationsInterrupt.code = "CIBA_USER_DOES_NOT_HAVE_PUSH_N
|
|
|
45
45
|
/**
|
|
46
46
|
* An interrupt that is thrown when the authorization request has expired.
|
|
47
47
|
*/
|
|
48
|
-
class AuthorizationRequestExpiredInterrupt extends
|
|
48
|
+
class AuthorizationRequestExpiredInterrupt extends AsyncAuthorizationInterrupt {
|
|
49
49
|
constructor(message, request) {
|
|
50
50
|
super(message, AuthorizationRequestExpiredInterrupt.code);
|
|
51
51
|
this.request = request;
|
|
@@ -57,7 +57,7 @@ AuthorizationRequestExpiredInterrupt.code = "CIBA_AUTHORIZATION_REQUEST_EXPIRED"
|
|
|
57
57
|
* An interrupt that is thrown when the authorization is still pending
|
|
58
58
|
* and the Authorizer is in `mode: interrupt`.
|
|
59
59
|
*/
|
|
60
|
-
class AuthorizationPendingInterrupt extends
|
|
60
|
+
class AuthorizationPendingInterrupt extends AsyncAuthorizationInterrupt {
|
|
61
61
|
constructor(message, request) {
|
|
62
62
|
super(message, AuthorizationPendingInterrupt.code);
|
|
63
63
|
this.request = request;
|
|
@@ -74,7 +74,7 @@ AuthorizationPendingInterrupt.code = "CIBA_AUTHORIZATION_PENDING";
|
|
|
74
74
|
/**
|
|
75
75
|
* An interrupt that is thrown when the authorization polling fails.
|
|
76
76
|
*/
|
|
77
|
-
class AuthorizationPollingInterrupt extends
|
|
77
|
+
class AuthorizationPollingInterrupt extends AsyncAuthorizationInterrupt {
|
|
78
78
|
constructor(message, request, retryAfter) {
|
|
79
79
|
super(message, AuthorizationPollingInterrupt.code);
|
|
80
80
|
this.request = request;
|
|
@@ -92,7 +92,7 @@ AuthorizationPollingInterrupt.code = "CIBA_AUTHORIZATION_POLLING_ERROR";
|
|
|
92
92
|
/**
|
|
93
93
|
* An interrupt that is thrown when the authorization polling fails.
|
|
94
94
|
*/
|
|
95
|
-
class InvalidGrantInterrupt extends
|
|
95
|
+
class InvalidGrantInterrupt extends AsyncAuthorizationInterrupt {
|
|
96
96
|
constructor(message, request) {
|
|
97
97
|
super(message, InvalidGrantInterrupt.code);
|
|
98
98
|
this.request = request;
|
|
@@ -100,4 +100,4 @@ class InvalidGrantInterrupt extends CIBAInterrupt {
|
|
|
100
100
|
}
|
|
101
101
|
exports.InvalidGrantInterrupt = InvalidGrantInterrupt;
|
|
102
102
|
InvalidGrantInterrupt.code = "CIBA_INVALID_GRANT";
|
|
103
|
-
//# sourceMappingURL=
|
|
103
|
+
//# sourceMappingURL=AsyncAuthorizationInterrupt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AsyncAuthorizationInterrupt.js","sourceRoot":"","sources":["../../../src/interrupts/AsyncAuthorizationInterrupt.ts"],"names":[],"mappings":";;;AACA,qDAAsE;AAMtE;;GAEG;AACH,MAAa,2BAA4B,SAAQ,+BAAc;IAC7D,YAAY,OAAe,EAAE,IAAY;QACvC,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,WAAW,CAEhB,SAAc;QAEd,OAAO,CACL,SAAS;YACT,+BAAc,CAAC,WAAW,CAAC,SAAS,CAAC;YACrC,OAAO,SAAS,CAAC,IAAI,KAAK,QAAQ;YAClC,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,IAAI;gBAC3B,CAAC,CAAC,IAAI,CAAC,IAAI,IAAI,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CACtD,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,cAAc,CAAC,SAAc;QAClC,OAAO,2BAA2B,CAAC,WAAW,CAAC,SAA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C,eAAU,GAAV,UAAU,CAAQ;IAGpC,CAAC;IAED;;OAEG;IACI,iBAAiB;QACtB,OAAO,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IAClD,CAAC;;AAlBH,sEAmBC;AAfe,kCAAI,GAAW,kCAA2C,CAAC;AAiB3E;;GAEG;AACH,MAAa,qBACX,SAAQ,2BAA2B;IAInC,YACE,OAAe,EACC,OAAkC;QAElD,KAAK,CAAC,OAAO,EAAE,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAF3B,YAAO,GAAP,OAAO,CAA2B;IAGpD,CAAC;;AAVH,sDAWC;AAPe,0BAAI,GAAW,oBAA6B,CAAC","sourcesContent":["import { AsyncAuthorizationRequest } from \"../authorizers/async-authorization/AsyncAuthorizationRequest\";\nimport { Auth0Interrupt, Auth0InterruptData } from \"./Auth0Interrupt\";\n\nexport interface WithRequestData {\n request: AsyncAuthorizationRequest;\n}\n\n/**\n * Base class for Async Authorization interrupts.\n */\nexport class AsyncAuthorizationInterrupt extends Auth0Interrupt {\n constructor(message: string, code: string) {\n super(message, code);\n }\n\n static isInterrupt<T extends abstract new (...args: any) => any>(\n this: T & { code?: string },\n interrupt: any\n ): interrupt is Auth0InterruptData<InstanceType<T>> {\n return (\n interrupt &&\n Auth0Interrupt.isInterrupt(interrupt) &&\n typeof interrupt.code === \"string\" &&\n (this.code === interrupt.code ||\n (!this.code && interrupt.code.startsWith(\"CIBA_\")))\n );\n }\n\n static hasRequestData(interrupt: any): interrupt is WithRequestData {\n return AsyncAuthorizationInterrupt.isInterrupt(interrupt) && \"request\" in interrupt;\n }\n}\n\n/**\n * An interrupt that is thrown when the user denies the authorization request.\n */\nexport class AccessDeniedInterrupt\n extends AsyncAuthorizationInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_ACCESS_DENIED\" as const;\n constructor(\n message: string,\n public readonly request: AsyncAuthorizationRequest\n ) {\n super(message, AccessDeniedInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the user does not have push notifications enabled.\n */\nexport class UserDoesNotHavePushNotificationsInterrupt extends AsyncAuthorizationInterrupt {\n public static code: string =\n \"CIBA_USER_DOES_NOT_HAVE_PUSH_NOTIFICATIONS\" as const;\n constructor(message: string) {\n super(message, UserDoesNotHavePushNotificationsInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization request has expired.\n */\nexport class AuthorizationRequestExpiredInterrupt\n extends AsyncAuthorizationInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_REQUEST_EXPIRED\" as const;\n constructor(\n message: string,\n public readonly request: AsyncAuthorizationRequest\n ) {\n super(message, AuthorizationRequestExpiredInterrupt.code);\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization is still pending\n * and the Authorizer is in `mode: interrupt`.\n */\nexport class AuthorizationPendingInterrupt\n extends AsyncAuthorizationInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_PENDING\" as const;\n constructor(\n message: string,\n public readonly request: AsyncAuthorizationRequest\n ) {\n super(message, AuthorizationPendingInterrupt.code);\n }\n\n /**\n * Returns the interval in seconds to wait until the next polling attempt.\n */\n public nextRetryInterval(): number {\n return this.request.interval;\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization polling fails.\n */\nexport class AuthorizationPollingInterrupt\n extends AsyncAuthorizationInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_POLLING_ERROR\" as const;\n constructor(\n message: string,\n public readonly request: AsyncAuthorizationRequest,\n public readonly retryAfter: number\n ) {\n super(message, AuthorizationPollingInterrupt.code);\n }\n\n /**\n * Returns the interval in seconds to wait until the next polling attempt.\n */\n public nextRetryInterval(): number {\n return this.retryAfter || this.request.interval;\n }\n}\n\n/**\n * An interrupt that is thrown when the authorization polling fails.\n */\nexport class InvalidGrantInterrupt\n extends AsyncAuthorizationInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_INVALID_GRANT\" as const;\n constructor(\n message: string,\n public readonly request: AsyncAuthorizationRequest\n ) {\n super(message, InvalidGrantInterrupt.code);\n }\n}\n"]}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.TokenVaultError = exports.TokenVaultInterrupt = void 0;
|
|
4
4
|
const Auth0Interrupt_1 = require("./Auth0Interrupt");
|
|
5
5
|
/**
|
|
6
6
|
* Error thrown when a tool call requires an access token for an external service.
|
|
7
7
|
*
|
|
8
8
|
* Throw this error if the service returns Unauthorized for the current access token.
|
|
9
9
|
*/
|
|
10
|
-
class
|
|
10
|
+
class TokenVaultInterrupt extends Auth0Interrupt_1.Auth0Interrupt {
|
|
11
11
|
constructor(message, connection, scopes, requiredScopes, behavior = "resume") {
|
|
12
|
-
super(message,
|
|
12
|
+
super(message, TokenVaultInterrupt.code);
|
|
13
13
|
this.behavior = behavior;
|
|
14
14
|
this.connection = connection;
|
|
15
15
|
this.scopes = scopes;
|
|
16
16
|
this.requiredScopes = requiredScopes;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
exports.
|
|
20
|
-
|
|
19
|
+
exports.TokenVaultInterrupt = TokenVaultInterrupt;
|
|
20
|
+
TokenVaultInterrupt.code = "TokenVaultError";
|
|
21
21
|
/**
|
|
22
22
|
* Error thrown when a tool call requires an access token for an external service.
|
|
23
23
|
*
|
|
24
|
-
* The authorizer will automatically convert this class of error to
|
|
24
|
+
* The authorizer will automatically convert this class of error to TokenVaultInterrupt.
|
|
25
25
|
*/
|
|
26
|
-
class
|
|
26
|
+
class TokenVaultError extends Error {
|
|
27
27
|
constructor(message) {
|
|
28
28
|
super(message);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
-
exports.
|
|
32
|
-
//# sourceMappingURL=
|
|
31
|
+
exports.TokenVaultError = TokenVaultError;
|
|
32
|
+
//# sourceMappingURL=TokenVaultInterrupt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TokenVaultInterrupt.js","sourceRoot":"","sources":["../../../src/interrupts/TokenVaultInterrupt.ts"],"names":[],"mappings":";;;AAAA,qDAAkD;AAElD;;;;GAIG;AACH,MAAa,mBAAoB,SAAQ,+BAAc;IAsBrD,YACE,OAAe,EACf,UAAkB,EAClB,MAAgB,EAChB,cAAwB,EACxB,WAAgC,QAAQ;QAExC,KAAK,CAAC,OAAO,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;IACvC,CAAC;;AAlCH,kDAmCC;AAfe,wBAAI,GAAG,iBAA0B,CAAC;AAiBlD;;;;GAIG;AACH,MAAa,eAAgB,SAAQ,KAAK;IACxC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;CACF;AAJD,0CAIC","sourcesContent":["import { Auth0Interrupt } from \"./Auth0Interrupt\";\n\n/**\n * Error thrown when a tool call requires an access token for an external service.\n *\n * Throw this error if the service returns Unauthorized for the current access token.\n */\nexport class TokenVaultInterrupt extends Auth0Interrupt {\n public behavior: \"resume\" | \"reload\";\n\n /**\n * The auth0 connection name.\n */\n public readonly connection: string;\n\n /**\n * The scopes required to access the external service as stated\n * in the authorizer.\n */\n public readonly scopes: string[];\n\n /**\n * The union between the current scopes of the Access Token plus the required scopes.\n * This is the list of scopes that will be used to request a new Access Token.\n */\n public readonly requiredScopes: string[];\n\n public static code = \"TokenVaultError\" as const;\n\n constructor(\n message: string,\n connection: string,\n scopes: string[],\n requiredScopes: string[],\n behavior: \"resume\" | \"reload\" = \"resume\"\n ) {\n super(message, TokenVaultInterrupt.code);\n this.behavior = behavior;\n this.connection = connection;\n this.scopes = scopes;\n this.requiredScopes = requiredScopes;\n }\n}\n\n/**\n * Error thrown when a tool call requires an access token for an external service.\n *\n * The authorizer will automatically convert this class of error to TokenVaultInterrupt.\n */\nexport class TokenVaultError extends Error {\n constructor(message: string) {\n super(message);\n }\n}\n"]}
|