npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nodebase-authorize-sdk

v1.0.26

Published

权限收敛平台的SDK

Downloads

11

Readme

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接口以便保障平台能够顺利访问到。