# Keycloak sends 403 Access Denied with NodeJS Adapter

**URL:** <https://forum.keycloak.org/t/keycloak-sends-403-access-denied-with-nodejs-adapter/1660>\
**Category:** Securing applications\
**Tags:** adapter-nodejs\
**Created:** [March 11, 2020, 8:37pm UTC](https://forum.keycloak.org/t/keycloak-sends-403-access-denied-with-nodejs-adapter/1660 "2020-03-11T20:37:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![luisRios](https://avatars.discourse-cdn.com/v4/letter/l/59ef9b/32.png) [@luisRios](https://forum.keycloak.org/u/luisRios)\
**Post date:** [March 11, 2020, 8:37pm UTC](https://forum.keycloak.org/t/keycloak-sends-403-access-denied-with-nodejs-adapter/1660/1 "2020-03-11T20:37:17Z")

</div>

Hi! I have a simple NodeJS application which I’d like to protect with keycloak-connect, but everytime returns a 403 - Access Denied error.

I have done all the tutorials i’ve found (same code, same keycloack and node versions) and even try the example provided in the library but still get the same error.

This is my keycloak.json file:

```auto
{
    "realm": "prueba",
    "auth-server-url": "http://localhost:8080/auth/",
    "ssl-required": "external",
    "resource": "prueba",
    "public-client": true,
    "confidential-port": 0
  }

```

My code:

```auto
var express = require("express");
var session = require("express-session");
var Keycloak = require("keycloak-connect");

var app = express();

app.use(session({
    secret:'thisShouldBeLongAndSecret',
    resave: false,
    saveUninitialized: true
}));

var sessionStore = new session.MemoryStore();
var keycloak = new Keycloak({ store: sessionStore });

app.use(keycloak.middleware());

// public url
app.get("/", (req, res) => res.send("Welcome!!"));

// protected url
app.get("/hello", keycloak.protect(), (req, res) => res.send("Hello!!"));

app.listen(3000, function () {
    console.log('Listening at http://localhost:3000');
});

```

When I navigate to [http://localhost:3000/hello](http://localhost:3000/hello) I get a 403 Access Denied and in console i get this

![ErrorGrantCode](https://global.discourse-cdn.com/free1/uploads/keycloak/original/1X/b874fe367406949ca5615572a4c615cd8fc3051d.png)

I really don’t know if I missed a step or any settings in Keycloak realms or client. I hope someone can help. Thank you!

---

<div class="post-metadata">

**Author:** ![dmitchell](https://avatars.discourse-cdn.com/v4/letter/d/a6a055/32.png) [@dmitchell](https://forum.keycloak.org/u/dmitchell)\
**Post date:** [May 21, 2020, 8:27pm UTC](https://forum.keycloak.org/t/keycloak-sends-403-access-denied-with-nodejs-adapter/1660/2 "2020-05-21T20:27:08Z")

</div>

You might try:

const memoryStore = new session.MemoryStore();

const mySession = session({  
secret: ‘thisShouldBeLongAndSecret’,  
resave: false,  
saveUninitialized: true,  
store: memoryStore  
});  
app.use( mySession );  
// create a kcConfig  
const kcConfig = { clientId: ‘xxx’ and so on };  
var keycloak = new Keycloak({ store: memoryStore }, kcConfig);  
app.use(keycloak.middleware());

---

<div class="post-metadata">

**Author:** ![subodhjoshi](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/subodhjoshi/32/987_2.png) [@subodhjoshi](https://forum.keycloak.org/u/subodhjoshi)\
**Post date:** [June 11, 2020, 11:43am UTC](https://forum.keycloak.org/t/keycloak-sends-403-access-denied-with-nodejs-adapter/1660/3 "2020-06-11T11:43:28Z")

</div>

Are you able to Resolve this issue?

---

<div class="post-metadata">

**Author:** ![amanmahalgavan](https://avatars.discourse-cdn.com/v4/letter/a/34f0e0/32.png) [@amanmahalgavan](https://forum.keycloak.org/u/amanmahalgavan)\
**Post date:** [June 29, 2020, 10:53pm UTC](https://forum.keycloak.org/t/keycloak-sends-403-access-denied-with-nodejs-adapter/1660/4 "2020-06-29T22:53:12Z")

</div>

Has anyone resolved this issue yet?

---

<div class="post-metadata">

**Author:** ![EnesToptas](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/enestoptas/32/1147_2.png) [@EnesToptas](https://forum.keycloak.org/u/EnesToptas)\
**Post date:** [July 24, 2020, 7:49am UTC](https://forum.keycloak.org/t/keycloak-sends-403-access-denied-with-nodejs-adapter/1660/5 "2020-07-24T07:49:16Z")

</div>

Were you able to solve this problem, I have been experiencing the same.

---

<div class="post-metadata">

**Author:** ![manasdwd07](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/manasdwd07/32/1693_2.png) [@manasdwd07](https://forum.keycloak.org/u/manasdwd07)\
**Post date:** [November 17, 2020, 12:36pm UTC](https://forum.keycloak.org/t/keycloak-sends-403-access-denied-with-nodejs-adapter/1660/6 "2020-11-17T12:36:46Z")

</div>

Has anyone resolved this issue ? Getting the same Access Denied 403 error even after doing what @dmitchell suggested.  
Please help me out 🙂

---

<div class="post-metadata">

**Author:** ![abstractj](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/abstractj/32/9_2.png) [@abstractj](https://forum.keycloak.org/u/abstractj)\
**Post date:** [November 17, 2020, 10:43pm UTC](https://forum.keycloak.org/t/keycloak-sends-403-access-denied-with-nodejs-adapter/1660/7 "2020-11-17T22:43:18Z")

</div>

Please provide steps to reproduce the issue you mention. That’s the only way to get people to help you.

Things like:

- Keycloak server version
- Keycloak Node.js version
- Realm configuration or how the client is configured
- Publish the code on GitHub if possible

The more information you provide, more quickly you may get an answer.

---

<div class="post-metadata">

**Author:** ![cric1](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/cric1/32/863_2.png) [@cric1](https://forum.keycloak.org/u/cric1)\
**Post date:** [November 24, 2020, 3:06am UTC](https://forum.keycloak.org/t/keycloak-sends-403-access-denied-with-nodejs-adapter/1660/8 "2020-11-24T03:06:54Z")

</div>

I too get the same error for the node adapter by following the keycloak documentation.

Keycloak version 11.0.0  
keycloak-connect: 11.0.2,  
node: 13.9.2  
express: 4.17.1  
express-session: 1.17.1

Client is configured as openid protocol with bearer-only =true.

---

<div class="post-metadata">

**Author:** ![shamimafridi](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/shamimafridi/32/1778_2.png) [@shamimafridi](https://forum.keycloak.org/u/shamimafridi)\
**Post date:** [November 29, 2020, 9:02am UTC](https://forum.keycloak.org/t/keycloak-sends-403-access-denied-with-nodejs-adapter/1660/9 "2020-11-29T09:02:48Z")

</div>

I have the same issue. Did anyone resolve this issue?

---

<div class="post-metadata">

**Author:** ![diegosm](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/diegosm/32/1850_2.png) [@diegosm](https://forum.keycloak.org/u/diegosm)\
**Post date:** [December 8, 2020, 6:44pm UTC](https://forum.keycloak.org/t/keycloak-sends-403-access-denied-with-nodejs-adapter/1660/10 "2020-12-08T18:44:35Z")

</div>

Guys I think I’m facing the same problem.

In my case, when I’m executing some commands like, create new realm, and after this, in sequence, I send another command like create roles at this new realm, I give access denied 403, it seems like the first command (create realm) sent me 201 status on keycloak API, but someway (I dont know why) the new realm isn’t ready properly.

If I send the create roles command before some time, it work correctly.

Does someone know how to solve it? I imagine that I could not run keycloak with high volume access.

Best regards,  
Diego

---

<div class="post-metadata">

**Author:** ![snlaight](https://yyz2.discourse-cdn.com/free1/user_avatar/forum.keycloak.org/snlaight/32/4237_2.png) [@snlaight](https://forum.keycloak.org/u/snlaight)\
**Post date:** [November 3, 2021, 7:16pm UTC](https://forum.keycloak.org/t/keycloak-sends-403-access-denied-with-nodejs-adapter/1660/11 "2021-11-03T19:16:01Z")

</div>

if you’re still running into this issue, following the steps here fixed the issue for me :

> <https://stackoverflow.com/questions/53550321/keycloak-gatekeeper-aud-claim-and-client-id-do-not-match/53627747#53627747>
