title: Keycloak in Nodejs always returning 403 Access Denied Error
body: <p>Keycloak returns 403 Error when I send it token from my react frontend. </p>
  
  <p>I have implemented the keycloak server and authentication in React. I can get the keycloak.token after a successful login and redirect in react.</p>
  
  <p>I have followed tutorials I found and my setup is pretty much the same as this answer: <a href="https://stackoverflow.com/questions/53774891/keycloak-nodejs-always-get-403">Keycloak nodeJS always get 403</a></p>
  
  <p>Unfortunately, I still get 403 - Access Denied - Error. I have setup a realm and below is my keycloak.json file and my code.</p>
  
  <pre><code>{
    "realm": "Weal V3",
    "bearer-only": true,
    "auth-server-url": "http://localhost:8080/auth",
    "ssl-required": "external",
    "resource": "node",
    "verify-token-audience": true,
    "use-resource-role-mappings": true,
    "confidential-port": 0
  }
  </code></pre>
  
  <p>My code</p>
  
  <pre><code>const express = require('express');
  const session = require('express-session');
  const Keycloak = require('keycloak-connect');
  const cors = require('cors');
  const morgan = require('morgan');
  
  
  const app = express();
  app.use(cors())
  app.use(morgan('combined'))
  
  const memoryStore = new session.MemoryStore();
  
  app.use(session({
      secret: 'some secret',
      resave: false,
      saveUninitialized: true,
      store: memoryStore
  }));
  
  const keycloak = new Keycloak({
      store: memoryStore
  });
  
  
  app.use(keycloak.middleware());
  
  
  app.get('/public', (req, res) =&gt; {
      res.json({ message: 'public' })
  })
  
  app.get('/secure', keycloak.protect(), (req, res) =&gt; {
      console.log(req)
      res.json({ message: 'secured' })
  })
  
  
  app.get('/admin', keycloak.protect(), (req, res) =&gt; {
      res.json({ message: 'secret' })
  })
  
  
  app.listen(5500, () =&gt; console.log('Server started on port 5500'))
  </code></pre>
  
  <p>I expect that when I navigate to <a href="http://localhost:5500/secure" rel="nofollow noreferrer">http://localhost:5500/secure</a> with Authorization: Bearer + keycloak.token from the react application I should get <code>{ message: 'secured' }</code>, but all I get is 403 Access Denied</p>