Pipeline 函数

初始化

使用以下接口时,请先完成初始化工作,请参考:

pageSDK for Node.js

Pipeline 函数类型

目前共支持三种类型的 pipeline 函数:

名称

说明

Pre-Register Pipeline

注册前 Pipeline,会在每次用户正式进入注册逻辑前触发,开发者可用此实现注册邮箱白名单、注册 IP 白名单等功能。

Post-Register Pipeline

注册后Pipeline, 会在每次用户完成注册逻辑 (但还未保存至数据库) 之后触发,开发者可用此实现往数据库写入自定义 metadata 、新用户注册 webhook 通知等功能。

Post-Authentication Pipeline

认证后 Pipeline 会在每次用户完成认证之后触发,开发者可用此实现往 token 加入自定义字段等功能。

创建 Pipeline 函数

一个函数也叫 Rule(规则),所以 SDK 命名方式如 addRule、updateRule 等。

Authing.pipeline.createRule(input)

  • 参数

    • input <object>

      • name: <string> 名称、必填。

      • type: <string> 类型,必填。可选值见 Pipeline 函数类型

      • code: <string> 代码,必填。见 Pipeline 函数开发指南

      • description: <string> 描述信息,可选。

  • 使用方法

const rule = await authing.pipeline.createRule({
  name: "注册白名单",
  code: "------函数代码------",
  type: "PRE_REGISTER"
})
  • 返回数据

    • _id: Rule 函数 ID

    • enabled: 是否开启。

{
    _id: "5e35841c691196a1ccb5b6f7",
    name: "注册白名单",
    description: "",
    type: "PRE_REGISTER",
    enabled: true,
    faasUrl: "云函数链接",
    code: "代码",
    createdAt: '2020-02-16T20:47:04+08:00',
    updatedAt: '2020-02-16T20:47:04+08:00'
}

修改 Pipeline 函数

一个用户池最多创建 50 个 Pipeline 函数。

Authing.pipeline.updateRule(input)

  • 参数

    • input <object>

      • _id: <string> Rule 函数 ID,必填。

      • name: <string> 名称,选填。

      • type: <string> 类型,选填。可选值见 Pipeline 函数类型

      • code: <string> 代码,选填。见 Pipeline 函数开发指南

      • description: <string> 描述信息,选填。

      • enabled: <string> 是否开启,选填。

  • 使用方法

// 停用此函数
const rule = await authing.pipeline.updateRule({
  _id: "5e35841c691196a1ccb5b6f7",
  enabled: false
})
  • 返回数据

{
    _id: "5e35841c691196a1ccb5b6f7",
    name: "注册白名单",
    description: "",
    type: "PRE_REGISTER",
    enabled: false,
    faasUrl: "云函数链接",
    code: "代码",
    createdAt: '2020-02-16T20:47:04+08:00',
    updatedAt: '2020-02-16T20:47:04+08:00'
}

根据 id 查询 Pipeline 函数

Authing.pipeline.ruleById(_id)

  • 参数

    • _id <string> 必填。

  • 使用方法

const rule = await authing.pipeline.ruleById("5e35841c691196a1ccb5b6f7")
  • 返回数据

{
    _id: "5e35841c691196a1ccb5b6f7",
    name: "注册白名单",
    description: "",
    type: "PRE_REGISTER",
    enabled: false,
    faasUrl: "云函数链接",
    code: "代码",
    createdAt: '2020-02-16T20:47:04+08:00',
    updatedAt: '2020-02-16T20:47:04+08:00'
}

删除 Pipeline 函数

Authing.pipeline.deleteById(_id)

  • 参数

    • _id <string> 函数 ID, 必填。

  • 使用方法

const res = await authing.pipeline.deleteById("5e35841c691196a1ccb5b6f7")
  • 返回数据

    • code: 为 200 时表示成功,其他 code 含义见下文错误代码列表

{
    code: 200,
    message: "操作成功!"
}

查询用户池 Pipeline 函数列表

Authing.pipeline.all()

  • 参数: 无

  • 使用方法

const rules = await authing.pipeline.all()
  • 返回数据

    • totalCount: 总数

    • list: 函数列表

{
    totalCount: 1,
    list: [
        {
            _id: "5e35841c691196a1ccb5b6f7",
            name: "注册白名单",
            description: "",
            type: "PRE_REGISTER",
            enabled: false,
            faasUrl: "云函数链接",
            code: "代码",
            createdAt: '2020-02-16T20:47:04+08:00',
            updatedAt: '2020-02-16T20:47:04+08:00'
        }
    ]
}

设置环境变量

Authing.pipeline.setEnv()

  • 参数

    • key: <string> 必填。

    • value: <string> 必填。

  • 使用方法

const env = await authing.pipeline.setEnv("KEY1","VALUE1")
  • 返回数据:返回最新的所有环境变量列表。

{
    totalCount: 1,
    list: [
        {
            key: "KEY1",
            value: "VALUE1"
        }
    ]
}

删除环境变量

Authing.pipeline.removeEnv(key)

  • 参数

    • key <string> 必填。

  • 使用方法

const env = await authing.pipeline.setEnv("KEY1")
  • 返回数据:返回最新的所有环境变量列表。

{
    totalCount: 0,
    list: []
}

查询用户池环境变量列表

环境变量的 scope 为整个用户池,用户池内的所有 Pipeline 函数共用所有环境变量。

Authing.pipeline.env()

  • 参数:无。

  • 使用方法

const env = await authing.pipeline.env()
  • 返回数据

{
    totalCount: 1,
    list: [
        {
            key: "KEY1",
            value: "VALUE1"
        }
    ]
}

Last updated