# Auth0 RBAC: nodejs using express-jwt-authz

**URL:** <https://community.auth0.com/t/auth0-rbac-nodejs-using-express-jwt-authz/96161>\
**Category:** Get Help\
**Tags:** user-authorization-rbac, directory-authorization\
**Created:** [December 10, 2022, 3:21am UTC](https://community.auth0.com/t/auth0-rbac-nodejs-using-express-jwt-authz/96161 "2022-12-10T03:21:49Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinood.persad](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vinood.persad/32/33660_2.png) [@vinood.persad](https://community.auth0.com/u/vinood.persad)\
**Post date:** [December 10, 2022, 3:21am UTC](https://community.auth0.com/t/auth0-rbac-nodejs-using-express-jwt-authz/96161/1 "2022-12-10T03:21:49Z")

</div>

Hi community, looking for some assistance on Auth0 RBAC with nodejs.  
I have configured RBAC on Auth0, angular frontend and nodejs backend. The nodejs backend uses express-jwt-authz. When i print out the token and go to [jwt.io](http://jwt.io/) i can see everything is as it should be however the server is returning 403 forbidden on my route. Permissions are sent as read:employees and is configured exactly the same in the code as you can see before.

I have placed the node js code along with an example token of what the server is seeing:

const express = require(‘express’);  
const router = express.Router();  
const { expressjwt: jwt } = require(‘express-jwt’);  
const jwks = require(‘jwks-rsa’);  
const jwtAuthz = require(“express-jwt-authz”);

const authorizeAuth0Token = jwt({  
secret: jwks.expressJwtSecret({  
cache: true,  
rateLimit: true,  
jwksRequestsPerMinute: 5,  
jwksUri: `${process.env.AUT0_DOMAIN}.well-known/jwks.json`  
}),  
audience: process.env.AUT0\_AUDIENCE,  
issuer: process.env.AUT0\_DOMAIN,  
algorithms: [‘RS256’]  
});

const checkAuthPermissions = jwtAuthz([‘read:employees’], {  
customScopeKey: “permissions”  
});

router.get(‘/employees’,authorizeAuth0Token, checkAuthPermissions, (req, res) =\> {  
res.status(200).json({‘test’:‘this api call is good’})  
});

Token: eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6ImdRUjNLdHFheWpGc2Z6Y05qUGFKSSJ9.eyJpc3MiOiJodHRwczovL2Rldi1ibGE1Z3Q0aGh5M2Rwd3Y2LnVzLmF1dGgwLmNvbS8iLCJzdWIiOiJhdXRoMHw2MzhiOWQwMjg3NzlhMDBlNTI2YTU0NWMiLCJhdWQiOlsiaHR0cHM6Ly9taXRhc2svYXBpIiwiaHR0cHM6Ly9kZXYtYmxhNWd0NGhoeTNkcHd2Ni51cy5hdXRoMC5jb20vdXNlcmluZm8iXSwiaWF0IjoxNjcwNjQxNDEwLCJleHAiOjE2NzA2NDUwMTAsImF6cCI6IkF2SWt4U0lqTUxleU9PVjNQMkdlNFBFRXJpdkRxU2hlIiwic2NvcGUiOiJvcGVuaWQgcHJvZmlsZSBlbWFpbCIsInBlcm1pc3Npb25zIjpbInJlYWQ6ZW1wbG95ZWVzIl19.fYXSVJa4CSPt\_UCIXJM9e6MPOD2xyx1KgogCeVVF0Mwo0YD68Qex7iUUU3O60gMGdMrh7x6B73qAakl-tS-gLH\_bVVM3PHWf4v\_fSSRbju2IIeLEHkTAAMRc6qk8jNzqiB725etGEJlmZDYipU9ryfHl11FnFFjX8kYDW4lBCbKOxdLcmHSZpJppsQ6QU0eFNLCp2\_PKUqGx6waofVZ6\_IpBS3b4LHfVjQkzsyGdWOFtLIRIoSnciaqkDMpT-FxydWGfp7EeP5eUaBk8n3RvZ22VMNLkkVxZPUDTmFM6wZMhu22kpy1F\_h5DmfaKz6A5WYP22mLouecQtw7fYZltjw

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [December 12, 2022, 10:01pm UTC](https://community.auth0.com/t/auth0-rbac-nodejs-using-express-jwt-authz/96161/3 "2022-12-12T22:01:37Z")

</div>

Hey there @vinood.persad!

Hmm that’s interesting you’re getting a `403` here - Are there any clues in the error logging as to why?

While I haven’t used `express-jwt-authz` myself, I was able to get this working using the updated [express-oauth2-jwt-bearer](https://github.com/auth0/node-oauth2-jwt-bearer/tree/main/packages/express-oauth2-jwt-bearer) library to achieve what you are after. My code looks like this:

```auto
const cors = require("cors");
const morgan = require("morgan");
const helmet = require("helmet");
const authConfig = require("./src/auth_config.json");

const express = require('express');
const { auth, requiredScopes, claimEquals, claimIncludes } = require('express-oauth2-jwt-bearer');
require('dotenv').config(); // Load the .env variables

const appPort = process.env.SERVER_PORT || 3000;
const appOrigin = authConfig.appOrigin || `http://localhost:${appPort}`;

const app = express();
const checkJwt = auth();
app.use(morgan("dev"));
app.use(helmet());
app.use(cors({ origin: appOrigin }));

//using claimIncludes to check if the permissions claim contains read:msg
app.get('/api/external', checkJwt, claimIncludes('permissions', 'read:msg'), (req, res) => {
  res.json({ message: `Hello ${req.auth.payload.sub} - Permissions: ${req.auth.payload.permissions}` });
});

app.listen(3001, () => console.log('listening at http://localhost:3001'))

```

I’m using this alongside our React sample to test, you can find my fork [here](https://github.com/tyfrth/auth0-react-samples?organization=tyfrth&organization=tyfrth).

Depending on where you are at in your project, it might be worth switching over to the improved experience - Some more on that here:

> **[Introducing the OAuth 2.0 Express SDK for Protecting APIs with JWT Bearer Tokens](https://auth0.com/blog/introducing-oauth2-express-sdk-protecting-api-with-jwt/#What-s-Happening-to--express-jwt----express-jwt-authz---and--jwks-rsa-)**
>
> Learn how the OAuth 2.0 Express SDK released by Auth0 makes protecting your Express API easier.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![vinood.persad](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vinood.persad/32/33660_2.png) [@vinood.persad](https://community.auth0.com/u/vinood.persad)\
**Post date:** [December 22, 2022, 1:43pm UTC](https://community.auth0.com/t/auth0-rbac-nodejs-using-express-jwt-authz/96161/4 "2022-12-22T13:43:45Z")

</div>

Thanks so much for the reply and the help. And also thanks for the example snippet provided. I took a look at the blog you provided and I do believe this will definitly fix my issue. I am yet to perform a test of this as its been a little busy with end of year, however I will be testing this solution within the coming days. i will confirm this helps as soon as I am done testing.

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [December 22, 2022, 11:37pm UTC](https://community.auth0.com/t/auth0-rbac-nodejs-using-express-jwt-authz/96161/5 "2022-12-22T23:37:15Z")

</div>

No problem, happy to help! Please keep us posted here on the results if you can 😄

---

<div class="post-metadata">

**Author:** ![vinood.persad](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/vinood.persad/32/33660_2.png) [@vinood.persad](https://community.auth0.com/u/vinood.persad)\
**Post date:** [December 23, 2022, 3:23pm UTC](https://community.auth0.com/t/auth0-rbac-nodejs-using-express-jwt-authz/96161/6 "2022-12-23T15:23:52Z")

</div>

Works like a charm. Thanks for the help much appreciated! enjoy the holidays!

---

<div class="post-metadata">

**Author:** ![ty.frith](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ty.frith/32/58484_2.png) [@ty.frith](https://community.auth0.com/u/ty.frith)\
**Post date:** [December 23, 2022, 11:26pm UTC](https://community.auth0.com/t/auth0-rbac-nodejs-using-express-jwt-authz/96161/7 "2022-12-23T23:26:08Z")

</div>

Great to know and thanks for following up here 😄 Happy holidays!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [January 6, 2023, 11:26pm UTC](https://community.auth0.com/t/auth0-rbac-nodejs-using-express-jwt-authz/96161/8 "2023-01-06T23:26:59Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
