@auth0/ai 1.0.2 → 2.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/CIBAAuthorizerBase.js +81 -55
- package/dist/cjs/authorizers/ciba/CIBAAuthorizerBase.js.map +1 -1
- package/dist/cjs/authorizers/ciba/CIBAAuthorizerParams.js.map +1 -1
- package/dist/cjs/authorizers/ciba/asyncLocalStorage.js +1 -1
- package/dist/cjs/authorizers/ciba/asyncLocalStorage.js.map +1 -1
- package/dist/cjs/authorizers/context.js +20 -0
- package/dist/cjs/authorizers/context.js.map +1 -0
- package/dist/cjs/authorizers/device-authorizer/DeviceAuthResponse.js +18 -0
- package/dist/cjs/authorizers/device-authorizer/DeviceAuthResponse.js.map +1 -0
- package/dist/cjs/authorizers/device-authorizer/DeviceAuthorizerBase.js +231 -0
- package/dist/cjs/authorizers/device-authorizer/DeviceAuthorizerBase.js.map +1 -0
- package/dist/cjs/{TokenResponse.js → authorizers/device-authorizer/DeviceAuthorizerParams.js} +1 -1
- package/dist/cjs/authorizers/device-authorizer/DeviceAuthorizerParams.js.map +1 -0
- package/dist/cjs/authorizers/device-authorizer/asyncLocalStorage.js +14 -0
- package/dist/cjs/authorizers/device-authorizer/asyncLocalStorage.js.map +1 -0
- package/dist/cjs/authorizers/device-authorizer/index.js +9 -0
- package/dist/cjs/authorizers/device-authorizer/index.js.map +1 -0
- package/dist/cjs/authorizers/federated-connections/FederatedConnectionAuthorizerBase.js +158 -0
- package/dist/cjs/authorizers/federated-connections/FederatedConnectionAuthorizerBase.js.map +1 -0
- package/dist/cjs/authorizers/federated-connections/FederatedConnectionAuthorizerParams.js +3 -0
- package/dist/cjs/authorizers/federated-connections/FederatedConnectionAuthorizerParams.js.map +1 -0
- package/dist/cjs/authorizers/federated-connections/asyncLocalStorage.js +5 -5
- package/dist/cjs/authorizers/federated-connections/asyncLocalStorage.js.map +1 -1
- package/dist/cjs/authorizers/federated-connections/index.js +5 -125
- package/dist/cjs/authorizers/federated-connections/index.js.map +1 -1
- package/dist/cjs/authorizers/index.js.map +1 -1
- package/dist/cjs/authorizers/types.js +14 -0
- package/dist/cjs/authorizers/types.js.map +1 -0
- package/dist/cjs/credentials.js +13 -0
- package/dist/cjs/credentials.js.map +1 -1
- package/dist/cjs/index.js +0 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/interrupts/DeviceInterrupts.js +79 -0
- package/dist/cjs/interrupts/DeviceInterrupts.js.map +1 -0
- package/dist/cjs/interrupts/index.js +37 -1
- package/dist/cjs/interrupts/index.js.map +1 -1
- package/dist/cjs/stores/Store.js +12 -0
- package/dist/cjs/stores/Store.js.map +1 -0
- package/dist/cjs/stores/SubStore.js +52 -0
- package/dist/cjs/stores/SubStore.js.map +1 -0
- package/dist/cjs/stores/impl/FSStore.js +80 -0
- package/dist/cjs/stores/impl/FSStore.js.map +1 -0
- package/dist/cjs/stores/impl/MemoryStore.js +15 -0
- package/dist/cjs/stores/impl/MemoryStore.js.map +1 -0
- package/dist/cjs/stores/impl/TempBoxStore.js +22 -0
- package/dist/cjs/stores/impl/TempBoxStore.js.map +1 -0
- package/dist/cjs/stores/index.js +10 -0
- package/dist/cjs/stores/index.js.map +1 -0
- package/dist/cjs/util/index.js +12 -0
- package/dist/cjs/util/index.js.map +1 -0
- package/dist/esm/authorizers/ciba/CIBAAuthorizerBase.d.ts +12 -8
- package/dist/esm/authorizers/ciba/CIBAAuthorizerBase.js +78 -55
- package/dist/esm/authorizers/ciba/CIBAAuthorizerBase.js.map +1 -1
- package/dist/esm/authorizers/ciba/CIBAAuthorizerParams.d.ts +20 -20
- package/dist/esm/authorizers/ciba/CIBAAuthorizerParams.js.map +1 -1
- package/dist/esm/authorizers/ciba/asyncLocalStorage.d.ts +7 -3
- package/dist/esm/authorizers/ciba/asyncLocalStorage.js +1 -1
- package/dist/esm/authorizers/ciba/asyncLocalStorage.js.map +1 -1
- package/dist/esm/authorizers/context.d.ts +16 -0
- package/dist/esm/authorizers/context.js +16 -0
- package/dist/esm/authorizers/context.js.map +1 -0
- package/dist/esm/authorizers/device-authorizer/DeviceAuthResponse.d.ts +38 -0
- package/dist/esm/authorizers/device-authorizer/DeviceAuthResponse.js +15 -0
- package/dist/esm/authorizers/device-authorizer/DeviceAuthResponse.js.map +1 -0
- package/dist/esm/authorizers/device-authorizer/DeviceAuthorizerBase.d.ts +49 -0
- package/dist/esm/authorizers/device-authorizer/DeviceAuthorizerBase.js +224 -0
- package/dist/esm/authorizers/device-authorizer/DeviceAuthorizerBase.js.map +1 -0
- package/dist/esm/authorizers/device-authorizer/DeviceAuthorizerParams.d.ts +58 -0
- package/dist/esm/authorizers/device-authorizer/DeviceAuthorizerParams.js +2 -0
- package/dist/esm/authorizers/device-authorizer/DeviceAuthorizerParams.js.map +1 -0
- package/dist/esm/authorizers/device-authorizer/asyncLocalStorage.d.ts +16 -0
- package/dist/esm/authorizers/device-authorizer/asyncLocalStorage.js +10 -0
- package/dist/esm/authorizers/device-authorizer/asyncLocalStorage.js.map +1 -0
- package/dist/esm/authorizers/device-authorizer/index.d.ts +4 -0
- package/dist/esm/authorizers/device-authorizer/index.js +3 -0
- package/dist/esm/authorizers/device-authorizer/index.js.map +1 -0
- package/dist/esm/authorizers/federated-connections/FederatedConnectionAuthorizerBase.d.ts +30 -0
- package/dist/esm/authorizers/federated-connections/FederatedConnectionAuthorizerBase.js +151 -0
- package/dist/esm/authorizers/federated-connections/FederatedConnectionAuthorizerBase.js.map +1 -0
- package/dist/esm/authorizers/federated-connections/FederatedConnectionAuthorizerParams.d.ts +38 -0
- package/dist/esm/authorizers/federated-connections/FederatedConnectionAuthorizerParams.js +2 -0
- package/dist/esm/authorizers/federated-connections/FederatedConnectionAuthorizerParams.js.map +1 -0
- package/dist/esm/authorizers/federated-connections/asyncLocalStorage.d.ts +7 -5
- package/dist/esm/authorizers/federated-connections/asyncLocalStorage.js +3 -3
- package/dist/esm/authorizers/federated-connections/asyncLocalStorage.js.map +1 -1
- package/dist/esm/authorizers/federated-connections/index.d.ts +3 -36
- package/dist/esm/authorizers/federated-connections/index.js +2 -122
- package/dist/esm/authorizers/federated-connections/index.js.map +1 -1
- package/dist/esm/authorizers/index.d.ts +1 -12
- package/dist/esm/authorizers/index.js.map +1 -1
- package/dist/esm/authorizers/types.d.ts +37 -0
- package/dist/esm/authorizers/types.js +11 -0
- package/dist/esm/authorizers/types.js.map +1 -0
- package/dist/esm/credentials.d.ts +33 -8
- package/dist/esm/credentials.js +11 -1
- package/dist/esm/credentials.js.map +1 -1
- package/dist/esm/index.d.ts +1 -3
- package/dist/esm/index.js +0 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interrupts/DeviceInterrupts.d.ts +55 -0
- package/dist/esm/interrupts/DeviceInterrupts.js +70 -0
- package/dist/esm/interrupts/DeviceInterrupts.js.map +1 -0
- package/dist/esm/interrupts/index.d.ts +2 -0
- package/dist/esm/interrupts/index.js +2 -0
- package/dist/esm/interrupts/index.js.map +1 -1
- package/dist/esm/stores/Store.d.ts +40 -0
- package/dist/esm/stores/Store.js +11 -0
- package/dist/esm/stores/Store.js.map +1 -0
- package/dist/esm/stores/SubStore.d.ts +31 -0
- package/dist/esm/stores/SubStore.js +48 -0
- package/dist/esm/stores/SubStore.js.map +1 -0
- package/dist/esm/stores/impl/FSStore.d.ts +19 -0
- package/dist/esm/stores/impl/FSStore.js +72 -0
- package/dist/esm/stores/impl/FSStore.js.map +1 -0
- package/dist/esm/stores/impl/MemoryStore.d.ts +8 -0
- package/dist/esm/stores/impl/MemoryStore.js +11 -0
- package/dist/esm/stores/impl/MemoryStore.js.map +1 -0
- package/dist/esm/stores/impl/TempBoxStore.d.ts +13 -0
- package/dist/esm/stores/impl/TempBoxStore.js +18 -0
- package/dist/esm/stores/impl/TempBoxStore.js.map +1 -0
- package/dist/esm/stores/index.d.ts +5 -0
- package/dist/esm/stores/index.js +4 -0
- package/dist/esm/stores/index.js.map +1 -0
- package/dist/esm/util/index.d.ts +3 -0
- package/dist/esm/util/index.js +8 -0
- package/dist/esm/util/index.js.map +1 -0
- package/package.json +20 -4
- package/dist/cjs/TokenResponse.js.map +0 -1
- package/dist/cjs/authorizers/device-authorizer.js +0 -130
- package/dist/cjs/authorizers/device-authorizer.js.map +0 -1
- package/dist/esm/TokenResponse.d.ts +0 -15
- package/dist/esm/TokenResponse.js +0 -2
- package/dist/esm/TokenResponse.js.map +0 -1
- package/dist/esm/authorizers/device-authorizer.d.ts +0 -15
- package/dist/esm/authorizers/device-authorizer.js +0 -90
- package/dist/esm/authorizers/device-authorizer.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeviceAuthorizerBase.js","sourceRoot":"","sources":["../../../../src/authorizers/device-authorizer/DeviceAuthorizerBase.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAiC;AACjC,iDAAuE;AACvE,6CAAyC;AAEzC,mDAAwE;AACxE,wEAK2C;AAC3C,yCAA+C;AAC/C,qCAAkC;AAClC,wCAAuE;AACvE,oCAA4E;AAC5E,2DAA2E;AAE3E,6DAG8B;AAE9B,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAEhF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAa,oBAAoB;IAQ/B,YACE,KAAuC,EACvC,MAA+C;QAE/C,IAAI,CAAC,KAAK,GAAG,+BAAuB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACzC,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;YACzB,MAAM,IAAI,KAAK,CAAC,w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Q,CAAC,WAAW,EAAE;QAEvB,OAAO,WAAW,CAAC;IACrB,CAAC;IAEO,aAAa;QACnB,MAAM,KAAK,GAAG;YACZ,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,MAAM,EAAE,IAAA,WAAI,EAAC,IAAI,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAC;SACvD,CAAC;QACF,MAAM,EAAE,GAAG,IAAA,wBAAU,EAAC,KAAK,CAAC,CAAC;QAC7B,OAAO,qBAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC3D,CAAC;IAES,iBAAiB;QACzB,MAAM,KAAK,GAAG,qCAAiB,CAAC,QAAQ,EAAE,CAAC;QAC3C,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;QACtE,CAAC;QACD,MAAM,cAAc,GAAG,IAAA,uBAAa,EAAC,WAAW,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QACjE,OAAO,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IACvE,CAAC;IAES,6BAA6B,CACrC,GAAkE;QAElE,MAAM,GAAG,CAAC;IACZ,CAAC;CACF;AA1QD,oDA0QC","sourcesContent":["import crypto from \"node:crypto\";\nimport { discovery, initiateDeviceAuthorization } from \"openid-client\";\nimport { stableHash } from \"stable-hash\";\n\nimport { TokenSet, tokenSetFromTokenResponse } from \"../../credentials\";\nimport {\n AccessDeniedInterrupt,\n AuthorizationPendingInterrupt,\n AuthorizationPollingInterrupt,\n AuthorizationRequestExpiredInterrupt,\n} from \"../../interrupts/DeviceInterrupts\";\nimport { Store, SubStore } from \"../../stores\";\nimport { omit } from \"../../util\";\nimport { AuthContext, ContextGetter, nsFromContext } from \"../context\";\nimport { Auth0PublicClientParams, Auth0PublicClientSchema } from \"../types\";\nimport { asyncLocalStorage, AsyncStorageValue } from \"./asyncLocalStorage\";\nimport { DeviceAuthorizerParams } from \"./DeviceAuthorizerParams\";\nimport {\n DeviceAuthorizationResponse,\n parseDeviceAuthResponse,\n} from \"./DeviceAuthResponse\";\n\nconst sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));\n\n/**\n * The DeviceAuthorizerBase class acts as a guard and wrapper around tools or agent\n * capabilities that require authenticated access. It encapsulates the\n * OpenID Connect Device Authorization Flow, allowing tools to interrupt execution\n * to request user authorization and resume seamlessly once authorization is granted.\n *\n * Enable agentic tools to be wrapped with secure, lazy-triggered device authorization,\n * with a clean interrupt/resume model for user-in-the-loop authentication.\n *\n * Core Concepts\n *\n * - Interrupt-driven flow: If no valid token is present, the tool throws a DeviceAuthInterrupt,\n * which contains the verification_uri, user_code, and other relevant metadata.\n *\n * - Polling/resumption: The Agent client can poll the agent to resume execution.\n *\n * - Token management: Tokens (and refresh tokens, if applicable) are stored and reused\n * transparently.\n *\n */\nexport class DeviceAuthorizerBase<ToolExecuteArgs extends any[]> {\n private auth0: Auth0PublicClientParams;\n private params: DeviceAuthorizerParams<ToolExecuteArgs> & {\n credentialsContext: AuthContext;\n };\n private credentialsStore: Store<TokenSet>;\n private authResponseStore: Store<DeviceAuthorizationResponse>;\n\n constructor(\n auth0: Partial<Auth0PublicClientParams>,\n params: DeviceAuthorizerParams<ToolExecuteArgs>\n ) {\n this.auth0 = Auth0PublicClientSchema.parse(auth0);\n if (!this.auth0.domain) {\n throw new Error(\"Domain is required.\");\n }\n if (!this.auth0.clientId) {\n throw new Error(\"Client ID is required.\");\n }\n if (!params.store) {\n throw new Error(\"Store is required.\");\n }\n\n this.params = {\n credentialsContext: \"thread\",\n ...params,\n };\n\n const instanceID = this.getInstanceID();\n\n this.credentialsStore = new SubStore(params.store, {\n baseNamespace: [instanceID, \"Credentials\"],\n getTTL: (credentials) =>\n credentials.expiresIn ? credentials.expiresIn * 1000 : undefined,\n });\n\n this.authResponseStore = new SubStore(params.store, {\n baseNamespace: [instanceID, \"AuthResponses\"],\n getTTL: (authResponse) =>\n authResponse.expiresIn ? authResponse.expiresIn * 1000 : undefined,\n });\n }\n\n private async start(): Promise<DeviceAuthorizationResponse> {\n const requestedAt = Date.now() / 1000;\n const config = await discovery(\n new URL(`https://${this.auth0.domain!}`),\n this.auth0.clientId!\n );\n\n const handle = await initiateDeviceAuthorization(config, {\n scope: (this.params.scopes ?? []).join(\" \"),\n audience: this.params.audience!,\n });\n\n return parseDeviceAuthResponse(handle, requestedAt);\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: DeviceAuthorizationResponse | 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 storeValue: AsyncStorageValue<any> = {\n args,\n context: context,\n };\n\n return asyncLocalStorage.run(storeValue, async () => {\n let credentials: TokenSet | undefined;\n let credentialsObtained = false;\n const authResponseNS = nsFromContext(\"tool-call\", context);\n const credentialsNS = nsFromContext(\n this.params.credentialsContext,\n context\n );\n try {\n credentials = await this.credentialsStore.get(\n credentialsNS,\n \"credential\"\n );\n\n if (!credentials) {\n if (\n !this.params.onAuthorizationRequest ||\n this.params.onAuthorizationRequest === \"interrupt\"\n ) {\n authResponse = await this.authResponseStore.get(\n authResponseNS,\n \"authResponse\"\n );\n\n if (!authResponse) {\n //Initial request\n authResponse = await this.start();\n await this.authResponseStore.put(\n authResponseNS,\n \"authResponse\",\n authResponse\n );\n }\n credentials = await this.getCredentials(authResponse);\n } else {\n // Block mode\n authResponse = await this.start();\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\n if (typeof credentials !== \"undefined\") {\n this.credentialsStore.put(\n credentialsNS,\n \"credential\",\n credentials\n );\n }\n\n credentialsObtained = true;\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 if (credentialsObtained) {\n await this.deleteAuthRequest();\n }\n storeValue.credentials = credentials;\n return execute(...args);\n });\n };\n }\n\n private async getCredentials(\n authResponse: DeviceAuthorizationResponse\n ): Promise<TokenSet | undefined> {\n //TODO: this is not supported neither by the OIDC client library\n // or the auth0 client.\n const url = `https://${this.auth0.domain!}/oauth/token`;\n const response = await fetch(url, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/x-www-form-urlencoded\",\n },\n body: new URLSearchParams({\n grant_type: \"urn:ietf:params:oauth:grant-type:device_code\",\n device_code: authResponse.deviceCode,\n client_id: this.auth0.clientId!,\n }),\n });\n\n if (!response.ok) {\n if (response.headers.get(\"content-type\")?.includes(\"application/json\")) {\n const { error, error_description } = await response.json();\n if (error === \"authorization_pending\") {\n throw new AuthorizationPendingInterrupt(\n error_description,\n authResponse\n );\n }\n if (error === \"slow_down\") {\n throw new AuthorizationPollingInterrupt(\n error_description,\n authResponse\n );\n }\n if (error === \"expired_token\") {\n throw new AuthorizationRequestExpiredInterrupt(\n error_description,\n authResponse\n );\n }\n if (error === \"access_denied\") {\n throw new AccessDeniedInterrupt(error_description, authResponse);\n }\n throw new Error(error_description);\n }\n const errText = await response.text();\n throw new Error(`Failed to obtain tokens: ${errText}`);\n }\n\n const tr = await response.json();\n const credentials = tokenSetFromTokenResponse(tr);\n\n return credentials;\n }\n\n protected async getCredentialsPolling(\n authResponse: DeviceAuthorizationResponse\n ): Promise<TokenSet | undefined> {\n let credentials: TokenSet | undefined = undefined;\n\n do {\n try {\n credentials = await this.getCredentials(authResponse);\n } catch (err) {\n if (\n err instanceof AuthorizationPendingInterrupt ||\n err instanceof AuthorizationPollingInterrupt\n ) {\n await sleep((err.response.interval ?? 10) * 1000);\n } else {\n throw err;\n }\n }\n } while (!credentials);\n\n return credentials;\n }\n\n private getInstanceID(): string {\n const props = {\n auth0: this.auth0,\n params: omit(this.params, [\"store\", \"onUnauthorized\"]),\n };\n const sh = stableHash(props);\n return crypto.createHash(\"MD5\").update(sh).digest(\"hex\");\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 = nsFromContext(\"tool-call\", store.context);\n return this.authResponseStore.delete(authResponseNS, \"authResponse\");\n }\n\n protected handleAuthorizationInterrupts(\n err: AuthorizationPendingInterrupt | AuthorizationPollingInterrupt\n ) {\n throw err;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeviceAuthorizerParams.js","sourceRoot":"","sources":["../../../../src/authorizers/device-authorizer/DeviceAuthorizerParams.ts"],"names":[],"mappings":"","sourcesContent":["import { TokenSet } from \"../../credentials\";\nimport { DeviceInterrupt } from \"../../interrupts/DeviceInterrupts\";\nimport { Store } from \"../../stores\";\nimport { AuthContext } from \"../context\";\nimport { OnAuthorizationRequest } from \"../types\";\nimport { DeviceAuthorizationResponse } from \"./DeviceAuthResponse\";\n\n/**\n * The parameters for the DeviceAuthorizer.\n */\nexport type DeviceAuthorizerParams<ToolExecuteArgs extends any[]> = {\n /**\n * The scopes to request.\n */\n scopes: string[];\n\n /**\n * The audience to request.\n */\n audience?: string;\n\n /**\n * The authorization response store.\n * Allows to store the authorization response for resuming the tool execution\n * after the interrupt.\n */\n store: Store;\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 * 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 this allow you\n * to show the link/code and open the browser\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: DeviceAuthorizationResponse,\n poll: Promise<TokenSet | undefined>\n ) => Promise<void>);\n\n /**\n *\n * A callback that is called when the authorization request is unsuccessful.\n *\n * @param err - The error that occurred.\n * @param args - The tool execution arguments.\n * @returns - The final response the tool will return.\n */\n onUnauthorized?: (\n err: Error | DeviceInterrupt,\n ...args: ToolExecuteArgs\n ) => any;\n};\n\nexport type { DeviceAuthorizationResponse };\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDeviceAuthorizerCredentials = exports.asyncLocalStorage = void 0;
|
|
4
|
+
const async_hooks_1 = require("async_hooks");
|
|
5
|
+
exports.asyncLocalStorage = new async_hooks_1.AsyncLocalStorage();
|
|
6
|
+
const getDeviceAuthorizerCredentials = () => {
|
|
7
|
+
const t = exports.asyncLocalStorage.getStore();
|
|
8
|
+
if (typeof t === "undefined") {
|
|
9
|
+
throw new Error("The tool must be wrapped with the withAsyncUserConfirmation function.");
|
|
10
|
+
}
|
|
11
|
+
return t.credentials;
|
|
12
|
+
};
|
|
13
|
+
exports.getDeviceAuthorizerCredentials = getDeviceAuthorizerCredentials;
|
|
14
|
+
//# sourceMappingURL=asyncLocalStorage.js.map
|
|
@@ -0,0 +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,uEAAuE,CACxE,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 withAsyncUserConfirmation 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.DeviceAuthorizerBase = exports.asyncLocalStorage = exports.getDeviceAuthorizerCredentials = void 0;
|
|
4
|
+
var asyncLocalStorage_1 = require("./asyncLocalStorage");
|
|
5
|
+
Object.defineProperty(exports, "getDeviceAuthorizerCredentials", { enumerable: true, get: function () { return asyncLocalStorage_1.getDeviceAuthorizerCredentials; } });
|
|
6
|
+
Object.defineProperty(exports, "asyncLocalStorage", { enumerable: true, get: function () { return asyncLocalStorage_1.asyncLocalStorage; } });
|
|
7
|
+
var DeviceAuthorizerBase_1 = require("./DeviceAuthorizerBase");
|
|
8
|
+
Object.defineProperty(exports, "DeviceAuthorizerBase", { enumerable: true, get: function () { return DeviceAuthorizerBase_1.DeviceAuthorizerBase; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/authorizers/device-authorizer/index.ts"],"names":[],"mappings":";;;AAAA,yDAG6B;AAF3B,mIAAA,8BAA8B,OAAA;AAC9B,sHAAA,iBAAiB,OAAA;AAGnB,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA","sourcesContent":["export {\n getDeviceAuthorizerCredentials,\n asyncLocalStorage,\n} from \"./asyncLocalStorage\";\n\nexport { DeviceAuthorizerBase } from \"./DeviceAuthorizerBase\";\n\nexport type {\n DeviceAuthorizerParams,\n DeviceAuthorizationResponse,\n} from \"./DeviceAuthorizerParams\";\n"]}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FederatedConnectionAuthorizerBase = void 0;
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
const stable_hash_1 = __importDefault(require("stable-hash"));
|
|
9
|
+
const credentials_1 = require("../../credentials");
|
|
10
|
+
const interrupts_1 = require("../../interrupts");
|
|
11
|
+
const parameters_1 = require("../../parameters");
|
|
12
|
+
const stores_1 = require("../../stores");
|
|
13
|
+
const util_1 = require("../../util");
|
|
14
|
+
const context_1 = require("../context");
|
|
15
|
+
const types_1 = require("../types");
|
|
16
|
+
const asyncLocalStorage_1 = require("./asyncLocalStorage");
|
|
17
|
+
/**
|
|
18
|
+
* Requests authorization to a third party service via Federated Connection.
|
|
19
|
+
*/
|
|
20
|
+
class FederatedConnectionAuthorizerBase {
|
|
21
|
+
constructor(auth0, params) {
|
|
22
|
+
this.auth0 = types_1.Auth0ClientSchema.parse(auth0);
|
|
23
|
+
this.params = {
|
|
24
|
+
credentialsContext: "thread",
|
|
25
|
+
...params,
|
|
26
|
+
};
|
|
27
|
+
const instanceID = this.getInstanceID();
|
|
28
|
+
this.credentialsStore = new stores_1.SubStore(params.store, {
|
|
29
|
+
baseNamespace: [instanceID, "Credentials"],
|
|
30
|
+
getTTL: (credentials) => credentials.expiresIn ? credentials.expiresIn * 1000 : undefined,
|
|
31
|
+
});
|
|
32
|
+
if (typeof params.refreshToken === "undefined" &&
|
|
33
|
+
typeof params.accessToken === "undefined") {
|
|
34
|
+
throw new Error("Either refreshToken or accessToken must be provided to initialize the Authorizer.");
|
|
35
|
+
}
|
|
36
|
+
if (typeof params.accessToken !== "undefined" &&
|
|
37
|
+
typeof params.refreshToken !== "undefined") {
|
|
38
|
+
throw new Error("Only one of refreshToken or accessToken can be provided to initialize the Authorizer.");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
getInstanceID() {
|
|
42
|
+
const props = {
|
|
43
|
+
auth0: this.auth0,
|
|
44
|
+
params: (0, util_1.omit)(this.params, ["store", "refreshToken", "accessToken"]),
|
|
45
|
+
};
|
|
46
|
+
const sh = (0, stable_hash_1.default)(props);
|
|
47
|
+
return crypto_1.default.createHash("MD5").update(sh).digest("hex");
|
|
48
|
+
}
|
|
49
|
+
handleAuthorizationInterrupts(err) {
|
|
50
|
+
throw err;
|
|
51
|
+
}
|
|
52
|
+
validateToken(tokenResponse) {
|
|
53
|
+
var _a;
|
|
54
|
+
const store = asyncLocalStorage_1.asyncLocalStorage.getStore();
|
|
55
|
+
if (!store) {
|
|
56
|
+
throw new Error("The tool must be wrapped with the FederationConnectionAuthorizer.");
|
|
57
|
+
}
|
|
58
|
+
const { scopes, connection } = store;
|
|
59
|
+
if (!tokenResponse) {
|
|
60
|
+
throw new interrupts_1.FederatedConnectionInterrupt(`Authorization required to access the Federated Connection: ${this.params.connection}`, connection, scopes, scopes);
|
|
61
|
+
}
|
|
62
|
+
const currentScopes = ((_a = tokenResponse.scope) !== null && _a !== void 0 ? _a : "").split(" ");
|
|
63
|
+
const missingScopes = scopes.filter((s) => !currentScopes.includes(s));
|
|
64
|
+
store.currentScopes = currentScopes;
|
|
65
|
+
if (missingScopes.length > 0) {
|
|
66
|
+
throw new interrupts_1.FederatedConnectionInterrupt(`Authorization required to access the Federated Connection: ${this.params.connection}. Missing scopes: ${missingScopes.join(", ")}`, connection, scopes, [...currentScopes, ...scopes]);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async getAccessTokenImpl(...toolContext) {
|
|
70
|
+
const store = asyncLocalStorage_1.asyncLocalStorage.getStore();
|
|
71
|
+
if (!store) {
|
|
72
|
+
throw new Error("The tool must be wrapped with the FederationConnectionAuthorizer.");
|
|
73
|
+
}
|
|
74
|
+
const { connection } = store;
|
|
75
|
+
const subjectToken = await this.getRefreshToken(...toolContext);
|
|
76
|
+
if (!subjectToken) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const exchangeParams = {
|
|
80
|
+
grant_type: "urn:auth0:params:oauth:grant-type:token-exchange:federated-connection-access-token",
|
|
81
|
+
client_id: this.auth0.clientId,
|
|
82
|
+
client_secret: this.auth0.clientSecret,
|
|
83
|
+
subject_token_type: "urn:ietf:params:oauth:token-type:refresh_token",
|
|
84
|
+
subject_token: subjectToken,
|
|
85
|
+
connection: connection,
|
|
86
|
+
requested_token_type: "http://auth0.com/oauth/token-type/federated-connection-access-token",
|
|
87
|
+
};
|
|
88
|
+
const res = await fetch(`https://${this.auth0.domain}/oauth/token`, {
|
|
89
|
+
method: "POST",
|
|
90
|
+
headers: { "Content-Type": "application/json" },
|
|
91
|
+
body: JSON.stringify(exchangeParams),
|
|
92
|
+
});
|
|
93
|
+
if (!res.ok) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const tokenResponse = await res.json();
|
|
97
|
+
return tokenResponse;
|
|
98
|
+
}
|
|
99
|
+
async getAccessToken(...toolContext) {
|
|
100
|
+
let tokenResponse;
|
|
101
|
+
if (typeof this.params.refreshToken === "function") {
|
|
102
|
+
tokenResponse = await this.getAccessTokenImpl(...toolContext);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
tokenResponse = await (0, parameters_1.resolveParameter)(this.params.accessToken, toolContext);
|
|
106
|
+
}
|
|
107
|
+
this.validateToken(tokenResponse);
|
|
108
|
+
return (0, credentials_1.tokenSetFromTokenResponse)(tokenResponse);
|
|
109
|
+
}
|
|
110
|
+
async getRefreshToken(...toolContext) {
|
|
111
|
+
return await (0, parameters_1.resolveParameter)(this.params.refreshToken, toolContext);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
*
|
|
115
|
+
* Wraps the execute method of an AI tool to handle Federated Connections authorization.
|
|
116
|
+
*
|
|
117
|
+
* @param getContext - A function that returns the context of the tool execution.
|
|
118
|
+
* @param execute - The tool execute method.
|
|
119
|
+
* @returns The wrapped execute method.
|
|
120
|
+
*/
|
|
121
|
+
protect(getContext, execute) {
|
|
122
|
+
return async (...args) => {
|
|
123
|
+
const context = getContext(...args);
|
|
124
|
+
const asyncStore = {
|
|
125
|
+
context: context,
|
|
126
|
+
scopes: this.params.scopes,
|
|
127
|
+
connection: this.params.connection,
|
|
128
|
+
};
|
|
129
|
+
if (asyncLocalStorage_1.asyncLocalStorage.getStore()) {
|
|
130
|
+
throw new Error("Cannot nest tool calls that require federated connection authorization.");
|
|
131
|
+
}
|
|
132
|
+
return asyncLocalStorage_1.asyncLocalStorage.run(asyncStore, async () => {
|
|
133
|
+
const credentialsNS = (0, context_1.nsFromContext)(this.params.credentialsContext, context);
|
|
134
|
+
try {
|
|
135
|
+
let credentials = await this.credentialsStore.get(credentialsNS, "credential");
|
|
136
|
+
if (!credentials) {
|
|
137
|
+
credentials = await this.getAccessToken(...args);
|
|
138
|
+
await this.credentialsStore.put(credentialsNS, "credential", credentials);
|
|
139
|
+
}
|
|
140
|
+
asyncStore.credentials = credentials;
|
|
141
|
+
return await execute(...args);
|
|
142
|
+
}
|
|
143
|
+
catch (err) {
|
|
144
|
+
if (err instanceof interrupts_1.FederatedConnectionError) {
|
|
145
|
+
const interrupt = new interrupts_1.FederatedConnectionInterrupt(err.message, asyncStore.connection, asyncStore.scopes, asyncStore.scopes);
|
|
146
|
+
return this.handleAuthorizationInterrupts(interrupt);
|
|
147
|
+
}
|
|
148
|
+
if (err instanceof interrupts_1.Auth0Interrupt) {
|
|
149
|
+
return this.handleAuthorizationInterrupts(err);
|
|
150
|
+
}
|
|
151
|
+
throw err;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
exports.FederatedConnectionAuthorizerBase = FederatedConnectionAuthorizerBase;
|
|
158
|
+
//# sourceMappingURL=FederatedConnectionAuthorizerBase.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FederatedConnectionAuthorizerBase.js","sourceRoot":"","sources":["../../../../src/authorizers/federated-connections/FederatedConnectionAuthorizerBase.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,8DAAqC;AAErC,mDAI2B;AAC3B,iDAI0B;AAC1B,iDAAoD;AACpD,yCAAwC;AACxC,qCAAiD;AACjD,wCAA0D;AAC1D,oCAAgE;AAChE,2DAA2E;AAG3E;;GAEG;AAEH,MAAa,iCAAiC;IAQ5C,YACE,KAAiC,EACjC,MAA4D;QAE5D,IAAI,CAAC,KAAK,GAAG,yBAAiB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM,GAAG;YACZ,kBAAkB,EAAE,QAAQ;Y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C5C,MAAM,SAAS,GAAG,IAAI,yCAA4B,CAChD,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,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;AA3ND,8EA2NC","sourcesContent":["import crypto from \"crypto\";\nimport stableHash from \"stable-hash\";\n\nimport {\n TokenResponse,\n TokenSet,\n tokenSetFromTokenResponse,\n} from \"../../credentials\";\nimport {\n Auth0Interrupt,\n FederatedConnectionError,\n FederatedConnectionInterrupt,\n} 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 { FederatedConnectionAuthorizerParams } from \"./FederatedConnectionAuthorizerParams\";\n\n/**\n * Requests authorization to a third party service via Federated Connection.\n */\n\nexport class FederatedConnectionAuthorizerBase<ToolExecuteArgs extends any[]> {\n private readonly auth0: Auth0ClientParams;\n private readonly params: RequireFields<\n FederatedConnectionAuthorizerParams<ToolExecuteArgs>,\n \"credentialsContext\"\n >;\n private readonly credentialsStore: SubStore<TokenSet>;\n\n constructor(\n auth0: Partial<Auth0ClientParams>,\n params: FederatedConnectionAuthorizerParams<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 if (\n typeof params.refreshToken === \"undefined\" &&\n typeof params.accessToken === \"undefined\"\n ) {\n throw new Error(\n \"Either refreshToken or accessToken must be provided to initialize the Authorizer.\"\n );\n }\n\n if (\n typeof params.accessToken !== \"undefined\" &&\n typeof params.refreshToken !== \"undefined\"\n ) {\n throw new Error(\n \"Only one of refreshToken or accessToken can be provided to initialize the Authorizer.\"\n );\n }\n }\n\n private getInstanceID(): string {\n const props = {\n auth0: this.auth0,\n params: omit(this.params, [\"store\", \"refreshToken\", \"accessToken\"]),\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 FederatedConnectionInterrupt(\n `Authorization required to access the Federated Connection: ${this.params.connection}`,\n connection,\n scopes,\n scopes\n );\n }\n\n const currentScopes = (tokenResponse.scope ?? \"\").split(\" \");\n const missingScopes = scopes.filter((s) => !currentScopes.includes(s));\n store.currentScopes = currentScopes;\n\n if (missingScopes.length > 0) {\n throw new FederatedConnectionInterrupt(\n `Authorization required to access the Federated Connection: ${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 const subjectToken = await this.getRefreshToken(...toolContext);\n\n if (!subjectToken) {\n return;\n }\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: \"urn:ietf:params:oauth:token-type:refresh_token\",\n subject_token: subjectToken,\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 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 if (typeof this.params.refreshToken === \"function\") {\n tokenResponse = await this.getAccessTokenImpl(...toolContext);\n } else {\n tokenResponse = await resolveParameter(\n this.params.accessToken!,\n toolContext\n );\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 /**\n *\n * Wraps the execute method of an AI tool to handle Federated Connections 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 federated connection 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 = 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 FederatedConnectionError) {\n const interrupt = new FederatedConnectionInterrupt(\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 return this.handleAuthorizationInterrupts(err);\n }\n throw err;\n }\n });\n };\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FederatedConnectionAuthorizerParams.js","sourceRoot":"","sources":["../../../../src/authorizers/federated-connections/FederatedConnectionAuthorizerParams.ts"],"names":[],"mappings":"","sourcesContent":["import { TokenResponse } from \"../../credentials\";\nimport { AuthorizerToolParameter } from \"../../parameters\";\nimport { Store } from \"../../stores\";\nimport { AuthContext } from \"../context\";\n\nexport type FederatedConnectionAuthorizerParams<ToolExecuteArgs extends any[]> =\n {\n /**\n * The Auth0 refresh token to exchange for an Federated Connection access token.\n */\n refreshToken?: AuthorizerToolParameter<ToolExecuteArgs, string | undefined>;\n\n /**\n * The Federated connection access token if available in the tool context.\n */\n accessToken?: AuthorizerToolParameter<\n ToolExecuteArgs,\n TokenResponse | undefined\n >;\n\n /**\n * The scopes required in the access token of the federated connection provider.\n */\n scopes: string[];\n\n /**\n * The connection name of the federated connection 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,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getCredentialsForConnection = exports.asyncLocalStorage = void 0;
|
|
4
4
|
const node_async_hooks_1 = require("node:async_hooks");
|
|
5
5
|
exports.asyncLocalStorage = new node_async_hooks_1.AsyncLocalStorage();
|
|
6
|
-
const
|
|
6
|
+
const getCredentialsForConnection = () => {
|
|
7
7
|
const store = exports.asyncLocalStorage.getStore();
|
|
8
8
|
if (typeof store === "undefined") {
|
|
9
|
-
throw new Error("The tool must be wrapped with the
|
|
9
|
+
throw new Error("The tool must be wrapped with the withTokenForConnections function.");
|
|
10
10
|
}
|
|
11
|
-
return store === null || store === void 0 ? void 0 : store.
|
|
11
|
+
return store === null || store === void 0 ? void 0 : store.credentials;
|
|
12
12
|
};
|
|
13
|
-
exports.
|
|
13
|
+
exports.getCredentialsForConnection = getCredentialsForConnection;
|
|
14
14
|
//# sourceMappingURL=asyncLocalStorage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asyncLocalStorage.js","sourceRoot":"","sources":["../../../../src/authorizers/federated-connections/asyncLocalStorage.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;
|
|
1
|
+
{"version":3,"file":"asyncLocalStorage.js","sourceRoot":"","sources":["../../../../src/authorizers/federated-connections/asyncLocalStorage.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;AAgCxC,QAAA,iBAAiB,GAAG,IAAI,oCAAiB,EAAqB,CAAC;AAErE,MAAM,2BAA2B,GAAG,GAAG,EAAE;IAC9C,MAAM,KAAK,GAAG,yBAAiB,CAAC,QAAQ,EAAE,CAAC;IAC3C,IAAI,OAAO,KAAK,KAAK,WAAW,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CACb,qEAAqE,CACtE,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,WAAW,CAAC;AAC5B,CAAC,CAAC;AARW,QAAA,2BAA2B,+BAQtC","sourcesContent":["import { AsyncLocalStorage } from \"node:async_hooks\";\n\nimport { TokenSet } from \"../../credentials\";\nimport { ToolCallContext } from \"../context\";\n\nexport type AsyncStorageValue = {\n /**\n * The Federated Connection access token.\n */\n credentials?: TokenSet;\n\n /**\n * The tool execution context.\n */\n context: ToolCallContext;\n\n /**\n * The federated connection name.\n */\n connection: string;\n\n /**\n * The scopes required to access the federated connection.\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\nexport const getCredentialsForConnection = () => {\n const store = asyncLocalStorage.getStore();\n if (typeof store === \"undefined\") {\n throw new Error(\n \"The tool must be wrapped with the withTokenForConnections function.\"\n );\n }\n return store?.credentials;\n};\n"]}
|
|
@@ -1,129 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FederatedConnectionAuthorizerBase = exports.getAccessTokenForConnection = exports.asyncLocalStorage = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
Object.defineProperty(exports, "
|
|
9
|
-
Object.defineProperty(exports, "getAccessTokenForConnection", { enumerable: true, get: function () { return asyncLocalStorage_2.getAccessTokenForConnection; } });
|
|
10
|
-
/**
|
|
11
|
-
* Requests authorization to a third party service via Federated Connection.
|
|
12
|
-
*/
|
|
13
|
-
class FederatedConnectionAuthorizerBase {
|
|
14
|
-
constructor(auth0, params) {
|
|
15
|
-
this.auth0 = auth0;
|
|
16
|
-
this.params = params;
|
|
17
|
-
if (typeof params.refreshToken === "undefined" &&
|
|
18
|
-
typeof params.accessToken === "undefined") {
|
|
19
|
-
throw new Error("Either refreshToken or accessToken must be provided to initialize the Authorizer.");
|
|
20
|
-
}
|
|
21
|
-
if (typeof params.accessToken !== "undefined" &&
|
|
22
|
-
typeof params.refreshToken !== "undefined") {
|
|
23
|
-
throw new Error("Only one of refreshToken or accessToken can be provided to initialize the Authorizer.");
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
handleAuthorizationInterrupts(err) {
|
|
27
|
-
throw err;
|
|
28
|
-
}
|
|
29
|
-
validateToken(tokenResponse) {
|
|
30
|
-
var _a;
|
|
31
|
-
const store = asyncLocalStorage_1.asyncLocalStorage.getStore();
|
|
32
|
-
if (!store) {
|
|
33
|
-
throw new Error("The tool must be wrapped with the FederationConnectionAuthorizer.");
|
|
34
|
-
}
|
|
35
|
-
const { scopes, connection } = store;
|
|
36
|
-
if (!tokenResponse) {
|
|
37
|
-
throw new interrupts_1.FederatedConnectionInterrupt(`Authorization required to access the Federated Connection: ${this.params.connection}`, connection, scopes, scopes);
|
|
38
|
-
}
|
|
39
|
-
const currentScopes = ((_a = tokenResponse.scope) !== null && _a !== void 0 ? _a : "").split(" ");
|
|
40
|
-
const missingScopes = scopes.filter((s) => !currentScopes.includes(s));
|
|
41
|
-
store.currentScopes = currentScopes;
|
|
42
|
-
if (missingScopes.length > 0) {
|
|
43
|
-
throw new interrupts_1.FederatedConnectionInterrupt(`Authorization required to access the Federated Connection: ${this.params.connection}. Missing scopes: ${missingScopes.join(", ")}`, connection, scopes, [...currentScopes, ...scopes]);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
async getAccessTokenImpl(...toolContext) {
|
|
47
|
-
const store = asyncLocalStorage_1.asyncLocalStorage.getStore();
|
|
48
|
-
if (!store) {
|
|
49
|
-
throw new Error("The tool must be wrapped with the FederationConnectionAuthorizer.");
|
|
50
|
-
}
|
|
51
|
-
const { connection } = store;
|
|
52
|
-
const subjectToken = await this.getRefreshToken(...toolContext);
|
|
53
|
-
if (!subjectToken) {
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
const exchangeParams = {
|
|
57
|
-
grant_type: "urn:auth0:params:oauth:grant-type:token-exchange:federated-connection-access-token",
|
|
58
|
-
client_id: this.auth0.clientId,
|
|
59
|
-
client_secret: this.auth0.clientSecret,
|
|
60
|
-
subject_token_type: "urn:ietf:params:oauth:token-type:refresh_token",
|
|
61
|
-
subject_token: subjectToken,
|
|
62
|
-
connection: connection,
|
|
63
|
-
requested_token_type: "http://auth0.com/oauth/token-type/federated-connection-access-token",
|
|
64
|
-
};
|
|
65
|
-
const res = await fetch(`https://${this.auth0.domain}/oauth/token`, {
|
|
66
|
-
method: "POST",
|
|
67
|
-
headers: { "Content-Type": "application/json" },
|
|
68
|
-
body: JSON.stringify(exchangeParams),
|
|
69
|
-
});
|
|
70
|
-
if (!res.ok) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
const tokenResponse = await res.json();
|
|
74
|
-
return tokenResponse;
|
|
75
|
-
}
|
|
76
|
-
async getAccessToken(...toolContext) {
|
|
77
|
-
let tokenResponse;
|
|
78
|
-
if (typeof this.params.refreshToken === "function") {
|
|
79
|
-
tokenResponse = await this.getAccessTokenImpl(...toolContext);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
tokenResponse = await (0, parameters_1.resolveParameter)(this.params.accessToken, toolContext);
|
|
83
|
-
}
|
|
84
|
-
this.validateToken(tokenResponse);
|
|
85
|
-
return tokenResponse;
|
|
86
|
-
}
|
|
87
|
-
async getRefreshToken(...toolContext) {
|
|
88
|
-
return await (0, parameters_1.resolveParameter)(this.params.refreshToken, toolContext);
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
*
|
|
92
|
-
* Wraps the execute method of an AI tool to handle Federated Connections authorization.
|
|
93
|
-
*
|
|
94
|
-
* @param getContext - A function that returns the context of the tool execution.
|
|
95
|
-
* @param execute - The tool execute method.
|
|
96
|
-
* @returns The wrapped execute method.
|
|
97
|
-
*/
|
|
98
|
-
protect(getContext, execute) {
|
|
99
|
-
return async (...args) => {
|
|
100
|
-
const asyncStore = {
|
|
101
|
-
context: await getContext(...args),
|
|
102
|
-
scopes: await (0, parameters_1.resolveParameter)(this.params.scopes, args),
|
|
103
|
-
connection: await (0, parameters_1.resolveParameter)(this.params.connection, args),
|
|
104
|
-
};
|
|
105
|
-
if (asyncLocalStorage_1.asyncLocalStorage.getStore()) {
|
|
106
|
-
throw new Error("Cannot nest tool calls that require federated connection authorization.");
|
|
107
|
-
}
|
|
108
|
-
return asyncLocalStorage_1.asyncLocalStorage.run(asyncStore, async () => {
|
|
109
|
-
try {
|
|
110
|
-
const tokenResponse = await this.getAccessToken(...args);
|
|
111
|
-
asyncStore.accessToken = tokenResponse.access_token;
|
|
112
|
-
return await execute(...args);
|
|
113
|
-
}
|
|
114
|
-
catch (err) {
|
|
115
|
-
if (err instanceof interrupts_1.FederatedConnectionError) {
|
|
116
|
-
const interrupt = new interrupts_1.FederatedConnectionInterrupt(err.message, asyncStore.connection, asyncStore.scopes, asyncStore.scopes);
|
|
117
|
-
return this.handleAuthorizationInterrupts(interrupt);
|
|
118
|
-
}
|
|
119
|
-
if (err instanceof interrupts_1.Auth0Interrupt) {
|
|
120
|
-
return this.handleAuthorizationInterrupts(err);
|
|
121
|
-
}
|
|
122
|
-
throw err;
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
exports.FederatedConnectionAuthorizerBase = FederatedConnectionAuthorizerBase;
|
|
4
|
+
var asyncLocalStorage_1 = require("./asyncLocalStorage");
|
|
5
|
+
Object.defineProperty(exports, "asyncLocalStorage", { enumerable: true, get: function () { return asyncLocalStorage_1.asyncLocalStorage; } });
|
|
6
|
+
Object.defineProperty(exports, "getAccessTokenForConnection", { enumerable: true, get: function () { return asyncLocalStorage_1.getCredentialsForConnection; } });
|
|
7
|
+
var FederatedConnectionAuthorizerBase_1 = require("./FederatedConnectionAuthorizerBase");
|
|
8
|
+
Object.defineProperty(exports, "FederatedConnectionAuthorizerBase", { enumerable: true, get: function () { return FederatedConnectionAuthorizerBase_1.FederatedConnectionAuthorizerBase; } });
|
|
129
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/authorizers/federated-connections/index.ts"],"names":[],"mappings":";;;AAAA,iDAI0B;AAC1B,iDAA6E;AAE7E,2DAA2E;AAI3E,yDAG6B;AAF3B,sHAAA,iBAAiB,OAAA;AACjB,gIAAA,2BAA2B,OAAA;AAc7B;;GAEG;AACH,MAAa,iCAAiC;IAC5C,YACmB,KAIhB,EACO,MAA4D;QALnD,UAAK,GAAL,KAAK,CAIrB;QACO,WAAM,GAAN,MAAM,CAAsD;QAEpE,IACE,OAAO,MAAM,CAAC,YAAY,KAAK,WAAW;YAC1C,OAAO,MAAM,CAAC,WAAW,KAAK,WAAW,EACzC,CAAC;YACD,MAAM,IAAI,KAAK,CACb,mFAAmF,CACpF,CAAC;QACJ,CAAC;QAED,IACE,OAAO,MAAM,CAAC,WAAW,KAAK,WAAW;YACzC,OAAO,MAAM,CAAC,YAAY,KAAK,WAAW,EAC1C,CAAC;YACD,MAAM,IAAI,KAAK,CACb,uFAAuF,CACxF,CAAC;QACJ,CAAC;IACH,CAAC;IAES,6BAA6B,CAAC,GAAmB;QACzD,MAAM,GAAG,CAAC;IACZ,CAAC;IAES,aAAa,CAAC,aAA6B;;QACnD,MAAM,KAAK,GAAG,qCAAiB,CAAC,QAAQ,EAAE,CAAC;QAC3C,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CACb,mEAAmE,CACpE,CAAC;QACJ,CAAC;QAED,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;QAErC,IAAI,CAAC,aAAa,EAAE,CAAC;YACnB,MAAM,IAAI,yCAA4B,CACpC,8DAA8D,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,EACt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AE,MAAM,IAAA,6BAAgB,EAAC,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC;gBACxD,UAAU,EAAE,MAAM,IAAA,6BAAgB,EAAC,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE,IAAI,CAAC;aACjE,CAAC;YAEF,IAAI,qCAAiB,CAAC,QAAQ,EAAE,EAAE,CAAC;gBACjC,MAAM,IAAI,KAAK,CACb,yEAAyE,CAC1E,CAAC;YACJ,CAAC;YAED,OAAO,qCAAiB,CAAC,GAAG,CAAC,UAAU,EAAE,KAAK,IAAI,EAAE;gBAClD,IAAI,CAAC;oBACH,MAAM,aAAa,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,GAAG,IAAI,CAAC,CAAC;oBACzD,UAAU,CAAC,WAAW,GAAG,aAAc,CAAC,YAAY,CAAC;oBACrD,OAAO,MAAM,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC;gBAChC,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,IAAI,GAAG,YAAY,qCAAwB,EAAE,CAAC;wBAC5C,MAAM,SAAS,GAAG,IAAI,yCAA4B,CAChD,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,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;AAnLD,8EAmLC","sourcesContent":["import {\n Auth0Interrupt,\n FederatedConnectionError,\n FederatedConnectionInterrupt,\n} from \"../../interrupts\";\nimport { AuthorizerToolParameter, resolveParameter } from \"../../parameters\";\nimport { TokenResponse } from \"../../TokenResponse\";\nimport { asyncLocalStorage, AsyncStorageValue } from \"./asyncLocalStorage\";\n\nexport type { AsyncStorageValue } from \"./asyncLocalStorage\";\n\nexport {\n asyncLocalStorage,\n getAccessTokenForConnection,\n} from \"./asyncLocalStorage\";\n\nexport type FederatedConnectionAuthorizerParams<ToolExecuteArgs extends any[]> =\n {\n refreshToken?: AuthorizerToolParameter<ToolExecuteArgs, string | undefined>;\n accessToken?: AuthorizerToolParameter<\n ToolExecuteArgs,\n TokenResponse | undefined\n >;\n scopes: AuthorizerToolParameter<ToolExecuteArgs, string[]>;\n connection: AuthorizerToolParameter<ToolExecuteArgs, string>;\n };\n\n/**\n * Requests authorization to a third party service via Federated Connection.\n */\nexport class FederatedConnectionAuthorizerBase<ToolExecuteArgs extends any[]> {\n constructor(\n private readonly auth0: {\n domain: string;\n clientId: string;\n clientSecret: string | undefined;\n },\n private params: FederatedConnectionAuthorizerParams<ToolExecuteArgs>\n ) {\n if (\n typeof params.refreshToken === \"undefined\" &&\n typeof params.accessToken === \"undefined\"\n ) {\n throw new Error(\n \"Either refreshToken or accessToken must be provided to initialize the Authorizer.\"\n );\n }\n\n if (\n typeof params.accessToken !== \"undefined\" &&\n typeof params.refreshToken !== \"undefined\"\n ) {\n throw new Error(\n \"Only one of refreshToken or accessToken can be provided to initialize the Authorizer.\"\n );\n }\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 FederatedConnectionInterrupt(\n `Authorization required to access the Federated Connection: ${this.params.connection}`,\n connection,\n scopes,\n scopes\n );\n }\n\n const currentScopes = (tokenResponse.scope ?? \"\").split(\" \");\n const missingScopes = scopes.filter((s) => !currentScopes.includes(s));\n store.currentScopes = currentScopes;\n\n if (missingScopes.length > 0) {\n throw new FederatedConnectionInterrupt(\n `Authorization required to access the Federated Connection: ${\n this.params.connection\n }. 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 const subjectToken = await this.getRefreshToken(...toolContext);\n\n if (!subjectToken) {\n return;\n }\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: \"urn:ietf:params:oauth:token-type:refresh_token\",\n subject_token: subjectToken,\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 return;\n }\n\n const tokenResponse: TokenResponse = await res.json();\n return tokenResponse;\n }\n\n protected async getAccessToken(\n ...toolContext: ToolExecuteArgs\n ): Promise<TokenResponse | undefined> {\n let tokenResponse: TokenResponse | undefined;\n if (typeof this.params.refreshToken === \"function\") {\n tokenResponse = await this.getAccessTokenImpl(...toolContext);\n } else {\n tokenResponse = await resolveParameter(\n this.params.accessToken!,\n toolContext\n );\n }\n this.validateToken(tokenResponse);\n return tokenResponse;\n }\n\n protected async getRefreshToken(...toolContext: ToolExecuteArgs) {\n return await resolveParameter(this.params.refreshToken, toolContext);\n }\n\n /**\n *\n * Wraps the execute method of an AI tool to handle Federated Connections 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: (...args: ToolExecuteArgs) => any,\n execute: (...args: ToolExecuteArgs) => any\n ): (...args: ToolExecuteArgs) => any {\n return async (...args: ToolExecuteArgs) => {\n const asyncStore: AsyncStorageValue<any> = {\n context: await getContext(...args),\n scopes: await resolveParameter(this.params.scopes, args),\n connection: await resolveParameter(this.params.connection, args),\n };\n\n if (asyncLocalStorage.getStore()) {\n throw new Error(\n \"Cannot nest tool calls that require federated connection authorization.\"\n );\n }\n\n return asyncLocalStorage.run(asyncStore, async () => {\n try {\n const tokenResponse = await this.getAccessToken(...args);\n asyncStore.accessToken = tokenResponse!.access_token;\n return await execute(...args);\n } catch (err) {\n if (err instanceof FederatedConnectionError) {\n const interrupt = new FederatedConnectionInterrupt(\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 return this.handleAuthorizationInterrupts(err);\n }\n throw err;\n }\n });\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/authorizers/federated-connections/index.ts"],"names":[],"mappings":";;;AAEA,yDAG6B;AAF3B,sHAAA,iBAAiB,OAAA;AACjB,gIAAA,2BAA2B,OAA+B;AAG5D,yFAAwF;AAA/E,sJAAA,iCAAiC,OAAA","sourcesContent":["export type { AsyncStorageValue } from \"./asyncLocalStorage\";\n\nexport {\n asyncLocalStorage,\n getCredentialsForConnection as getAccessTokenForConnection,\n} from \"./asyncLocalStorage\";\n\nexport { FederatedConnectionAuthorizerBase } from \"./FederatedConnectionAuthorizerBase\";\n\nexport type { FederatedConnectionAuthorizerParams } from \"./FederatedConnectionAuthorizerParams\";\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/authorizers/index.ts"],"names":[],"mappings":"","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/authorizers/index.ts"],"names":[],"mappings":"","sourcesContent":["export type { ContextGetter } from \"./context\";\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Auth0PublicClientSchema = exports.Auth0ClientSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.Auth0ClientSchema = zod_1.z.object({
|
|
6
|
+
domain: zod_1.z.string().default(() => process.env.AUTH0_DOMAIN),
|
|
7
|
+
clientId: zod_1.z.string().default(() => process.env.AUTH0_CLIENT_ID),
|
|
8
|
+
clientSecret: zod_1.z.string().default(() => process.env.AUTH0_CLIENT_SECRET),
|
|
9
|
+
});
|
|
10
|
+
exports.Auth0PublicClientSchema = zod_1.z.object({
|
|
11
|
+
domain: zod_1.z.string().default(() => process.env.AUTH0_DOMAIN),
|
|
12
|
+
clientId: zod_1.z.string().default(() => process.env.AUTH0_CLIENT_ID),
|
|
13
|
+
});
|
|
14
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/authorizers/types.ts"],"names":[],"mappings":";;;AAEA,6BAAwB;AAcX,QAAA,iBAAiB,GAAG,OAAC,CAAC,MAAM,CAAC;IACxC,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,YAAa,CAAC;IAC3D,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,eAAgB,CAAC;IAChE,YAAY,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,mBAAoB,CAAC;CACzE,CAAC,CAAC;AAEU,QAAA,uBAAuB,GAAG,OAAC,CAAC,MAAM,CAAC;IAC9C,MAAM,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,YAAa,CAAC;IAC3D,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,eAAgB,CAAC;CACjE,CAAC,CAAC","sourcesContent":["import { AuthenticationClientOptions } from \"auth0\";\nimport * as jose from \"jose\";\nimport { z } from \"zod\";\n\nexport type AuthParams = {\n allowed?: boolean;\n accessToken?: string;\n claims?: jose.JWTPayload;\n};\n\nexport type ToolWithAuthHandler<I, O, C> = (\n authParams: AuthParams,\n input: I,\n config?: C\n) => Promise<O>;\n\nexport const Auth0ClientSchema = z.object({\n domain: z.string().default(() => process.env.AUTH0_DOMAIN!),\n clientId: z.string().default(() => process.env.AUTH0_CLIENT_ID!),\n clientSecret: z.string().default(() => process.env.AUTH0_CLIENT_SECRET!),\n});\n\nexport const Auth0PublicClientSchema = z.object({\n domain: z.string().default(() => process.env.AUTH0_DOMAIN!),\n clientId: z.string().default(() => process.env.AUTH0_CLIENT_ID!),\n});\n\nexport type Auth0ClientParams = z.infer<typeof Auth0ClientSchema>;\nexport type Auth0PublicClientParams = z.infer<typeof Auth0PublicClientSchema>;\n\nexport type AuthorizerParams = Pick<\n AuthenticationClientOptions,\n \"domain\" | \"clientId\" | \"clientSecret\"\n>;\n\nexport type OnAuthorizationRequest = \"block\" | \"interrupt\";\n"]}
|
package/dist/cjs/credentials.js
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tokenSetFromTokenResponse = void 0;
|
|
4
|
+
const tokenSetFromTokenResponse = (tr) => {
|
|
5
|
+
var _a;
|
|
6
|
+
return {
|
|
7
|
+
tokenType: (_a = tr.token_type) !== null && _a !== void 0 ? _a : "Bearer",
|
|
8
|
+
accessToken: tr.access_token,
|
|
9
|
+
idToken: tr.id_token,
|
|
10
|
+
refreshToken: tr.refresh_token,
|
|
11
|
+
expiresIn: tr.expires_in,
|
|
12
|
+
scopes: tr.scope ? tr.scope.split(" ") : undefined,
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
exports.tokenSetFromTokenResponse = tokenSetFromTokenResponse;
|
|
3
16
|
//# sourceMappingURL=credentials.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/credentials.ts"],"names":[],"mappings":"","sourcesContent":["export
|
|
1
|
+
{"version":3,"file":"credentials.js","sourceRoot":"","sources":["../../src/credentials.ts"],"names":[],"mappings":";;;AAoCO,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;KACnD,CAAC;AACJ,CAAC,CAAC;AATW,QAAA,yBAAyB,6BASpC","sourcesContent":["export 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};\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 */\nexport interface TokenSet {\n scopes?: string[];\n idToken?: string;\n refreshToken?: string;\n\n expiresIn?: number;\n accessToken: string;\n tokenType: string;\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 };\n};\n"]}
|
package/dist/cjs/index.js
CHANGED
|
@@ -14,7 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./authorizers/device-authorizer"), exports);
|
|
18
17
|
__exportStar(require("./errors"), exports);
|
|
19
18
|
__exportStar(require("./authorizers/fga/fga-filter"), exports);
|
|
20
19
|
__exportStar(require("./authorizers/fga/fga-client"), exports);
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAEA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAEA,2CAAyB;AACzB,+DAA6C;AAC7C,+DAA6C;AAC7C,+CAA6B","sourcesContent":["export type { AuthParams, AuthorizerParams } from \"./authorizers/types\";\nexport type * from \"./credentials\";\nexport * from \"./errors\";\nexport * from \"./authorizers/fga/fga-filter\";\nexport * from \"./authorizers/fga/fga-client\";\nexport * from \"./parameters\";\n"]}
|