Enforcing Web Security
During this scenario, we will use the Devprime stack’s security adapter to enable security settings so that when there is an access request, user authentication is required on a centralized Keycloak basis.
To move forward in this scenario, it is essential to have an instance of Keycloak and follow the steps as instructed below:
-
Create an instance of Keycloak following the indicated procedures.
-
Install the Devprime CLI.
-
Creating a microservice for use in the ms-sec-order demo
dp new ms-order --state mongodb --stream rabbitmq --marketplace order --init
-
After completion, you can run the microservice. Then finish.
.\run.ps1 or ./run.sh (Linux, macOS) -
Adding web template for use in the demo. This will create some web pages
to use in the demonstration.
dp add web login
After running it, we will have a new Endpoint called “/private” that already has the “Authorize” attribute necessary to indicate that that url requires authentication. The excerpt from the file below “code src/App/appsettings.json” demonstrates this scenario
with the URLs /private, /login, and /logout.
To view from Visual Studio Code:
code src/App/appsettings.json
|
|
- Open the settings file and include in the security adapter the Keycloak parameters obtained in item 1 of this step-by-step by changing the items “ClientID / ClientSecret / LogoutUri / Audience”
IMPORTANTE:
Put the same value as the ClientID in the Audience field as shown in the example below and make sure
that EnableOIDC is set to “true”.
Procedure for Adding Security Configuration by OIDC:
a) Open from Visual Studio Code
code src/App/appsettings.json
b) Copy the code below and put it in the appsettings.json
|
|
-
Run the application and open https://localhost:5001 to view the new links added.
-
Go to the private link and you will be directed to authentication
-
Log in or register with Keycloak under “Register”.
-
In case of success, the private web page will be released.
Next Steps:
You’ve secured a web application using Keycloak and a microservice using the Devprime platform. Congratulations🚀🚀🚀
Last modified April 11, 2024 (cc33f7e6)