Configuring Clarity's Public and Secure API Access
Liferay's service access policies control remote access to web services, ensuring only permitted methods are invoked. OAuth 2.0 provides an additional security layer, registering known to complete authorization. Proper configuration protects your environment by restricting access to approved entities, retrieving sensitive data securely, and ensuring seamless integration with strict access control when leveraging Liferay's headless APIs. Clarity's team would like to test publicizing endpoints with service access policies and implementing OAuth 2.0 security to protect document requests.
In these exercises, you'll configure a service access policy to enable securely fetching and displaying Clarity's blogs within dashboards. Additionally, you'll restrict access to secure documents by registering an OAuth 2.0 application.
Exercise: Retrieving Clarity's Blogs with Headless APIs
Here, you'll consume headless APIs to retrieve Clarity's existing blog posts and access the blogs API endpoint to verify its service signature (used to connect the component via the installed service class’s fully qualified name).
-
Sign in as the Clarity Admin user.
- Username:
admin@clarityvisionsolutions.com
- Password:
learn
- Username:
-
Open the Site Menu (
), expand Configuration, and click Site Settings. -
Under the Platform section, click Site Configuration.
-
From the Details tab, copy the Site ID for use in a later step.
-
Navigate to the API Explorer at http://localhost:8080/o/api.
-
Within the default Headless Delivery REST application, search for the
getSiteBlogPostingsPage
BlogPosting endpoint.This endpoint has a single required parameter: the
siteId
. -
Enter your Site ID value as the
siteId
parameter of thegetSiteBlogPostingsPage
endpoint. -
Click Execute.
Several useful pieces of information are shown, including the
- Curl command for executing this request from a terminal or third-party platform.
- Request URL.
- HTTP Response code.
- Response body containing a list of blog postings from the Clarity Public Enterprise website.
- Response headers.
-
Search for "headline" within the response body to review the returned blog titles.
Next, you'll test calling the request URL using the same method as Clarity's dashboards. -
Copy the Request URL of the endpoint for later steps.
-
Open a new browser window in Incognito mode and paste the Request URL.
-
You will see the following error message indicating that access is denied:
This error provides valuable information by displaying theBlogPosting
service signature, which you will use to configure the service access policy.
Great! You've retrieved Clarity's blog posts and verified the required service signature.
Exercise: Creating Clarity's Blogs Service Access Policy
Here, you'll configure a service access policy to enable public access to the blog posting API endpoint for Clarity's dashboards.
-
Signed in as the Clarity Admin on your Liferay instance, open the Global Menu (
), go to the Control Panel tab, and click Service Access Policy. -
Click New.
-
Enter the following information for the new service access policy:
- Name: BLOGS_POSTING_API_ACCESS
- Enabled: True
- Default: True
- Title: Grants access to the BLOGS POSTING API requests
-
Click Switch to Advanced Mode.
-
Within Allowed Service Signatures, paste the previously identified service signature:
-
Click Save.
Now, you'll retry calling the REST API's request URL to simulate an API call from a dashboard. -
Open a new browser window in Incognito mode and navigate to the Request URL copied in the previous exercise.
You should now see a list of blog posts available to display within dashboards, as public access has been granted through the configured service access policy.
Exercise: Restricting Clarity's Secure Document Access with OAuth 2.0
Here, you'll register an OAuth 2.0 application to securely retrieve document data and display it with real-time updates within Clarity's dashboards.
-
Signed in as the Clarity Admin on your Liferay instance, open the Global Menu (
), go to the Control Panel tab, and click Roles. -
Create a new Regular Role called 'Headless API'.
-
Assign the new Headless API Role to the Clarity Dashboard System Account user.
With a system user configured for testing purposes, you're ready to create an OAuth 2 application to read data on the user's behalf.
-
Open the Global Menu (
), go to the Control Panel tab, and click OAuth 2 Administration. -
Click New.
-
Fill out the following fields.
Field Value Name Clarity Dashboard Website URL http://localhost:8080/ Callback URIs http://localhost:8080/ Client Authentication Method Client Secret Basic or Post Client Profile Web Application Allowed Authorization Types Client Credentials
orJWT_BEARER
Client Credentials User Clarity Dashboard System Account NOTE
The token's access permissions for thecurl
call are determined by the permissions of the user referenced in the Client Credentials User. -
Click Save.
-
Click Edit for the Client Secret, and copy the displayed secret for use in a later step.
-
Copy the Client ID for use in a later step.
-
Click the Scopes tab.
-
Select the
LIFERAY.HEADLESS.DELIVERY
service access policy. -
Check the read data on your behalf checkbox.
-
Click Save.
Now, you're ready to grant permissions to the Headless API role to create tokens used in curl calls. -
Open the Global Menu (
), go to the Control Panel tab, and click OAuth 2 Administration. -
Click Actions (
) for Clarity Dashboard and select Permissions. -
Grant the Create Token permission for the Headless API role.
-
Click Save.
Next, you'll acquire the access token and test it with a curl command. -
Open a terminal window.
-
In a terminal window, replace the
WindowsCLIENT-ID
andCLIENT-SECRET
placeholder values with your own and execute the following command:
Non-Windows -
Copy the returned access token. Example below:
NOTE
This access authorization token acts as your credentials, granting permission to interact with the API. -
In your terminal, replace the
WindowsSITE-ID
andACCESS_TOKEN
placeholders and execute the following command:
Non-Windows
Using the configured OAuth 2.0 application, you're able to receive document information securely through Liferay's headless APIs.
Conclusion
Great! You've successfully configured Clarity's API access by enabling public access for blog content and securing document data with OAuth2 authentication. This approach balances open access for public resources while enforcing security for restricted assets, keeping Clarity's integrations both accessible and protected.
Next, you'll learn how to consume the API in both frontend and backend contexts.
Capabilities
Product
Education
Contact Us