The goal of this project is to implement an application where a user can manage (create/read/update/delete) jobs. For it, we will create a backend Restful API called jobs-api and a frontend application called jobs-ui. Furthermore, we will use Okta to secure the complete application.
Important: Since Okta removed the Developer Edition Account, this project will no longer be updated.
On ivangfr.github.io, I have compiled my Proof-of-Concepts (PoCs) and articles. You can easily search for the technology you are interested in by using the filter. Who knows, perhaps I have already implemented a PoC or written an article about what you are looking for.
- [Medium] Implementing and Securing a Simple Spring Boot REST API with Okta
- [Medium] Implementing and Securing a Simple Spring Boot UI (Thymeleaf + RBAC) with Okta
- [Medium] Implementing and Securing a Spring Boot GraphQL API with Okta
- [Medium] Building a Single Spring Boot App with Keycloak or Okta as IdP: Introduction
-
Spring BootWeb Java application that exposes a REST API for managing jobs. The job data are stored in Elasticsearch It has some endpoints that are secured.Oktais used to handle authentication and authorization.The table below shows the endpoints, whether they are secured or not, and the authorization role required to access the secured ones.
Endpoint Secured Role GET /actuator/*No POST /callback/tokenNo GET /api/jobs/newestNo POST /api/jobsYes JOBS_STAFFPUT /api/jobs/{id}Yes JOBS_STAFFDELETE /api/jobs/{id}Yes JOBS_STAFFGET /api/jobs/{id}Yes JOBS_STAFF, JOBS_CUSTOMERPUT /api/jobs/searchYes JOBS_STAFF, JOBS_CUSTOMER -
Reactfrontend application where customers can look for a job and staff members can handle jobs. In order to access it, a person must login. The authentication is handled byOkta.
Java 21or higher.npm- A containerization tool (e.g.,
Docker,Podman, etc.) Oktaaccount
- If you do not have a Developer Edition Account, you can create one at https://developer.okta.com/signup/
- If you already have, access https://developer.okta.com/login/
The picture below shows how Okta Admin Dashboard looks like:
- In the
Okta Admin Dashboardmain menu on the left, clickApplicationsmenu and thenApplicationssub-menu. - On the next page, click
Create App Integrationbutton. - Select
OIDC - OpenID Connectas Sign on method andSingle-Page Applicationas Application type. ClickNextbutton. - Enter the following values in the form:
- General Settings
- App integration name:
Jobs Portal SPA. - Grant type: check
Authorization CodeandImplicit (hybrid). - Sign-in redirect URIs:
http://localhost:3000/implicit/callbackandhttp://localhost:8080/callback/token. - Sign-out redirect URIs:
http://localhost:3000.
- App integration name:
- Assignments
- Controlled access:
Skip group assignment for now.
- Controlled access:
- General Settings
- Click
Savebutton. - On the next screen, the
Client IDofJobs Portal SPAis displayed. TheOkta Domaincan be obtained by clicking the button-menu present on the up-right corner of the screen.
- In the
Okta Admin Dashboardmain menu on the left, clickDirectorymenu and thenGroupssub-menu: - Add Staff Group
- Click
Add Groupbutton. - Enter
JOBS_STAFFfor the Name text-field. - Click
Savebutton.
- Click
- Add Customer Group
- Click
Add Groupbutton. - Enter
JOBS_CUSTOMERfor the Name text-field. - Click
Savebutton.
- Click
- In the
Okta Admin Dashboardmain menu on the left, clickDirectorymenu and thenPeoplesub-menu: - Click
Add personbutton. - Enter the following information for the Staff person:
- First name:
Mario. - Last name:
Bros. - Username:
mario.bros@test.com. - Primary email:
mario.bros@test.com. - Groups:
JOBS_STAFF(the group will popup; select it to add it). - Password:
Set by admin. - Set a strong password in the text-field that will appear.
Uncheckthe check-box that says "User must change password on first login".- Click
Save and Add Anotherbutton.
- First name:
- Enter the following information for the Customer person:
- First name:
Luigi. - Last name:
Bros. - Username:
luigi.bros@test.com. - Primary email:
luigi.bros@test.com. - Groups:
JOBS_CUSTOMER(the group will popup; select it to add it). - Password:
Set by admin. - Set a strong password in the text-field that will appear.
- Leave
Uncheckedthe check-box that says "User must change password on first login". - Click
Savebutton.
- First name:
- In the
Okta Admin Dashboardmain menu on the left, clickDirectorymenu and thenGroupssub-menu. - Select
JOBS_STAFF. - Click
Applicationstab. - Click
Assign Applicationsbutton. - Click the
Assignbutton related toJobs Portal SPAand then clickDone. - In the
Okta Admin Dashboardmain menu on the left, clickGroupssub-menu again. - Select
JOBS_CUSTOMER. - Click
Applicationstab. - Click
Assign Applicationsbutton. - Click the
Assignbutton related toJobs Portal SPAand then clickDone.
- In the
Okta Admin Dashboardmain menu on the left, clickSecuritymenu and thenAPIsub-menu. - In
Authorization Serverstab, select thedefault. - In
Claimstab, clickAdd Claim. - Enter the following information for the claim:
- Name:
groups. - Include in token type:
- Select
Access Token. - Keep
Alwaysin the right field.
- Select
- Value type:
Groups. - Filter:
- Select
Matches regex. - Set
.*in the right field.
- Select
- Include in:
Any scope. - Click
Createbutton.
- Name:
-
Open a terminal and inside
okta-springboot-reactroot folder run:docker compose up -d
-
Wait for
elasticsearchDocker container to be up and running. To check it, run:docker compose ps
-
jobs-api
-
In a terminal, navigate to
okta-springboot-react/jobs-apifolder. -
Export the following environment variables. Those values were obtained while adding Application:
export OKTA_DOMAIN=... export OKTA_CLIENT_ID=...
-
Run the
Mavencommand below to startjobs-api:./mvnw clean spring-boot:run
-
-
jobs-ui
-
Open a new terminal and navigate to
okta-springboot-react/jobs-uifolder. -
Create a file called
.env.localwith the following content. Those values were obtained while adding Application:REACT_APP_OKTA_ORG_URL=https://<OKTA_DOMAIN> REACT_APP_OKTA_CLIENT_ID=<OKTA_CLIENT_ID>
-
If you are running
jobs-uifor the first time, execute thenpmcommand below:npm install
-
To start
jobs-uirun:npm start
It will open
job-uiin a browser automatically.
-
| Application | URL |
|---|---|
| jobs-api | http://localhost:8080/swagger-ui.html |
| jobs-ui | http://localhost:3000 |
-
Open a browser and access http://localhost:3000.
-
Click
Loginin the navigation bar. -
The Okta login page will appear. Enter the username & password of the person added at the step
Configuring Okta > Add peopleand clickSign In. -
Done!
Note: If you are using the person
luigi.bros@test.com, you will not be able to create/update/delete a job because it doesn't have the required role for it.
In order to use just the jobs-api endpoints, you must have an JWT access token. Below are the steps to get it.
-
In a terminal, create the following environment variables. Those values were obtained while adding Application:
OKTA_DOMAIN=... OKTA_CLIENT_ID=...
-
Get Okta Access Token Url:
OKTA_ACCESS_TOKEN_URL="https://${OKTA_DOMAIN}/oauth2/default/v1/authorize?\ client_id=${OKTA_CLIENT_ID}\ &redirect_uri=http://localhost:8080/callback/token\ &scope=openid\ &response_type=token\ &response_mode=form_post\ &state=state\ &nonce=myNonceValue" echo $OKTA_ACCESS_TOKEN_URL
-
Copy the Okta Access Token Url from the previous step and paste it in a browser.
-
The Okta login page will appear. Enter the username & password of the person added at the step
Configuring Okta > Add peopleand clickSign Inbutton. -
It will redirect to
/callback/tokenendpoint ofjobs-apiand theAccess tokenwill be displayed, together with other information:{ "state": "state", "access_token": "eyJraWQiOiJyNFdY...", "token_type": "Bearer", "expires_in": "3600", "scope": "openid" }Note: In jwt.io, you can decode and verify the
JWTaccess token.
-
GET /api/jobs/newestThe
api/jobs/newestendpoint is public, so we can access it without any problem:curl -i http://localhost:8080/api/jobs/newest?number=2It should return:
HTTP/1.1 200 [{"id":"uuulE2sBTYouQKNL1uoV", ...},{"id":"u-ulE2sBTYouQKNL1-qb", ...}]
-
GET /api/jobswithout Access TokenTry to get the list of jobs without informing the access token:
curl -i http://localhost:8080/api/jobs
It should return:
HTTP/1.1 401
-
GET /api/jobswith Access TokenFirst, get the access token as explained in
Getting Access Tokensection. Then, create an environment variable for the access token:ACCESS_TOKEN=...
Call to get the list of jobs, providing the access token:
curl -i http://localhost:8080/api/jobs -H "Authorization: Bearer $ACCESS_TOKEN"Response
HTTP/1.1 200 {"content":[{"id":"uISqEWsBpDcNLtN2kZv3","title":"Expert Java Developer - Cloud","company":"Microsoft","logoUrl"...}
Note: If you are using the person
luigi.bros@test.com, you will not be able to create/update/delete a job because it doesn't have the required role for it.
-
First, get the access token as explained in
Getting Access Tokensection. -
Open
jobs-apiSwagger website http://localhost:8080/swagger-ui.html. -
Click
Authorizebutton. Paste the access token in theValuefield. Then, clickAuthorizeandCloseto finalize. -
Done! You can now access the sensitive endpoints.
Note: If you are using the person
luigi.bros@test.com, you will not be able to create/update/delete a job because it doesn't have the required role for it.
-
Go to the terminals where
jobs-apiandjobs-uiare running and pressCtrl+C. -
To stop and remove containers, network and volumes, run in a terminal the following command inside
okta-springboot-reactroot folder:docker compose down -v
- In the
Okta Admin Dashboardmain menu on the left, clickDirectorymenu and thenPeoplesub-menu. - Click
Mario Brosin the People list. - In
Mario Brosprofile, clickMore Actionsmulti-button and thenDeactivate. - Confirm deactivation by clicking
Deactivatebutton. - Still in
Mario Brosprofile, clickDeletebutton. - Confirm deletion by clicking
Deletebutton. - Click
Luigi Brosin the People list. - In
Luigi Brosprofile, clickMore Actionsmulti-button and thenDeactivate. - Confirm deactivation by clicking
Deactivatebutton. - Still in
Luigi Brosprofile, clickDeletebutton. - Confirm deletion by clicking
Deletebutton.
- In the
Okta Admin Dashboardmain menu on the left, clickDirectorymenu and thenGroupssub-menu. - Select
JOBS_CUSTOMER. - In
JOBS_CUSTOMERprofile, clickActionsbutton and thenDeletesub-button. - Confirm deletion by clicking
Delete Groupbutton. - Select
JOBS_STAFF. - In
JOBS_STAFFprofile, clickActionsbutton and thenDeletesub-button. - Confirm deletion by clicking
Delete Groupbutton.
- In the
Okta Admin Dashboardmain menu on the left, clickApplicationsmenu and thenApplicationssub-menu. - In Application list whose status is
ACTIVE, clickJobs Portal SPA'sgearicon and then clickDeactivate. - Confirm deactivation by clicking
Deactivate Applicationbutton. - In Application list whose status is
INACTIVE, clickJobs Portal SPA'sgearicon and then clickDelete. - Confirm deletion by clicking
Delete Applicationbutton.
- In the
Okta Admin Dashboardmain menu on the left, clickSecuritymenu and thenAPIsub-menu. - In
Authorization Serverstab, select thedefault. - In
Claimstab, click thexicon related to thegroupsclaim created. - Confirm deletion by clicking
OKbutton.
-
In a terminal, make sure you are in
okta-springboot-react/jobs-uifolder. -
Run the following commands:
npm upgrade npm i -g npm-check-updates ncu -u npm install


