zhike-jwt

0.1.13 • Public • Published

Node.js SDK for Zhike JWT authentication

Dependencies

What you need to run this app:

Install

npm install zhike-jwt

Usage

const JwtHandler = require('zhike-jwt');

let handler = new JwtHandler('./example.conf.js'); // JwtHandler also accept a js object
let promise = handler.get_user_permission('zhangsan@innobuddy.com');
promise.then((perms) => console.log(perms);

API

Constructor method

JwtHandler(path_to_conf_file)

(Synchronous) Returns the Jwt handler instance

arguments

path_to_conf_file is the path to configure file. The path can be an absolute path or a relative path. If it is a relative path, it must begin with "./", for example "./myconf.js".

Functional methods

user permission query

function definition

get_user_permission(email)

(Asynchronous) Returns user permissions in an object, and the object looks like

{
    code: 0, 
    data: [perm1, perm2, ...]
}
arguments

email The email of the target user. (Note, currently we support email only)

organization query

function definition

get_organization_tree(organizationId)

(Asynchronous) Returns organization tree in an object, and the object looks like

{
    "id": 1,
    "name": "北京新中关学习中心",
    "parent_id": 1395,
    "type": "机构",
    "children": []
}

advanced query

function definition

query(options) (Asynchronous) Returns query result in an object. How the object looks like depends on the query uri, for example

    let options = {
      method: 'POST',
      uri: `${handler.serverUrl}/api/staff/get_staff_by_userids/`,
      body: {
        ids: [41992,41974]
      },
      json: true
    }
    let staff = await handler.query(options);
arguments

options is the query options object, it contains not only the real parameter in body attribute, but also query method and the uri, like options variable in the above example.

Configure file

The configure file is a js file, see example.conf.js for example. The entries are list below, more details can be found at here.

Entry Description
issuer A string that will be checked against the iss field of the token, see jwt document for details
serverUrl The url of AAA service
privateKey The private key used to sign jwt signature, see jwt document for details
publicKey The public key used to verify jwt signature. It should be signed by CA, see jwt document for details
disableTracing 是否禁止zipkin traceing,缺省为否
zipkinServiceUrl zipkin服务url,确实了测试环境zipkin url
serviceName 本服务名,缺省为jwt_client,应设置为当前使用jwt的服务名,如smartstudy-backend

Readme

Keywords

Package Sidebar

Install

npm i zhike-jwt

Weekly Downloads

3

Version

0.1.13

License

none

Unpacked Size

20.8 kB

Total Files

14

Last publish

Collaborators

  • zhiker