title: Use keycloak.protect() with express.Router()
body: <p>I want to secure my routes using Keycloak which is an open source identity and access management.
  I have tried to follow their documentation but I was not able to make it work.</p>
  
  <p>Here is my app.js file:</p>
  
  <pre><code>const express = require( 'express' );
  const routePlaces = require( './routes/placesRoutes' );
  
  const Keycloak = require( 'keycloak-connect' );
  const session = require( 'express-session' );
  const memoryStrore = new session.MemoryStore();
  
  let kcConfig = {
      clientId =      'parking-app',
      bearerOnly:     true,
      serverUrl:      'localhost:8080/auth',
      realm:          'FlexParking',
      reamlPublicKey: 'MIIBIjANBg…'
  }
  
  var keycloak = new KeyCloak( {store: memoryStore}, kcConfig );
  
  app.use( keycloak.middleware({
      //  here I think I have to place my routes
  }));
  
  app.use( '/places, routePlaces );
  module.exports = app;
  </code></pre>
  
  <p>The server is created in a <code>server.js</code> file and all the endpoints are working perfectly before trying to use Keycloak.</p>
  
  <p>Here is my <code>routePlaces.js</code> file:</p>
  
  <pre><code>'use strict';
  const express = require( 'express' );
  const place = require( '../controllers/placesController' );
  
  router.route( '/gps' ).get( place.get_place_by_gps );
  router.route( '/street' ).get( place.get_place_by_street );
  
  module.exports = router;
  </code></pre>
  
  <p>And here is my <code>placesController.js</code>:</p>
  
  <pre><code>'use strict';
  
  exports.get_place_by_gps = ( req, res, next ) =&gt; {
      res.send( ' GET places by the GPS position' );
  }
  
  exports.get_place_by_street = ( req, res, next ) =&gt; {
      res.send( ' GET places by the street name' );
  }
  </code></pre>
  
  <p>I want my route ('/places/gps') to be protected using <code>keycloak.connect('...')</code> and the route '/places/street' to be used without any protection. How to configure the Keycloak middleware to do that?</p>
  
  <pre><code>app.use( keycloak.middleware({
      //  here i think i have to place my routes
  }));
  </code></pre>
  
  <p>How can the route be protected like this:</p>
  
  <pre class="lang-js prettyprint-override"><code>router.route( '/gps' ).get( place.get_place_by_gps, keycloak.connect('user'));
  </code></pre>