# ujwt

> µJwt - a small JWT token lib (links to @svenardo/µJwt)

Latest version **1.0.4** (published 2018-09-23) · Apache-2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install ujwt
pnpm add ujwt
yarn add ujwt
bun add ujwt
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2018-09-23 |
| First published | 2018-09-21 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 14.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sven Anders Robbestad |
| Maintainers | svenanders |
| Keywords | jwt |

## Links

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

## Dependencies (1)

- [@svenardo/ujwt](https://npm.io/package/@svenardo/ujwt.md) ^0.2.10

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

- 1.0.4 (latest) — 2018-09-23
- 1.0.3 — 2018-09-21
- 1.0.1 — 2018-09-21
- 1.0.0 — 2018-09-21

## README

# µJwt

### Motivation

* Create a micro JWT lib that does just the bare essentials in accordance with JWT spec
* Provide a server implementation that authenticates the user 

## Usage

```
// Generate token
const claims = {
  "key": "value"
};
const token = Sign(alg, key, claims);

// Verify token
const verify = Verify(alg, key, token);
```

## Example implementations

### Algorithm when not using an external authentication service

##### Generate Message and Signature
```
client generates message
  append user info to message
  client generates signature
    signature generation appends expire time to message
    sign header.message according to JWT spec with HMAC SHA256 using a shared secret 
      return header.message.signature
```
The result is a header.message.signature that can be used in a capability based link

Example token (_header.message.signature_) using password *big-secret*:
```
eyJ0eXAiOiJKV1QiLA0KICJhbGciOiJIUzI1NiJ9.eyJmaWxlIjoiL3Jlc291cmNlLzIwMTgvMDYvMTEvYXNuZDA5MTJubnNudWM5ODIubXA0In0.-yr9RlB9gzVSV8WyKSx5gmp6sjnS9inpDBN7413jdVU=
```

## Strategies

##### Handling /resource/message.signature
```
server receives request
verify that signature and message matches using HMAC SHA256 and the same shared secret 
verify that current time is less than expire time
if valid
 redirect to file
else 
 redirect to 410 Gone
```


### Algorithm when using an external Active Directory

##### /sign
```
send the OIDC bearer token provided by the ADFS server and message to signing server
if authentication is approved
 append expire time to message
 append user info to message
 sign header.message with HMAC SHA256 and the shared key
   return token
```

##### /verify
```
send signing generateSharedKey and message
verify that signature and message matches
verify that current time is less than expire time
if valid
 redirect to file
else 
 redirect to 410 Gone
```

This implementation does not rely on a shared key. The initial 
authentication is deferred to the Active Directory used by the client.

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