Difficulty: beginner
Estimated Time: 5 minutes

Secure a service, obtain a token and making a secure request.

In this scenario, you will learn :

  • How to configure a NodeJS service exposing a REST endpoint to make it secure.
  • Obtain a OpenID Connect token from Keycloak.
  • Make a http request against the service using the obtained token.

Congratulations you have completed scenario ! Now that we have a secured service, we can learn how to secure an application that will consume this service in a secured way.

Securing a service

Step 1 of 3

Securing the app

Let's secure our first service.

Configure our Service

The service needs some configuration specific to keycloak. For most Keycloak adapters this will happen in a file named keycloak.json :

    "realm": "katacoda",
    "bearer-only": true,
    "auth-server-url": "https://[[HOST_SUBDOMAIN]]-8443-[[KATACODA_HOST]].environments.katacoda.com/auth",
    "ssl-required": "external",
    "resource": "service-nodejs"
  • realm : The realm in which this service belongs
  • bearer-only : This is a flag to indicate that this service will not perform any redirect and just accepts authenticated requests
  • auth-server-url : This is the url of our Keycloak instance.

Start the service

Go to the service directory :

cd /root/service-nodejs/

Install the service :

npm install

And run it :

npm start