UiPath Documentation
functions
2.2610
true
函数用户指南
  • 概述
    • 关于函数
    • 许可
  • JavaScript 函数
    • 入门指南
    • 构建 JavaScript 函数
    • HTTP 触发器和路由
    • 函数上下文
    • 访问平台服务
    • 测试和调试
  • Python 函数
  • 部署并运行

函数上下文

运行时传递给每个 JavaScript 函数处理程序的身份、平台坐标和请求数据。

每个处理程序都会收到一个上下文对象作为其第二个参数。它包含函数的调用者、函数自己的平台身份以及出站平台调用的发送位置,因此不必将这些内容作为输入传递。

handler: async (input, ctx) => {
  ctx.user?.accessToken     // the caller's OAuth token
  ctx.user?.sub             // the caller's user id
  ctx.robot?.accessToken    // the function's own platform token
  ctx.robot?.key            // the robot key
  ctx.platform?.baseUrl     // e.g. "https://<automation-suite-fqdn>"
  ctx.platform?.orgId       // organization id
  ctx.platform?.tenantId    // tenant id
  ctx.platform?.folderKey   // folder of the invocation, if any
  ctx.params                // path parameters, as strings
  ctx.headers               // request headers, lowercase keys
}
handler: async (input, ctx) => {
  ctx.user?.accessToken     // the caller's OAuth token
  ctx.user?.sub             // the caller's user id
  ctx.robot?.accessToken    // the function's own platform token
  ctx.robot?.key            // the robot key
  ctx.platform?.baseUrl     // e.g. "https://<automation-suite-fqdn>"
  ctx.platform?.orgId       // organization id
  ctx.platform?.tenantId    // tenant id
  ctx.platform?.folderKey   // folder of the invocation, if any
  ctx.params                // path parameters, as strings
  ctx.headers               // request headers, lowercase keys
}

两个身份​

一个函数每次调用时都会被赋予两个身份,在这两种身份之间进行选择即为安全决策。

ctx.userctx.robot
所有权归属调用函数的调用者函数自己的平台标识
适用的权限调用者自己的函数的服务帐户
用于代表已登录的用户执行操作正在读取调用者不得直接访问的资源

ctx.user.accessToken 适用于调用者希望仅查看其自身权限允许的内容的情况。当函数必须访问调用者无法访问的内容(例如,受限文件夹中的凭据)时,适用 ctx.robot.accessToken。请参阅访问平台服务。

备注:

ctx.robot is the more privileged identity. A handler that reads a caller-supplied resource name is acting as a deputy for the caller's request with the function's own privileges. Fetching must be constrained to a fixed set in code.

平台坐标​

ctx.platform 为出站平台调用提供 baseUrl、orgId 和 tenantId。这些来自运行时,而非调用者,因此请求无法重定向函数将其流量发送到的位置,并且绝不会将其接受为输入字段。

ctx.platform is null unless all three are available. folderKey can be null on its own, for a folderless invocation.

可用位置​

HTTP 触发器作业本地 serve
ctx.user调用者的身份无调用者身份当请求包含持有者令牌时显示
ctx.robot是是null
ctx.platform是是仅适用于设置了 UIPATH_BASE_URL、UIPATH_ORG_ID 和 UIPATH_TENANT_ID 的情况
ctx.params, ctx.headers是空 — 没有 HTTP 请求是

由于 ctx.robot 在本地为 null,因此需要平台令牌的代码应回退到环境变量,以进行本地开发:

const token = ctx.robot?.accessToken || process.env["UIPATH_ACCESS_TOKEN"] || "";
const token = ctx.robot?.accessToken || process.env["UIPATH_ACCESS_TOKEN"] || "";

后续步骤​

  • 两个身份​
  • 平台坐标​
  • 可用位置​
  • 后续步骤​

此页面有帮助吗?

连接

需要帮助? 支持(opens in new window)

想要了解详细内容? UiPath Academy(opens in new window)

有问题? UiPath 论坛(opens in new window)

保持更新