In this exercise, you will secure an API by using Red Hat Single Sign On (RHSSO).
Outcomes
You should be able to:
Configure 3scale API Management to synchronize with RHSSO.
Configure 3scale API Management to require a valid JSON Web Token (JWT) to authenticate an API call.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command:
Deploys and configures an RHSSO instance.
Deploys the application you will use in this exercise, which consists of:
Front end React-based application.
Back end API application.
Configures the product and backend in 3scale API Management.
[student@workstation ~]$ lab start secure-oauth
Procedure 4.3. Instructions
Verify that the books_api_v2 backend does not require Open ID Connect for authentication.
Get the application ID for the current application plan:
[student@workstation ~]$3scale application list 3scale-tenant \ --service=secure_oauthID NAME STATE ENABLED ACCOUNT_ID SERVICE_ID PLAN_ID7secure_oauth_app live true 3 3 10
Get the user key for the application, for example for an application with the ID 7:
[student@workstation ~]$ 3scale application show 3scale-tenant 7 \
-o json | jq -r '.user_key'
acaa2950a6124cd27a45194c023d2a3dUse the key to call the books-api service:
[student@workstation ~]$ curl \
"https://secure-oauth-3scale-apicast-staging.apps.ocp4.example.com/books?user_key=acaa2950a6124cd27a45194c023d2a3d" \
| jq
...output omitted...The API call succeeds without a JWT token.
Add the RHSSO certificate chain to the 3scale API Management certificate chain.
This step is necessary because the 3scale API Management Zync pod does not trust the self-signed certificates of RHSSO.
Examine the /home/student/DO240/labs/secure-oauth/inject_rhsso_ca.sh script.
Execute the script:
[student@workstation ~]$ sh \
/home/student/DO240/labs/secure-oauth/inject_rhsso_ca.sh
...output omitted...
configmap/zync-new-ca-bundle created
deploymentconfig.apps.openshift.io/zync-que volume updated
deploymentconfig.apps.openshift.io/zync-que updatedVerify that the zync pod in the 3scale project is in the Running state:
[student@workstation ~]$oc -n 3scale get pods \ -l threescale_component_element=zync-queNAME READY STATUS RESTARTS AGE zync-que-3-jmsst 1/1Running08s
Create the zync-client RHSSO client.
Use the pre-created zync-client.json file.
The zync-client.json file creates a client configured as a service account in RHSSO.
Execute the following command to get the RHSSO password:
[student@workstation ~]$ oc -n rhsso get secret \
credential-keycloak --template={{.data.ADMIN_PASSWORD}} \
| base64 -d ; echo
7jpffNJgZTG8yA==In a web browser, navigate to the following URL:
https://keycloak-rhsso.apps.ocp4.example.com/auth/admin/master/console/#/realms/do240
Log in as admin with the password from the previous step.
Click , then click .
Click and select the /home/student/DO240/labs/secure-oauth/zync-client.json file.
Then, click .
Click the tab. In the section, select Realm Management.
Click manage clients, then click .
Click the tab. You will require the value later.
Keep the browser tab open.
Integrate the secure_oauth product with RHSSO.
In a new browser tab, log in to the the 3scale API Management Administration Portal as the admin user.
Execute the following command to see the ADMIN_PASSWORD:
[student@workstation ~]$ oc get secret system-seed -n 3scale \
-o json | jq -r .data.ADMIN_PASSWORD | base64 -d; echo
...output omitted...In the section, click the secure_oauth product.
Click → .
In the section, select OpenID Connect Use OpenID Connect for any OAuth 2.0 flow.
In the section, construct the URL in the following format:
https://CLIENT-ID:CLIENT-SECRET@RHSSO-URL
Use the following parameters:
Client-id: zync-client
Client-secret: Copy the Secret value from the RHSSO web console.
RHSSO URL: keycloak-rhsso.apps.ocp4.example.com/auth/realms/do240
For example:
https://zync-client:f6f0..7dd4@keycloak-rhsso.apps.ocp4.example.com/auth/realms/do240
Click . Then, click and click .
Create a new Application.
Click → . Then, click .
Select the Developer account, secure_oauth product, and the secure_oauth_basic application plan.
Enter the following:
: sso_app
: sso_app
Then, click .
Note the number of your application, for example 7308b6b9.
Change the sso_app RHSSO client visibility.
Use the following configuration:
Access Type: public
Public access type is for client-side clients that perform a browser login. This means the application requires only the client ID to authenticate the request.
Valid Redirect URIs: *
RHSSO can redirect a request that is authenticated by this client to any URL.
Web Origins: *
RHSSO configures the Access-Control-Allow-Origin header for responses that are authenticated by this client.
This is important for browser Cross-Origin Resource Sharing (CORS) configuration.
The RHSSO client configuration is simplified for testing purposes.
In the RHSSO Administration Console browser tab, click .
Click the newly created client, for example 7308b6b9.
Verify that the name of the client is sso_app.
Change the following properties:
Access Type: public
Valid Redirect URIs: *
Web Origins: *
Then, click .
Modify the front end application to use the sso_app client.
Edit the book-config configuration map in the secure-oauth project, and change the REACT_APP_CLIENT_ID property to the client ID of the sso_app
[student@workstation ~]$oc edit cm book-config -n secure-oauthapiVersion: v1 data: REACT_APP_CLIENT_ID:7308b6b9...output omitted...
Delete the front end pod.
The new pod receives the updated REACT_APP_CLIENT_ID value.
[student@workstation ~]$ oc -n secure-oauth delete pod \
-l app=books-frontend
pod "books-frontend-v2-f5658556-57vqh" deletedEnable CORS for the secure_oauth product.
In the 3scale API Management Administration Portal, open the secure_oauth product.
Click → .
Then, click and select the CORS Request Handling policy.
Move the CORS Request Handling policy to the start of the policy chain.
Failure to put the CORS policy as the first policy in the policy chain might result in the front end application not working.
Click the CORS Request Handling policy.
Enter the following configuration:
allow_origin: *
Then, click , and .
Promote the configuration to the staging APIcast.
In a web browser, visit the following URL:
http://books-frontend-secure-oauth.apps.ocp4.example.com
Log in with the user student and password redhat.
You can examine the RHSSO student user by viewing the /home/student/DO240/labs/secure-oauth/04_user.yml file.
![]() |
This concludes the guided exercise.