Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/byteboomers/userhut-token-decoder-node
Userhut token decoder for Node
https://github.com/byteboomers/userhut-token-decoder-node
authentication userhut
Last synced: 24 days ago
JSON representation
Userhut token decoder for Node
- Host: GitHub
- URL: https://github.com/byteboomers/userhut-token-decoder-node
- Owner: byteboomers
- License: mit
- Created: 2019-04-23T09:53:14.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-07-02T19:49:13.000Z (over 5 years ago)
- Last Synced: 2024-08-09T23:04:51.779Z (5 months ago)
- Topics: authentication, userhut
- Language: JavaScript
- Size: 164 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# userhut-token-decoder-node
Userhut token decoder for Node
## Installation
### NPM
```bash
npm install --save userhut-token-decoder jsonwebtoken
```[npm package link](https://www.npmjs.com/package/userhut-token-decoder)
## Usage
```javascript
// Initialize library
const TokenDecoder = require("userhut-token-decoder");
const tokenDecoder = new TokenDecoder({
poolId: "your-pool-id",
publicKey: "your-public-key"
});// Decode token
const token = ctx.request.headers["authorization"];
const decoded = tokenDecoder.decode(token);
```### Koa middleware
```javascript
const TokenDecoder = require("userhut-token-decoder");
const tokenDecoder = new TokenDecoder({
poolId: process.env.APP_USERHUT_POOL_ID,
publicKey: process.env.APP_USERHUT_PUBLIC_KEY_B64
});module.exports = async (ctx, next) => {
const token = ctx.request.headers["authorization"];
const user = tokenDecoder.decode(token);
ctx.state.user = user;
return next();
};
```