0.1.13 • Published 6 years ago

zhike-jwt v0.1.13

Weekly downloads
91
License
-
Repository
-
Last release
6 years ago

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.

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

6 years ago

0.1.11

6 years ago

0.1.10

6 years ago

0.1.9

6 years ago

0.1.8

6 years ago

0.1.7

6 years ago

0.1.6

6 years ago

0.1.5

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago