Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

auth0-api-tokens

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

auth0-api-tokens - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

2

package.json
{
"name": "auth0-api-tokens",
"version": "1.0.0",
"version": "1.1.0",
"description": "Library that given a Auth0 global client credentials allows users to generate JWT tokens for API v2",

@@ -5,0 +5,0 @@ "main": "index.js",

# auth0-api-tokens ![build status](https://travis-ci.org/auth0/auth0-api-tokens.svg?branch=master)
Library that given a Auth0 global client credentials allows users to generate JWT tokens for API v2.
Library that given Auth0 global client credentials allows users to generate JWT tokens for API v2.

@@ -17,10 +17,13 @@ You can read more about API v2 tokens in [this blog post](https://auth0.com/blog/2014/12/02/using-json-web-tokens-as-api-keys/) and in the [API explorer](https://docs.auth0.com/apiv2).

var createToken = require('auth0-api-tokens')({
clientId: '{YOUR_GLOBAL_CLIENT_ID}',
clientSecret: '{YOUR_GLOBAL_CLIENT_Secret}',
}, TOKEN_EXPIRATION_IN_SECONDS)
clientId: '{YOUR_GLOBAL_CLIENT_ID}',
clientSecret: '{YOUR_GLOBAL_CLIENT_Secret}',
})
// each key is an entity, each array element is an action
var token = createToken({
scopes: {
users: ['read', 'write'],
clients: ['delete']
},
lifetimeInSeconds: TOKEN_EXPIRATION_IN_SECONDS
});

@@ -44,2 +47,2 @@

This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info.
This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info.

@@ -7,15 +7,16 @@ var jwt = require('jsonwebtoken');

module.exports = function(credentials){
return function(scopes, lifetimeInSeconds){
lifetimeInSeconds = lifetimeInSeconds || DEFAULT_LIFETIME_IN_SECONDS;
var payload = {
iat: Math.floor(Date.now() / 1000),
scopes: Object.keys(scopes).reduce(function(c,v){
c[v] = {
actions: scopes[v]
};
return function(params){
var lifetimeInSeconds = params.lifetimeInSeconds || DEFAULT_LIFETIME_IN_SECONDS;
var scopes = params.scopes || {};
return c;
}, {})
};
var payload = params.extra_claims || {};
payload.iat = Math.floor(Date.now() / 1000);
payload.scopes = Object.keys(scopes).reduce(function(c,v){
c[v] = {
actions: scopes[v]
};
return c;
}, {});
payload.jti = crypto

@@ -22,0 +23,0 @@ .createHash('md5')

@@ -13,5 +13,11 @@ var expect = require('chai').expect;

token = createToken({
users: [ 'read', 'update' ],
clients: [ 'delete' ]
}, 3600);
scopes: {
users: [ 'read', 'update' ],
clients: [ 'delete' ]
},
lifetimeInSeconds: 3600,
extra_claims: {
foo: 'bar'
}
});

@@ -50,2 +56,6 @@ decodedToken = jws.decode(token);

});
it('should set extra claims', function(){
expect(payload.foo).to.equal('bar');
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc