npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@aquarela/jwt-signer

v1.6.9

Published

Sign JWT Token with any Signature algorithm key.

Downloads

27

Readme

Sign JWT Token with any Signature algorithm key.

🏠 Homepage

Updates

1.6.7 fixes problems which may occur within TypeScript

1.6.6

Now it verifies if token is valid and return an JSON object or a error (that may be expiration, invalid algorithm, payload and etc.)

example output:


{

valid: true,

payload: { sub: '94828482248', name: 'The Dude', iat: 1516239022 },

token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpX(...)Eo-PAyF1xJWxYFSnw'

}

Install

NPM


#yarn

yarn add @aquarela/jwt-signer

  

#npm

npm -i @aquarela/jwt-signer

  

CDN


#unpkg

https://unpkg.com/@aquarela/[email protected]/lib/index.js

  

#jsdeliver

https://cdn.jsdelivr.net/npm/@aquarela/jwt-signer

  

Usage

You need only the private key (as file using keyPath or raw using inline argument)


import { jwtSign } from  '@aquarela/jwt-signer'  // Import the package

  

const data = {

sub:  "94828482248",

name:  "The Dude",

iat:  1516239022

} // Create Payload Data

  

console.log(jwtSign({keyPath:  './private.pem', payload: data}))

  

// output:

//

// {

// valid: true,

// payload: { sub: '94828482248', name: 'The Dude', iat: 1516239022 },

// token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpX(...)Eo-PAyF1xJWxYFSnw'

// }

Options

There 4 argument on jwtSign: keyPath or inline (required), payload (required) and options.

keyPath (@string) *required (can be swapped with inline argument)

keyPath support local or external paths of your private key.


import { jwtSign } from  '@aquarela/jwt-signer'  // Import the package

  

(...)

console.log(jwtSign({

keyPath:  './private.pem', // private key file on the root folder.

(...)}))

// output:

//

// {

// valid: true,

// payload: { sub: '94828482248', name: 'The Dude', iat: 1516239022 },

// token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpX(...)Eo-PAyF1xJWxYFSnw'

// }

inline (@string) *required (can be swapped with keyPath argument)

inline support raw private key data.


import { jwtSign } from  '@aquarela/jwt-signer'

  

(...)

  

const rawData =  `-----BEGIN RSA PRIVATE KEY-----

MIICXQIBAAKBgQDUi8T6pRUhWdA+g8hlebFMzRRoM0MCnqMoHg/IEmd0pY1t9O0J

oDLXCcCEguTJaaw73y7TwHERgxE1Ma/mExIQtMTgrpVBgVCOw1tsz5Kf7xGNXH5f

(...)

-----END RSA PRIVATE KEY-----`

  

  

console.log(jwtSign({

keyPath:  '',

inline: rawData,

(...)

}))

// output:

//

// {

// valid: true,

// payload: { sub: '94828482248', name: 'The Dude', iat: 1516239022 },

// token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpX(...)Eo-PAyF1xJWxYFSnw'

// }

payload (@object) *required

payload is the data as JSON Object your gonna embed in your jwt token.

You can see an example here.


import { jwtSign } from  '@aquarela/jwt-signer'  // Import the package

  

const data = { sub:  "94828482248", name:  "The Dude", iat:  1516239022 }

  

(...)

console.log(jwtSign({(...)

payload: data}))

// output:

//

// {

// valid: true,

// payload: { sub: '94828482248', name: 'The Dude', iat: 1516239022 },

// token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpX(...)Eo-PAyF1xJWxYFSnw'

// }

options (@object) *required

payload is the data as JSON Object you can configure some things as algorithm.


import { jwtSign } from  '@aquarela/jwt-signer'  // Import the package

  

(...)

  

/**

  

* Signature algorithm. Could be one of these values :

* - HS256: HMAC using SHA-256 hash algorithm (default)

* - HS384: HMAC using SHA-384 hash algorithm

* - HS512: HMAC using SHA-512 hash algorithm

* - RS256: RSASSA using SHA-256 hash algorithm

* - RS384: RSASSA using SHA-384 hash algorithm

* - RS512: RSASSA using SHA-512 hash algorithm

* - ES256: ECDSA using P-256 curve and SHA-256 hash algorithm

* - ES384: ECDSA using P-384 curve and SHA-384 hash algorithm

* - ES512: ECDSA using P-521 curve and SHA-512 hash algorithm

* - none: No digital signature or MAC value included

  

*/

  

const options = {

algorithm:  'RS512'

}

  

(...)

console.log(jwtSign({(...)

options: options}))

  

// output:

//

// {

// valid: 'yes',

// payload: { sub: '94828482248', name: 'The Dude', iat: 1516239022 },

// token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpX(...)Eo-PAyF1xJWxYFSnw'

// }

Thats it.

Author

👤 AQUARELA

Show your support

Give a ⭐️ if this project helped you!