Hey Folks,
I’m working on a typical SaaS application. There is a user facing page: https://portal.example.com and in internal page for admins: https://admin.example.com. Backend is node.js application. The same backend application is handling requests both for user as well as admin requests.
In auth0 I have two applications, one for clients another for admins. Admins are using internal database, and clients use Google Connect. I had to set identical audience for both applications (the reason will come below).
Added a rule which adds an admin role to the accessToken.
function (user, context, callback) {
if(context.clientName === 'ExampleAdmin'){
context.accessToken[`https://example/roles`] = ['example-admin'];
}
return callback(null, user, context);
}
Inside the backend I’m validating and parsing the JWT token using express-jwt and jwks-rsa modules.
jwt({
secret: JwksRsa.expressJwtSecret({
cache: true,
rateLimit: true,
jwksRequestsPerMinute: 5,
jwksUri: `https://example.auth0.com/.well-known/jwks.json`,
}),
audience: 'https://example.com/'
issuer: 'https://example.auth0.com/',
algorithms: ['RS256'],
})
There is another middleware which checks the presence of https://example/roles = example-admin and therefore allows access to all users.
While I’ve got it working I’m not sure if this is the right way of doing things. This should be a pretty common scenario for majority of SaaS applications since the internal admin portal is a must to build a successful business. Here are my questions:
- Should there be a separate Admin application in Auth0 or a separate Admin tenant?
- Should the audience be different for Admin vs User application?
- What is the best way for node.js backend to validate & accept both admin as well as user JWT tokens?
Thanks,
Ruben