@auth0/ai 3.6.0 → 4.0.1
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/dist/cjs/authorizers/ciba/CIBAAuthorizerBase.js +3 -3
- package/dist/cjs/authorizers/ciba/CIBAAuthorizerBase.js.map +1 -1
- package/dist/cjs/authorizers/ciba/CIBAAuthorizerParams.js.map +1 -1
- package/dist/cjs/credentials.js +3 -0
- package/dist/cjs/credentials.js.map +1 -1
- package/dist/cjs/interrupts/CIBAInterrupts.js +15 -2
- package/dist/cjs/interrupts/CIBAInterrupts.js.map +1 -1
- package/dist/esm/authorizers/ciba/CIBAAuthorizerBase.js +3 -3
- package/dist/esm/authorizers/ciba/CIBAAuthorizerBase.js.map +1 -1
- package/dist/esm/authorizers/ciba/CIBAAuthorizerParams.d.ts +4 -4
- package/dist/esm/authorizers/ciba/CIBAAuthorizerParams.js.map +1 -1
- package/dist/esm/credentials.d.ts +8 -0
- package/dist/esm/credentials.js +3 -0
- package/dist/esm/credentials.js.map +1 -1
- package/dist/esm/interrupts/CIBAInterrupts.d.ts +10 -1
- package/dist/esm/interrupts/CIBAInterrupts.js +15 -2
- package/dist/esm/interrupts/CIBAInterrupts.js.map +1 -1
- package/package.json +3 -2
|
@@ -67,7 +67,7 @@ class CIBAAuthorizerBase {
|
|
|
67
67
|
const authParams = {
|
|
68
68
|
scope: ensureOpenIdScope(this.params.scopes).join(" "),
|
|
69
69
|
audience: this.params.audience || "",
|
|
70
|
-
|
|
70
|
+
requested_expiry: ((_a = this.params.requestedExpiry) !== null && _a !== void 0 ? _a : 300).toString(),
|
|
71
71
|
binding_message: (_b = (await (0, parameters_1.resolveParameter)(this.params.bindingMessage, toolContext))) !== null && _b !== void 0 ? _b : "",
|
|
72
72
|
userId: (_c = (await (0, parameters_1.resolveParameter)(this.params.userID, toolContext))) !== null && _c !== void 0 ? _c : "",
|
|
73
73
|
};
|
|
@@ -97,7 +97,7 @@ class CIBAAuthorizerBase {
|
|
|
97
97
|
throw new interrupts_1.AuthorizationPendingInterrupt(e.error_description, authRequest);
|
|
98
98
|
}
|
|
99
99
|
if (e.error === "slow_down") {
|
|
100
|
-
throw new interrupts_1.AuthorizationPollingInterrupt(e.error_description, authRequest);
|
|
100
|
+
throw new interrupts_1.AuthorizationPollingInterrupt(e.error_description, authRequest, Number(e.headers.get('retry-after')));
|
|
101
101
|
}
|
|
102
102
|
if (e.error == "invalid_grant") {
|
|
103
103
|
throw new interrupts_1.InvalidGrantInterrupt(e.error_description, authRequest);
|
|
@@ -123,7 +123,7 @@ class CIBAAuthorizerBase {
|
|
|
123
123
|
catch (err) {
|
|
124
124
|
if (err instanceof interrupts_1.AuthorizationPendingInterrupt ||
|
|
125
125
|
err instanceof interrupts_1.AuthorizationPollingInterrupt) {
|
|
126
|
-
await sleep(err.
|
|
126
|
+
await sleep(err.nextRetryInterval() * 1000);
|
|
127
127
|
}
|
|
128
128
|
else {
|
|
129
129
|
throw err;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CIBAAuthorizerBase.js","sourceRoot":"","sources":["../../../../src/authorizers/ciba/CIBAAuthorizerBase.ts"],"names":[],"mappings":";;;;;;AAAA,iCAA6C;AAC7C,oDAA4B;AAC5B,8DAAqC;AAErC,mDAAwE;AACxE,iDAO0B;AAC1B,iDAAoD;AACpD,yCAAwC;AAExC,wCAA0D;AAC1D,oCAAgE;AAChE,2DAA2E;AAI3E,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;AAC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B,CAAC,GAAG,CAAC,CAAC;oBACjD,CAAC;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;AAhTD,gDAgTC","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 { asyncLocalStorage, AsyncStorageValue } from \"./asyncLocalStorage\";\nimport { CIBAAuthorizationRequest } from \"./CIBAAuthorizationRequest\";\nimport { CIBAAuthorizerParams } from \"./CIBAAuthorizerParams\";\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 CIBAAuthorizerBase<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 CIBAAuthorizerParams<ToolExecuteArgs>,\n \"credentialsContext\"\n >;\n\n constructor(\n auth0: Partial<Auth0ClientParams>,\n params: CIBAAuthorizerParams<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<CIBAAuthorizationRequest>(\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<CIBAAuthorizationRequest> {\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 request_expiry: (this.params.requestExpiry ?? 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: CIBAAuthorizationRequest\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 );\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: CIBAAuthorizationRequest) {\n return this.getCredentialsInternal(authRequest);\n }\n\n protected async getCredentialsPolling(\n authRequest: CIBAAuthorizationRequest\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.request.interval * 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: CIBAAuthorizationRequest | 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"]}
|
|
1
|
+
{"version":3,"file":"CIBAAuthorizerBase.js","sourceRoot":"","sources":["../../../../src/authorizers/ciba/CIBAAuthorizerBase.ts"],"names":[],"mappings":";;;;;;AAAA,iCAA6C;A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AAI,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,gDAiTC","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 { asyncLocalStorage, AsyncStorageValue } from \"./asyncLocalStorage\";\nimport { CIBAAuthorizationRequest } from \"./CIBAAuthorizationRequest\";\nimport { CIBAAuthorizerParams } from \"./CIBAAuthorizerParams\";\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 CIBAAuthorizerBase<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 CIBAAuthorizerParams<ToolExecuteArgs>,\n \"credentialsContext\"\n >;\n\n constructor(\n auth0: Partial<Auth0ClientParams>,\n params: CIBAAuthorizerParams<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<CIBAAuthorizationRequest>(\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<CIBAAuthorizationRequest> {\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: CIBAAuthorizationRequest\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: CIBAAuthorizationRequest) {\n return this.getCredentialsInternal(authRequest);\n }\n\n protected async getCredentialsPolling(\n authRequest: CIBAAuthorizationRequest\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: CIBAAuthorizationRequest | 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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CIBAAuthorizerParams.js","sourceRoot":"","sources":["../../../../src/authorizers/ciba/CIBAAuthorizerParams.ts"],"names":[],"mappings":"","sourcesContent":["import { TokenSet } from \"../../credentials\";\nimport {\n AuthorizationPendingInterrupt,\n AuthorizationPollingInterrupt,\n CIBAInterrupt,\n} from \"../../interrupts\";\nimport { AuthorizerToolParameter } from \"../../parameters\";\nimport { Store } from \"../../stores\";\nimport { AuthContext, ToolCallContext } from \"../context\";\nimport { OnAuthorizationRequest } from \"../types\";\nimport { CIBAAuthorizationRequest } from \"./CIBAAuthorizationRequest\";\n\nexport type CIBAAuthorizerParams<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
|
|
1
|
+
{"version":3,"file":"CIBAAuthorizerParams.js","sourceRoot":"","sources":["../../../../src/authorizers/ciba/CIBAAuthorizerParams.ts"],"names":[],"mappings":"","sourcesContent":["import { AuthorizationDetails, TokenSet } from \"../../credentials\";\nimport {\n AuthorizationPendingInterrupt,\n AuthorizationPollingInterrupt,\n CIBAInterrupt,\n} from \"../../interrupts\";\nimport { AuthorizerToolParameter } from \"../../parameters\";\nimport { Store } from \"../../stores\";\nimport { AuthContext, ToolCallContext } from \"../context\";\nimport { OnAuthorizationRequest } from \"../types\";\nimport { CIBAAuthorizationRequest } from \"./CIBAAuthorizationRequest\";\n\nexport type CIBAAuthorizerParams<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: CIBAAuthorizationRequest,\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 | CIBAInterrupt,\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"]}
|
package/dist/cjs/credentials.js
CHANGED
|
@@ -10,6 +10,9 @@ const tokenSetFromTokenResponse = (tr) => {
|
|
|
10
10
|
refreshToken: tr.refresh_token,
|
|
11
11
|
expiresIn: tr.expires_in,
|
|
12
12
|
scopes: tr.scope ? tr.scope.split(" ") : undefined,
|
|
13
|
+
...(tr.authorization_details
|
|
14
|
+
? { authorizationDetails: tr.authorization_details }
|
|
15
|
+
: {}),
|
|
13
16
|
};
|
|
14
17
|
};
|
|
15
18
|
exports.tokenSetFromTokenResponse = tokenSetFromTokenResponse;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/credentials.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/credentials.ts"],"names":[],"mappings":";;;AA8CO,MAAM,yBAAyB,GAAG,CAAC,EAAiB,EAAY,EAAE;;IACvE,OAAO;QACL,SAAS,EAAE,MAAA,EAAE,CAAC,UAAU,mCAAI,QAAQ;QACpC,WAAW,EAAE,EAAE,CAAC,YAAY;QAC5B,OAAO,EAAE,EAAE,CAAC,QAAQ;QACpB,YAAY,EAAE,EAAE,CAAC,aAAa;QAC9B,SAAS,EAAE,EAAE,CAAC,UAAU;QACxB,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS;QAClD,GAAG,CAAC,EAAE,CAAC,qBAAqB;YAC1B,CAAC,CAAC,EAAE,oBAAoB,EAAE,EAAE,CAAC,qBAAqB,EAAE;YACpD,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC,CAAC;AAZW,QAAA,yBAAyB,6BAYpC","sourcesContent":["export interface AuthorizationDetails {\n readonly type: string;\n readonly [parameter: string]: unknown;\n}\n\nexport type TokenResponse = {\n /** Bearer token for API authorization */\n access_token: string;\n /** Refresh token (requires `offline_access` scope) */\n refresh_token?: string;\n /** JWT containing user identity claims */\n id_token: string;\n /** Typically \"Bearer\" */\n token_type?: string;\n /** Token validity in seconds (default: 86400) */\n expires_in: number;\n /** Granted permissions space */\n scope: string;\n /** Granted authorization details */\n authorization_details?: AuthorizationDetails[];\n};\n\n/**\n * Represents a set of authentication tokens returned after a successful authentication flow.\n *\n * @interface TokenSet\n * @property {string[]} [scopes] - Optional array of permission scopes granted for the token.\n * @property {string} [idToken] - Optional JWT ID token containing user claims.\n * @property {string} [refreshToken] - Optional token used to obtain new access tokens without re-authentication.\n * @property {number} [expiresIn] - Optional time in seconds until the access token expires.\n * @property {string} accessToken - The access token string used for API requests.\n * @property {string} tokenType - The type of the token, typically \"Bearer\".\n * @property {AuthorizationDetails[]} [authorizationDetails] - Optional array of authorization details granted for the token.\n */\nexport interface TokenSet {\n scopes?: string[];\n idToken?: string;\n refreshToken?: string;\n\n expiresIn?: number;\n accessToken: string;\n tokenType: string;\n\n authorizationDetails?: AuthorizationDetails[];\n}\n\nexport const tokenSetFromTokenResponse = (tr: TokenResponse): TokenSet => {\n return {\n tokenType: tr.token_type ?? \"Bearer\",\n accessToken: tr.access_token,\n idToken: tr.id_token,\n refreshToken: tr.refresh_token,\n expiresIn: tr.expires_in,\n scopes: tr.scope ? tr.scope.split(\" \") : undefined,\n ...(tr.authorization_details\n ? { authorizationDetails: tr.authorization_details }\n : {}),\n };\n};\n"]}
|
|
@@ -62,6 +62,12 @@ class AuthorizationPendingInterrupt extends CIBAInterrupt {
|
|
|
62
62
|
super(message, AuthorizationPendingInterrupt.code);
|
|
63
63
|
this.request = request;
|
|
64
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Returns the interval in seconds to wait until the next polling attempt.
|
|
67
|
+
*/
|
|
68
|
+
nextRetryInterval() {
|
|
69
|
+
return this.request.interval;
|
|
70
|
+
}
|
|
65
71
|
}
|
|
66
72
|
exports.AuthorizationPendingInterrupt = AuthorizationPendingInterrupt;
|
|
67
73
|
AuthorizationPendingInterrupt.code = "CIBA_AUTHORIZATION_PENDING";
|
|
@@ -69,9 +75,16 @@ AuthorizationPendingInterrupt.code = "CIBA_AUTHORIZATION_PENDING";
|
|
|
69
75
|
* An interrupt that is thrown when the authorization polling fails.
|
|
70
76
|
*/
|
|
71
77
|
class AuthorizationPollingInterrupt extends CIBAInterrupt {
|
|
72
|
-
constructor(message, request) {
|
|
78
|
+
constructor(message, request, retryAfter) {
|
|
73
79
|
super(message, AuthorizationPollingInterrupt.code);
|
|
74
80
|
this.request = request;
|
|
81
|
+
this.retryAfter = retryAfter;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Returns the interval in seconds to wait until the next polling attempt.
|
|
85
|
+
*/
|
|
86
|
+
nextRetryInterval() {
|
|
87
|
+
return this.retryAfter || this.request.interval;
|
|
75
88
|
}
|
|
76
89
|
}
|
|
77
90
|
exports.AuthorizationPollingInterrupt = AuthorizationPollingInterrupt;
|
|
@@ -81,7 +94,7 @@ AuthorizationPollingInterrupt.code = "CIBA_AUTHORIZATION_POLLING_ERROR";
|
|
|
81
94
|
*/
|
|
82
95
|
class InvalidGrantInterrupt extends CIBAInterrupt {
|
|
83
96
|
constructor(message, request) {
|
|
84
|
-
super(message,
|
|
97
|
+
super(message, InvalidGrantInterrupt.code);
|
|
85
98
|
this.request = request;
|
|
86
99
|
}
|
|
87
100
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CIBAInterrupts.js","sourceRoot":"","sources":["../../../src/interrupts/CIBAInterrupts.ts"],"names":[],"mappings":";;;AACA,qDAAsE;AAMtE;;GAEG;AACH,MAAa,aAAc,SAAQ,+BAAc;IAC/C,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,aAAa,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,SAAS,IAAI,SAAS,CAAC;IACxE,CAAC;CACF;AArBD,sCAqBC;AAED;;GAEG;AACH,MAAa,qBACX,SAAQ,aAAa;IAIrB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,EAAE,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAF3B,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AAVH,sDAWC;AAPe,0BAAI,GAAW,oBAA6B,CAAC;AAS7D;;GAEG;AACH,MAAa,yCAA0C,SAAQ,aAAa;IAG1E,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,EAAE,yCAAyC,CAAC,IAAI,CAAC,CAAC;IACjE,CAAC;;AALH,8FAMC;AALe,8CAAI,GAChB,4CAAqD,CAAC;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BC;AAfe,kCAAI,GAAW,kCAA2C,CAAC;AAiB3E;;GAEG;AACH,MAAa,qBACX,SAAQ,aAAa;IAIrB,YACE,OAAe,EACC,OAAiC;QAEjD,KAAK,CAAC,OAAO,EAAE,qBAAqB,CAAC,IAAI,CAAC,CAAC;QAF3B,YAAO,GAAP,OAAO,CAA0B;IAGnD,CAAC;;AAVH,sDAWC;AAPe,0BAAI,GAAW,oBAA6B,CAAC","sourcesContent":["import { CIBAAuthorizationRequest } from \"../authorizers/ciba/CIBAAuthorizationRequest\";\nimport { Auth0Interrupt, Auth0InterruptData } from \"./Auth0Interrupt\";\n\nexport interface WithRequestData {\n request: CIBAAuthorizationRequest;\n}\n\n/**\n * Base class for CIBA interrupts.\n */\nexport class CIBAInterrupt 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 CIBAInterrupt.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 CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_ACCESS_DENIED\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\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 CIBAInterrupt {\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 CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_REQUEST_EXPIRED\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\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 CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_PENDING\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\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 CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_POLLING_ERROR\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest,\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 CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_INVALID_GRANT\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, InvalidGrantInterrupt.code);\n }\n}\n"]}
|
|
@@ -61,7 +61,7 @@ export class CIBAAuthorizerBase {
|
|
|
61
61
|
const authParams = {
|
|
62
62
|
scope: ensureOpenIdScope(this.params.scopes).join(" "),
|
|
63
63
|
audience: this.params.audience || "",
|
|
64
|
-
|
|
64
|
+
requested_expiry: ((_a = this.params.requestedExpiry) !== null && _a !== void 0 ? _a : 300).toString(),
|
|
65
65
|
binding_message: (_b = (await resolveParameter(this.params.bindingMessage, toolContext))) !== null && _b !== void 0 ? _b : "",
|
|
66
66
|
userId: (_c = (await resolveParameter(this.params.userID, toolContext))) !== null && _c !== void 0 ? _c : "",
|
|
67
67
|
};
|
|
@@ -91,7 +91,7 @@ export class CIBAAuthorizerBase {
|
|
|
91
91
|
throw new AuthorizationPendingInterrupt(e.error_description, authRequest);
|
|
92
92
|
}
|
|
93
93
|
if (e.error === "slow_down") {
|
|
94
|
-
throw new AuthorizationPollingInterrupt(e.error_description, authRequest);
|
|
94
|
+
throw new AuthorizationPollingInterrupt(e.error_description, authRequest, Number(e.headers.get('retry-after')));
|
|
95
95
|
}
|
|
96
96
|
if (e.error == "invalid_grant") {
|
|
97
97
|
throw new InvalidGrantInterrupt(e.error_description, authRequest);
|
|
@@ -117,7 +117,7 @@ export class CIBAAuthorizerBase {
|
|
|
117
117
|
catch (err) {
|
|
118
118
|
if (err instanceof AuthorizationPendingInterrupt ||
|
|
119
119
|
err instanceof AuthorizationPollingInterrupt) {
|
|
120
|
-
await sleep(err.
|
|
120
|
+
await sleep(err.nextRetryInterval() * 1000);
|
|
121
121
|
}
|
|
122
122
|
else {
|
|
123
123
|
throw err;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CIBAAuthorizerBase.js","sourceRoot":"","sources":["../../../../src/authorizers/ciba/CIBAAuthorizerBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,UAAU,MAAM,aAAa,CAAC;AAErC,OAAO,EAAY,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,6BAA6B,EAC7B,oCAAoC,EACpC,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Q,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","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 { asyncLocalStorage, AsyncStorageValue } from \"./asyncLocalStorage\";\nimport { CIBAAuthorizationRequest } from \"./CIBAAuthorizationRequest\";\nimport { CIBAAuthorizerParams } from \"./CIBAAuthorizerParams\";\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 CIBAAuthorizerBase<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 CIBAAuthorizerParams<ToolExecuteArgs>,\n \"credentialsContext\"\n >;\n\n constructor(\n auth0: Partial<Auth0ClientParams>,\n params: CIBAAuthorizerParams<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<CIBAAuthorizationRequest>(\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<CIBAAuthorizationRequest> {\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 request_expiry: (this.params.requestExpiry ?? 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: CIBAAuthorizationRequest\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 );\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: CIBAAuthorizationRequest) {\n return this.getCredentialsInternal(authRequest);\n }\n\n protected async getCredentialsPolling(\n authRequest: CIBAAuthorizationRequest\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.request.interval * 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: CIBAAuthorizationRequest | 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"]}
|
|
1
|
+
{"version":3,"file":"CIBAAuthorizerBase.js","sourceRoot":"","sources":["../../../../src/authorizers/ciba/CIBAAuthorizerBase.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,UAAU,MAAM,aAAa,CAAC;AAErC,OAAO,EAAY,yBAAyB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EACL,qBAAqB,EACrB,6BAA6B,EAC7B,6BAA6B,EAC7B,oCAAoC,EACpC,qBAAqB,EACrB,yCAAyC,GAC1C,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,EAAiB,aAAa,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAqB,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAqB,MAAM,qBAAqB,CAAC;AAI3E,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CA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ypto\";\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 { asyncLocalStorage, AsyncStorageValue } from \"./asyncLocalStorage\";\nimport { CIBAAuthorizationRequest } from \"./CIBAAuthorizationRequest\";\nimport { CIBAAuthorizerParams } from \"./CIBAAuthorizerParams\";\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 CIBAAuthorizerBase<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 CIBAAuthorizerParams<ToolExecuteArgs>,\n \"credentialsContext\"\n >;\n\n constructor(\n auth0: Partial<Auth0ClientParams>,\n params: CIBAAuthorizerParams<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<CIBAAuthorizationRequest>(\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<CIBAAuthorizationRequest> {\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: CIBAAuthorizationRequest\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: CIBAAuthorizationRequest) {\n return this.getCredentialsInternal(authRequest);\n }\n\n protected async getCredentialsPolling(\n authRequest: CIBAAuthorizationRequest\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: CIBAAuthorizationRequest | 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"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TokenSet } from "../../credentials";
|
|
1
|
+
import { AuthorizationDetails, TokenSet } from "../../credentials";
|
|
2
2
|
import { AuthorizationPendingInterrupt, AuthorizationPollingInterrupt, CIBAInterrupt } from "../../interrupts";
|
|
3
3
|
import { AuthorizerToolParameter } from "../../parameters";
|
|
4
4
|
import { Store } from "../../stores";
|
|
@@ -21,7 +21,7 @@ export type CIBAAuthorizerParams<ToolExecuteArgs extends any[]> = {
|
|
|
21
21
|
/**
|
|
22
22
|
* The authorization parameters for RAR request.
|
|
23
23
|
*/
|
|
24
|
-
authorizationDetails?: AuthorizerToolParameter<ToolExecuteArgs,
|
|
24
|
+
authorizationDetails?: AuthorizerToolParameter<ToolExecuteArgs, AuthorizationDetails[]>;
|
|
25
25
|
/**
|
|
26
26
|
* The audience to request authorization for.
|
|
27
27
|
*/
|
|
@@ -29,9 +29,9 @@ export type CIBAAuthorizerParams<ToolExecuteArgs extends any[]> = {
|
|
|
29
29
|
/**
|
|
30
30
|
* The time in seconds for the authorization request to expire.
|
|
31
31
|
*
|
|
32
|
-
* Defaults to
|
|
32
|
+
* Defaults to 300 (5 minutes).
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
requestedExpiry?: number;
|
|
35
35
|
/**
|
|
36
36
|
* The behavior when the authorization request is made.
|
|
37
37
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CIBAAuthorizerParams.js","sourceRoot":"","sources":["../../../../src/authorizers/ciba/CIBAAuthorizerParams.ts"],"names":[],"mappings":"","sourcesContent":["import { TokenSet } from \"../../credentials\";\nimport {\n AuthorizationPendingInterrupt,\n AuthorizationPollingInterrupt,\n CIBAInterrupt,\n} from \"../../interrupts\";\nimport { AuthorizerToolParameter } from \"../../parameters\";\nimport { Store } from \"../../stores\";\nimport { AuthContext, ToolCallContext } from \"../context\";\nimport { OnAuthorizationRequest } from \"../types\";\nimport { CIBAAuthorizationRequest } from \"./CIBAAuthorizationRequest\";\n\nexport type CIBAAuthorizerParams<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
|
|
1
|
+
{"version":3,"file":"CIBAAuthorizerParams.js","sourceRoot":"","sources":["../../../../src/authorizers/ciba/CIBAAuthorizerParams.ts"],"names":[],"mappings":"","sourcesContent":["import { AuthorizationDetails, TokenSet } from \"../../credentials\";\nimport {\n AuthorizationPendingInterrupt,\n AuthorizationPollingInterrupt,\n CIBAInterrupt,\n} from \"../../interrupts\";\nimport { AuthorizerToolParameter } from \"../../parameters\";\nimport { Store } from \"../../stores\";\nimport { AuthContext, ToolCallContext } from \"../context\";\nimport { OnAuthorizationRequest } from \"../types\";\nimport { CIBAAuthorizationRequest } from \"./CIBAAuthorizationRequest\";\n\nexport type CIBAAuthorizerParams<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: CIBAAuthorizationRequest,\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 | CIBAInterrupt,\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,3 +1,7 @@
|
|
|
1
|
+
export interface AuthorizationDetails {
|
|
2
|
+
readonly type: string;
|
|
3
|
+
readonly [parameter: string]: unknown;
|
|
4
|
+
}
|
|
1
5
|
export type TokenResponse = {
|
|
2
6
|
/** Bearer token for API authorization */
|
|
3
7
|
access_token: string;
|
|
@@ -11,6 +15,8 @@ export type TokenResponse = {
|
|
|
11
15
|
expires_in: number;
|
|
12
16
|
/** Granted permissions space */
|
|
13
17
|
scope: string;
|
|
18
|
+
/** Granted authorization details */
|
|
19
|
+
authorization_details?: AuthorizationDetails[];
|
|
14
20
|
};
|
|
15
21
|
/**
|
|
16
22
|
* Represents a set of authentication tokens returned after a successful authentication flow.
|
|
@@ -22,6 +28,7 @@ export type TokenResponse = {
|
|
|
22
28
|
* @property {number} [expiresIn] - Optional time in seconds until the access token expires.
|
|
23
29
|
* @property {string} accessToken - The access token string used for API requests.
|
|
24
30
|
* @property {string} tokenType - The type of the token, typically "Bearer".
|
|
31
|
+
* @property {AuthorizationDetails[]} [authorizationDetails] - Optional array of authorization details granted for the token.
|
|
25
32
|
*/
|
|
26
33
|
export interface TokenSet {
|
|
27
34
|
scopes?: string[];
|
|
@@ -30,6 +37,7 @@ export interface TokenSet {
|
|
|
30
37
|
expiresIn?: number;
|
|
31
38
|
accessToken: string;
|
|
32
39
|
tokenType: string;
|
|
40
|
+
authorizationDetails?: AuthorizationDetails[];
|
|
33
41
|
}
|
|
34
42
|
export declare const tokenSetFromTokenResponse: (tr: TokenResponse) => TokenSet;
|
|
35
43
|
//# sourceMappingURL=credentials.d.ts.map
|
package/dist/esm/credentials.js
CHANGED
|
@@ -7,6 +7,9 @@ export const tokenSetFromTokenResponse = (tr) => {
|
|
|
7
7
|
refreshToken: tr.refresh_token,
|
|
8
8
|
expiresIn: tr.expires_in,
|
|
9
9
|
scopes: tr.scope ? tr.scope.split(" ") : undefined,
|
|
10
|
+
...(tr.authorization_details
|
|
11
|
+
? { authorizationDetails: tr.authorization_details }
|
|
12
|
+
: {}),
|
|
10
13
|
};
|
|
11
14
|
};
|
|
12
15
|
//# sourceMappingURL=credentials.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/credentials.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/credentials.ts"],"names":[],"mappings":"AA8CA,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,EAAiB,EAAY,EAAE;;IACvE,OAAO;QACL,SAAS,EAAE,MAAA,EAAE,CAAC,UAAU,mCAAI,QAAQ;QACpC,WAAW,EAAE,EAAE,CAAC,YAAY;QAC5B,OAAO,EAAE,EAAE,CAAC,QAAQ;QACpB,YAAY,EAAE,EAAE,CAAC,aAAa;QAC9B,SAAS,EAAE,EAAE,CAAC,UAAU;QACxB,MAAM,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS;QAClD,GAAG,CAAC,EAAE,CAAC,qBAAqB;YAC1B,CAAC,CAAC,EAAE,oBAAoB,EAAE,EAAE,CAAC,qBAAqB,EAAE;YACpD,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC,CAAC","sourcesContent":["export interface AuthorizationDetails {\n readonly type: string;\n readonly [parameter: string]: unknown;\n}\n\nexport type TokenResponse = {\n /** Bearer token for API authorization */\n access_token: string;\n /** Refresh token (requires `offline_access` scope) */\n refresh_token?: string;\n /** JWT containing user identity claims */\n id_token: string;\n /** Typically \"Bearer\" */\n token_type?: string;\n /** Token validity in seconds (default: 86400) */\n expires_in: number;\n /** Granted permissions space */\n scope: string;\n /** Granted authorization details */\n authorization_details?: AuthorizationDetails[];\n};\n\n/**\n * Represents a set of authentication tokens returned after a successful authentication flow.\n *\n * @interface TokenSet\n * @property {string[]} [scopes] - Optional array of permission scopes granted for the token.\n * @property {string} [idToken] - Optional JWT ID token containing user claims.\n * @property {string} [refreshToken] - Optional token used to obtain new access tokens without re-authentication.\n * @property {number} [expiresIn] - Optional time in seconds until the access token expires.\n * @property {string} accessToken - The access token string used for API requests.\n * @property {string} tokenType - The type of the token, typically \"Bearer\".\n * @property {AuthorizationDetails[]} [authorizationDetails] - Optional array of authorization details granted for the token.\n */\nexport interface TokenSet {\n scopes?: string[];\n idToken?: string;\n refreshToken?: string;\n\n expiresIn?: number;\n accessToken: string;\n tokenType: string;\n\n authorizationDetails?: AuthorizationDetails[];\n}\n\nexport const tokenSetFromTokenResponse = (tr: TokenResponse): TokenSet => {\n return {\n tokenType: tr.token_type ?? \"Bearer\",\n accessToken: tr.access_token,\n idToken: tr.id_token,\n refreshToken: tr.refresh_token,\n expiresIn: tr.expires_in,\n scopes: tr.scope ? tr.scope.split(\" \") : undefined,\n ...(tr.authorization_details\n ? { authorizationDetails: tr.authorization_details }\n : {}),\n };\n};\n"]}
|
|
@@ -44,14 +44,23 @@ export declare class AuthorizationPendingInterrupt extends CIBAInterrupt impleme
|
|
|
44
44
|
readonly request: CIBAAuthorizationRequest;
|
|
45
45
|
static code: string;
|
|
46
46
|
constructor(message: string, request: CIBAAuthorizationRequest);
|
|
47
|
+
/**
|
|
48
|
+
* Returns the interval in seconds to wait until the next polling attempt.
|
|
49
|
+
*/
|
|
50
|
+
nextRetryInterval(): number;
|
|
47
51
|
}
|
|
48
52
|
/**
|
|
49
53
|
* An interrupt that is thrown when the authorization polling fails.
|
|
50
54
|
*/
|
|
51
55
|
export declare class AuthorizationPollingInterrupt extends CIBAInterrupt implements WithRequestData {
|
|
52
56
|
readonly request: CIBAAuthorizationRequest;
|
|
57
|
+
readonly retryAfter: number;
|
|
53
58
|
static code: string;
|
|
54
|
-
constructor(message: string, request: CIBAAuthorizationRequest);
|
|
59
|
+
constructor(message: string, request: CIBAAuthorizationRequest, retryAfter: number);
|
|
60
|
+
/**
|
|
61
|
+
* Returns the interval in seconds to wait until the next polling attempt.
|
|
62
|
+
*/
|
|
63
|
+
nextRetryInterval(): number;
|
|
55
64
|
}
|
|
56
65
|
/**
|
|
57
66
|
* An interrupt that is thrown when the authorization polling fails.
|
|
@@ -55,15 +55,28 @@ export class AuthorizationPendingInterrupt extends CIBAInterrupt {
|
|
|
55
55
|
super(message, AuthorizationPendingInterrupt.code);
|
|
56
56
|
this.request = request;
|
|
57
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Returns the interval in seconds to wait until the next polling attempt.
|
|
60
|
+
*/
|
|
61
|
+
nextRetryInterval() {
|
|
62
|
+
return this.request.interval;
|
|
63
|
+
}
|
|
58
64
|
}
|
|
59
65
|
AuthorizationPendingInterrupt.code = "CIBA_AUTHORIZATION_PENDING";
|
|
60
66
|
/**
|
|
61
67
|
* An interrupt that is thrown when the authorization polling fails.
|
|
62
68
|
*/
|
|
63
69
|
export class AuthorizationPollingInterrupt extends CIBAInterrupt {
|
|
64
|
-
constructor(message, request) {
|
|
70
|
+
constructor(message, request, retryAfter) {
|
|
65
71
|
super(message, AuthorizationPollingInterrupt.code);
|
|
66
72
|
this.request = request;
|
|
73
|
+
this.retryAfter = retryAfter;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Returns the interval in seconds to wait until the next polling attempt.
|
|
77
|
+
*/
|
|
78
|
+
nextRetryInterval() {
|
|
79
|
+
return this.retryAfter || this.request.interval;
|
|
67
80
|
}
|
|
68
81
|
}
|
|
69
82
|
AuthorizationPollingInterrupt.code = "CIBA_AUTHORIZATION_POLLING_ERROR";
|
|
@@ -72,7 +85,7 @@ AuthorizationPollingInterrupt.code = "CIBA_AUTHORIZATION_POLLING_ERROR";
|
|
|
72
85
|
*/
|
|
73
86
|
export class InvalidGrantInterrupt extends CIBAInterrupt {
|
|
74
87
|
constructor(message, request) {
|
|
75
|
-
super(message,
|
|
88
|
+
super(message, InvalidGrantInterrupt.code);
|
|
76
89
|
this.request = request;
|
|
77
90
|
}
|
|
78
91
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CIBAInterrupts.js","sourceRoot":"","sources":["../../../src/interrupts/CIBAInterrupts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAsB,MAAM,kBAAkB,CAAC;AAMtE;;GAEG;AACH,MAAM,OAAO,aAAc,SAAQ,cAAc;IAC/C,YAAY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thorizationRequest\";\nimport { Auth0Interrupt, Auth0InterruptData } from \"./Auth0Interrupt\";\n\nexport interface WithRequestData {\n request: CIBAAuthorizationRequest;\n}\n\n/**\n * Base class for CIBA interrupts.\n */\nexport class CIBAInterrupt 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 CIBAInterrupt.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 CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_ACCESS_DENIED\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\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 CIBAInterrupt {\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 CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_REQUEST_EXPIRED\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\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 CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_PENDING\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\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 CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_AUTHORIZATION_POLLING_ERROR\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest,\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 CIBAInterrupt\n implements WithRequestData\n{\n public static code: string = \"CIBA_INVALID_GRANT\" as const;\n constructor(\n message: string,\n public readonly request: CIBAAuthorizationRequest\n ) {\n super(message, InvalidGrantInterrupt.code);\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auth0/ai",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "Auth0AI SDK for JavaScript",
|
|
5
5
|
"types": "dist/esm/index.d.ts",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
"lint": "eslint \"./**/*.ts*\"",
|
|
15
15
|
"type-check": "tsc --noEmit",
|
|
16
16
|
"test": "vitest run",
|
|
17
|
+
"test:debug": "vitest --inspect-brk --no-file-parallelism run",
|
|
17
18
|
"semantic-release": "npx --no semantic-release"
|
|
18
19
|
},
|
|
19
20
|
"author": {
|
|
@@ -79,7 +80,7 @@
|
|
|
79
80
|
},
|
|
80
81
|
"dependencies": {
|
|
81
82
|
"@openfga/sdk": "^0.8.0",
|
|
82
|
-
"auth0": "^4.
|
|
83
|
+
"auth0": "^4.30.0",
|
|
83
84
|
"jose": "^5.9.6",
|
|
84
85
|
"openid-client": "^6.1.7",
|
|
85
86
|
"stable-hash": "^0.0.5",
|