Secure an application, getting redirect to the login screen and call a secured service.
In this scenario, you will learn how to:
- Configure a web application.
- Log in to your application.
- Have your application make a secure request to a secured service.
Congratulations! You have completed this 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.

Steps
Securing an application
Securing the app
Configure our Application
The application needs some configuration specific to keycloak. For most Keycloak adapters, this configuration exists in the keycloak.json
file:
{ "realm": "katacoda", "auth-server-url": "https://[[HOST_SUBDOMAIN]]-8443-[[KATACODA_HOST]].environments.katacoda.com/auth", "ssl-required": "external", "resource": "web-client" }
- realm : The
realm
in which this service belongs - auth-server-url : This is the
url
of our Keycloak instance. - resource : The name of the client defined in Keycloak
Create the client in Keycloak
Manual creation
You can manually create the client in the Keycloak console.
Go the Keycloak Web Console then open the Clients
screen, click on Create
and enter the following values:
- Client ID : web-client
- Root URL : https://[[HOST_SUBDOMAIN]]-8000-[[KATACODA_HOST]].environments.katacoda.com
Click save
and you are done.
Import the client with a rest call
Just execute this script:
export access_token=$(\
curl -X POST https://[[HOST_SUBDOMAIN]]-8443-[[KATACODA_HOST]].environments.katacoda.com/auth/realms/master/protocol/openid-connect/token \
-H 'content-type: application/x-www-form-urlencoded' \
-d 'username=admin&password=admin&grant_type=password&client_id=admin-cli' | jq --raw-output '.access_token' \
)
curl -v -X POST https://[[HOST_SUBDOMAIN]]-8443-[[KATACODA_HOST]].environments.katacoda.com/auth/admin/realms/katacoda/clients -H 'content-type: application/json' -H "Authorization: Bearer "$access_token -d @/root/web-client.json
You’ll love Katacoda

Guided Path
Knowing what you need to know is the hardest part. Our guided pathways help build your knowledge around real-world scenarios.

Learn By Doing
The best way to learn is by doing. All our tutorials are interactive with pre-configured live environments ready for you to use.

Stay up-to-date
It's a competitive industry. Your skills need to keep up with the latest approaches. Katacoda keeps your skills up-to-date.
You’ll love Katacoda

Guided Path
Knowing what you need to know is the hardest part. Our guided pathways help build your knowledge around real-world scenarios.

Learn By Doing
The best way to learn is by doing. All our tutorials are interactive with pre-configured live environments ready for you to use.

Stay up-to-date
It's a competitive industry. Your skills need to keep up with the latest approaches. Katacoda keeps your skills up-to-date.