1.0.26 • Published 6 years ago

nodebase-authorize-sdk v1.0.26

Weekly downloads
111
License
-
Repository
github
Last release
6 years ago

Authorize SDK

权限收敛平台的SDK

Install

npm install --save nodebase-authorize-sdk

Usage

const SDK = require('nodebase-authorize-sdk');
const sdk = new SDK(appid, appsercret, apphost);

Arguments:

  • appid string 平台提供的序列号
  • appsercret string 平台提供的密钥
  • apphost string 平台的域名地址 默认http://authorize.u51-inc.com:8080(测试环境)

encodeSign

加密签名

sdk.encodeSign({
  a: 1,
  b: 2
})

decodeSign

解密签名

sdk.encodeSign({
  a: 1,
  b: 2,
  key: 'sadfasdfasdf',
  sign: 'SDJFENKNAKFNJKHJASSADF'
})

如果不符合签名,会抛出错误。

login

本服务登入到平台服务

await sdk.login();

fetch

fetch(url, data, headers)请求平台服务的基础方法

await this.fetch('/auth/configs', {
  token: this.token,
  key: this.appid
}, {
  headers: {
    ...
  }
});

Arguments:

  • url string 请求地址
  • data string 请求参数
  • headers object 请求的额外参数,比如头部信息

userLogin

用户登录

await sdk.userLogin(username, password, finger, ip)

Arguments:

  • username string 用户名
  • password string 密码
  • finger string 设备指纹
  • ip string client ip

注意:指纹数据请使用 npm install --save fingerprintjs2 模块,在前端处理传递到后端。

userLogout

用户退出登录

await sdk.userLogout(finger, ip)

Arguments:

  • finger string 设备指纹
  • ip string client ip

userStatus

检测用户登入状态

await sdk.userStatus(finger, ip)

Arguments:

  • finger string 设备指纹
  • ip string client ip

getUserInfo

批量获取用户详细信息(涉及用户隐私)

await sdk.getUserInfo([
  'shenyunjie',
  'liubin'
])

参数为用户域账号列表

Use in nodebase

config/plugins.js

"authorize-sdk": {
  enable: true,
  package: 'nodebase-authorize-sdk',
  dependencies: ['ymer']
}

config/plugin.${env}.js

"authorize-sdk": {
  authorize: {
    host: "http://authorize.u51-inc.com:8080",
    key: '${appid}',
    secret: '${appsecret}'
  }
}

Nodebase#service

  • encode
  • decode
  • fetch
  • userLogin
  • userLogout
  • userStatus
  • getUserInfo
  • myRights
app.service.sdk.encode = sdk.encodeSign.bind(sdk);
app.service.sdk.decode = sdk.decodeSign.bind(sdk);
app.service.sdk.fetch = sdk.fetch.bind(sdk);
app.service.sdk.userLogin = sdk.userLogin.bind(sdk);
app.service.sdk.userLogout = sdk.userLogout.bind(sdk);
app.service.sdk.userStatus = sdk.userStatus.bind(sdk);
app.service.sdk.getUserInfo = sdk.getUserInfo.bind(sdk);

这里特别将一下如何获得我所具有的所有权限标识,我们通过app.service.sdk.myRights(me)方法获得。

me为该用户的详细信息。必须具备:

  • Emp_Account
  • Emp_Dep_Chain
  • Job_Id

存在3个数据即可获得

Nodebase#middleware

  • userStatus 用户状态中间件
  • allow 权限过滤中间件

userStatus

用来直接判断用户的登录状态,无需额外操作。判断成功登录后,会将当前用户信息存放在ctx.me上面,开发者可以自行接入中间件处理这个数据。

const resolve = async (ctx, next) => {
  console.log(ctx.me);
  await next();
}
router.use('/auth', app.middleware.sdk.userStatus, resolve);

allow

用来处理当前请求是否能够通过平台设置的权限而进行之后的行为操作。

router.get(
  '/auth/deal', 
  app.middleware.sdk.allow('superadmin', 'editable', 'deleteable'),
  app.controller.doing.with.actions
);

Nodebase#webhook

我们可以在平台上设置webhook来处理数据的变动。

通常我们通过await app.service.realodAuthorizeRightsData()方法来自动更新平台配置到本地。

webhook都是以post方式提交给服务器的,所以你需要定义好自定的api接口以便保障平台能够顺利访问到。

1.0.26

6 years ago

1.0.25

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.22

6 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago