title: How to authenticate keycloak token using node js that calls postgraphile?
body: <p>I'm new on node js, and the company that i work for needs a proof of concept about postgraphile, the situation is this:</p>
  <ol>
  <li>I created a node js mini server that uses postgraphile to access the data on postgres</li>
  <li>The mini server works fine and can return data and also can use mutations.</li>
  <li>I used keycloak-connect to try to access keycloak to authenticate the token from the request that is sent by postman but there is a problem.</li>
  <li>If the token is valid or not it does not matter for the mini server, the only thing that seems to matter is that is a bearer token.</li>
  </ol>
  <p>I tried to use other plugins (like keycloak-nodejs-connect, keycloak-verify, etc) but the result is the same, i also changed my code to use the examples in the documentation of those plugins but nothing.</p>
  <p>This is my code: (keycloak-config.js file)</p>
  <pre><code>var session = require('express-session');
  var Keycloak = require('keycloak-connect');
  
  let _keycloak;
  
  var keycloakConfig = {
      clientId: 'type credential',
      bearerOnly: true,
      serverUrl: 'our company server',
      realm: 'the test realm',
      grantType: &quot;client_credentials&quot;,
      credentials: {
          secret: 'our secret'
      }
  };
  
  function initKeycloak(){
      if(_keycloak){
          console.warn(&quot;Trying to init Keycloak again!&quot;);
          return _keycloak;
      }
      else{
          console.log(&quot;Initializing Keycloak...&quot;);
          var memoryStore = new session.MemoryStore();
          _keycloak = new Keycloak({store: memoryStore}, keycloakConfig);
  
          return _keycloak;
      }
  }
  
  function getKeycloak(){
      if(!_keycloak){
          console.error('Keycloak has not been initialized. Please called init first');
      }
  
      return _keycloak;
  }
  
  module.exports = {
      initKeycloak,
      getKeycloak
  };
  </code></pre>
  <p>My Index.js file:</p>
  <pre><code>const express = require('express')
  const bodyParser = require('body-parser')
  const postgraphile = require('./postgraphile')
  const app = express()
  
  const keycloak = require('../config/keycloak-config').initKeycloak()
  
  var router = express.Router();
  
  app.set( 'trust proxy', true );
  app.use(keycloak.middleware());
  app.use(cors());
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(postgraphile);
  
  app.get('/', keycloak.checkSso(), (req, res) =&gt; {
      res.send('success');
      } );
  
  var server = app.listen(8080, () =&gt; console.log(`Server running on port ${8080}`));
  </code></pre>
  <p>Also I used this code to get the token and use the keycloak-verify plugin but got nothing:</p>
  <pre><code>router.get('/',keycloak.protect(),function(req, res, next) {
      var token=req.headers['authorization'];
      console.log(token);
  
      try {
          let user = keycloak.jwt.verify(token);
          console.log(user.isExpired());
      } catch (error) {
          console.error(error);
      }
  })
  </code></pre>
  <p>I know that I lack the knowledge because I am a backend (C#) developer, can somebody help me with this?, thanks in advance.</p>