# zhike-jwt

> ## Dependencies

Latest version **0.1.13** (published 2018-03-30) · 0 weekly downloads

## Install

```sh
npm install zhike-jwt
pnpm add zhike-jwt
yarn add zhike-jwt
bun add zhike-jwt
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.13 |
| Published | 2018-03-30 |
| First published | 2017-08-11 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 20.3 KB |
| Known vulnerabilities | 0 (+4 in 2 direct dependencies) |
| Install scripts | no |
| Author | Quan |
| Maintainers | zhiker |
| Keywords | jwt |

## Links

- npm: https://www.npmjs.com/package/zhike-jwt
- npm.io page: https://npm.io/package/zhike-jwt

## Dependencies (7)

- [zipkin](https://npm.io/package/zipkin.md) ^0.9.0
- [request](https://npm.io/package/request.md) ^2.81.0
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^7.4.2
- [request-promise](https://npm.io/package/request-promise.md) ^4.2.1
- [zipkin-context-cls](https://npm.io/package/zipkin-context-cls.md) ^0.6.1
- [zipkin-transport-http](https://npm.io/package/zipkin-transport-http.md) ^0.9.0
- [zipkin-instrumentation-request](https://npm.io/package/zipkin-instrumentation-request.md) ^0.9.0

## Alternatives

- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 0.1.13 (latest) — 2018-03-30
- 0.1.11 — 2018-03-27
- 0.1.10 — 2018-01-25
- 0.1.9 — 2018-01-24
- 0.1.8 — 2018-01-24
- 0.1.7 — 2018-01-18
- 0.1.6 — 2018-01-18
- 0.1.5 — 2018-01-12
- 0.1.4 — 2018-01-12
- 0.1.3 — 2017-12-28
- 0.1.2 — 2017-12-28
- 0.1.1 — 2017-12-23
- 0.1.0 — 2017-10-26
- 0.0.9 — 2017-10-23
- 0.0.8 — 2017-10-19
- … 7 more at https://npm.io/package/zhike-jwt/versions

## README

# Node.js SDK for Zhike JWT authentication

## Dependencies

What you need to run this app:

* [Node.Js](https://nodejs.org)
* [node-jsonwebtoken](https://github.com/auth0/node-jsonwebtoken)

## 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

```javascript
{
	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

```javascript
{
    "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

```javascript
    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](http://getblimp.github.io/django-rest-framework-jwt/).

|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|

---
_Source: https://npm.io/package/zhike-jwt · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
