We are using a Rule to change the token expiration date in some cases by modifying jwtConfiguration.lifetimeInSeconds:
function (user, context, callback) {
//When the api keys are requested;
if(context.request.query.scope.indexOf('api_keys') > -1 ){
Date.prototype.addYears=function(years) {
return new Date(this.getTime() + years*31556926000); //milliseconds in a year
};
var d = new Date();
var t = d.addYears(20);
context.jwtConfiguration = context.jwtConfiguration || {};
context.jwtConfiguration.lifetimeInSeconds = (t.getTime() / 1000);
//Adding the jti
var gen_jti = require('uuid').v4();
console.log('requested api token transaction '+ gen_jti);
user.jti = gen_jti;
}
callback(null, user, context);
}
It seems that this doesn’t work any more. The rule gets called and runs, but the expiration of the token doesn’t change. We think it stopped working around December 2016.
The reason why we do this is to implement API keys for our REST API. Back in February 2016 we asked Auth0 Customer Support and one of the engineers suggested this solution, which worked very well… while it worked
A bit more about our use case:
We have a web application and a REST API. For the web application with use Auth0 for authentication. For the API, we generate JWT tokens using Auth0 which don’t expire (well, they expire in 20 years), and give those to our users so they can call our API endpoints. They do this the same way as in the web application, adding an “Authorization” header containing the JWT token (“Bearer xxx”).
The way that we ask Auth0 to generate these tokens is by passing a special scope (we call it “api_keys”), and then in the rule, if we have such a request we modify the expiration as shown above.
We just noticed that this broke, which for us means our API key mechanism is broken.
I read somewhere that you are not supporting jwtConfiguration.lifetimeInSeconds in some endpoints. Are you not going to support jwtConfiguration.lifetimeInSeconds any more?
Also, is there any other way to request tokens to Auth0 changing the expiration date? The normal expiration that we set in the Auth0 client is ok for the web application, but for API keys this is not a good option. Should we generate a separate client for this?
In general, how do you recommend your (Auth0) customers to proceed when they have their own REST API and they want to perform authentication using Auth0?