(Optional) Exercise 1: Setup the web-application and Microservices locally
Last updated
Last updated
To run these optional exercises you need to ensure you have installed the following tools on your local machine and you can run them in your terminal sessions.
Docker 3.0.4 or higher (running Keycloak locally)
Java 9 or higher
Here is the local architecture whichs shows the Web-App and the two Microservices Web-API and Articles are running on your local machine in terminal sessions. Keycloak is running on Kubernetes on IBM Cloud.
The gif shows the logon to the example web frontend application. This is the simplified sequence which happens in the background:
When we invoke the web frontend on `http://localhost:8080 we will be routed to login dialog provided by the Keyloak server.
After the successfully Keycloak authentication we will be redirected to the web frontend and the frontend gets an access-token.
The access-token contains the needed information for the authorization at the Java microservice Web-API and the user information.
The web frontend extracts and displays the username.
Then the web fronted uses the access-token to invoke the Web-API Microservice endpoint to get the articles and displays the Articles.
If you have your Keycloak running on Kubernetes you just skip to setup Web-App.
In this part we will setup Keycloak locally. We will run a local Keycloak Docker container and reuse an existing realm configuration.
The image below shows the relevant elements we will use later.
Open the first terminal session and enter following command:
Note: We use here
KEYCLOAK_USER=admin
KEYCLOAK_PASSWORD=admin
8282:8080
port forwarding
keycloak:9.0.2
container image
Open the Keycloak in a browser select the Administration Console
Use following URL:
Login to using the URL in your browser with user/admin
and password/admin
Select Add realm
Choose for import Select file and open the quarkus-realm.json
.
view all users
You should see following users: admin
, alice
, jdoe
Now insert Keycloak URL
/auth in main.js
(http://localhost:8282
) and save the changes.
Example:
Open the second terminal session and start the application on port 8080.
Insert your the auth-server-url
URL of your Keycloak instance in application.properties
file and save the file.
Therefore you use the Keycloak URL
you got during the setup of Keycloak on IBM Cloud.
Example:
Open a third terminal and start the service on port 8081.
Insert your the auth-server-url
URL of your Keycloak instance in application.properties
file and save the file. Therefore you use the Keycloak URL
you got during the setup of Keycloak on IBM Cloud.
Example:
Open a fourth terminal and start the service on port 8081.
Open the following URL in your browser:
Congratulations, you have successfully completed this optional hands-on lab tasks for
uthentication and Authorization with Keycloak and Quarkus
section of the workshop. Awesome :star: