<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Robin]]></title><description><![CDATA[Robin]]></description><link>https://robinbiju.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 11 Sep 2026 09:21:18 GMT</lastBuildDate><atom:link href="https://robinbiju.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How to secure a REST web service using OAUTH in Oracle APEX?]]></title><description><![CDATA[Securing RESTful web services is crucial to protect sensitive data and ensure authorized access. In Oracle APEX, integrating OAuth adds a robust layer of security by requiring users to authenticate and authorize access to your services. Registering y...]]></description><link>https://robinbiju.hashnode.dev/how-to-secure-a-rest-web-service-using-oauth-in-oracle-apex</link><guid isPermaLink="true">https://robinbiju.hashnode.dev/how-to-secure-a-rest-web-service-using-oauth-in-oracle-apex</guid><category><![CDATA[oracleapex]]></category><category><![CDATA[oracle ords]]></category><category><![CDATA[REST API]]></category><category><![CDATA[Apex]]></category><category><![CDATA[web services]]></category><category><![CDATA[APIs]]></category><category><![CDATA[API Gateway]]></category><dc:creator><![CDATA[Robin Biju]]></dc:creator><pubDate>Mon, 18 Nov 2024 12:30:26 GMT</pubDate><content:encoded><![CDATA[<p>Securing RESTful web services is crucial to protect sensitive data and ensure authorized access. In Oracle APEX, integrating OAuth adds a robust layer of security by requiring users to authenticate and authorize access to your services. Registering your schema with Oracle REST Data Services (ORDS) is a must to enable OAuth and leverage its capabilities. This article explores the step-by-step process of implementing OAuth for securing REST web services in Oracle APEX, ensuring your APIs are both accessible to intended users and resilient against unauthorized access.</p>
<ol>
<li><p><strong>Create a Module</strong>:</p>
<ul>
<li><p>In Oracle APEX, navigate to <strong>SQL Workshop</strong> &gt; <strong>RESTful Services</strong> and create a new module for your web service.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1731865916526/c331c14f-178c-4594-a095-772b44b9f7d0.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
<li><p><strong>Create a Web Service Under the Module</strong>:</p>
<ul>
<li><p>Define your web service within the module you created by adding the necessary templates, handlers, and configurations for the endpoints you want to expose.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1731866467069/cda8f601-36d5-4ec5-941a-9ddfd411a7fa.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
<li><p><strong>Create a Role and Privilege</strong>:</p>
<ul>
<li><p>To secure the web service, you need to create a role and privilege in Oracle APEX.</p>
</li>
<li><p><strong>Define a Role</strong>: Go to <strong>SQL Workshop</strong> &gt; <strong>RESTful Services</strong> &gt; <strong>Roles</strong> and create a new role (e.g., <code>empinfo-api-role</code>).</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1731866599210/d88bb17b-bae5-4f88-97d7-324205cdfbcf.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><strong>Define a Privilege</strong>: Go to <strong>SQL Workshop</strong> &gt; <strong>RESTful Services</strong> &gt; <strong>Privileges</strong> and create a new privilege.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1731866690142/7d53acf2-3e80-445f-be00-2cc286326a57.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p>In the privilege configuration, select the newly created role and module we want to secure.</p>
</li>
<li><p>Save the privilege to enforce security for the specified module.</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>Create OAuth Client Credentials</strong>:</p>
<ul>
<li><p>Now, create OAuth client credentials that are linked to the role and privilege created in the previous step.</p>
</li>
<li><p>Use the <code>OAUTH.CREATE_CLIENT</code> procedure from the <code>OAUTH</code> package with the required parameters.</p>
</li>
<li><p><strong>Parameters for</strong> <code>OAUTH.CREATE_CLIENT</code>:</p>
<ul>
<li><p><code>p_name</code>: Unique name for the client (e.g., <code>'rob-api-client'</code>).</p>
</li>
<li><p><code>p_grant_type</code>: Type of OAuth grant (e.g., <code>'client_credentials'</code>, <code>'authorization_code'</code>, or <code>'implicit'</code>).</p>
</li>
<li><p><code>p_owner</code>: Owner of the client application (optional).</p>
</li>
<li><p><code>p_description</code>: Description of the client, shown to the end user during approval (optional if using client credentials).</p>
</li>
<li><p><code>p_origins_allowed</code>: Comma-separated list of allowed URL prefixes.</p>
</li>
<li><p><code>p_redirect_uri</code>: URI for OAuth token or error redirects (required for non-client credentials flows).</p>
</li>
<li><p><code>p_support_email</code>: Support email for end-user inquiries.</p>
</li>
<li><p><code>p_privilege_names</code>: List of privileges the client is allowed to access.</p>
</li>
<li><p><code>p_token_duration</code>, <code>p_refresh_duration</code>, <code>p_code_duration</code>: Optional durations (in seconds) for access, refresh, and authorization code tokens, respectively.</p>
</li>
<li><p><strong>Note</strong>: Use a <code>COMMIT</code> statement after calling <code>OAUTH.CREATE_CLIENT</code> to ensure the changes are saved.</p>
</li>
</ul>
</li>
<li><p>Example</p>
</li>
</ul>
</li>
</ol>
<pre><code class="lang-sql">    <span class="hljs-keyword">BEGIN</span>
       oauth.create_client(
                          p_name =&gt; <span class="hljs-string">'rob-api-client'</span>
                        , p_grant_type =&gt; <span class="hljs-string">'client_credentials'</span>
                        , p_owner =&gt; <span class="hljs-string">'ROB'</span>
                        , p_description =&gt; <span class="hljs-string">'Client credentials for the web service used HR app'</span>
                        , p_support_email =&gt; <span class="hljs-string">'support@rob.com'</span>
                        , p_privilege_names =&gt; <span class="hljs-string">'empinfo-api-priv'</span>
       );

       <span class="hljs-keyword">COMMIT</span>;
    <span class="hljs-keyword">END</span>;
</code></pre>
<ol start="5">
<li><p><strong>Grant Role to the OAuth Client</strong>:</p>
<ul>
<li><p>Assign the role to the newly created OAuth client to give it the appropriate access.</p>
</li>
<li><p>Run the following PL/SQL block with the client name and associated role name:</p>
</li>
</ul>
</li>
</ol>
<pre><code class="lang-sql">    <span class="hljs-keyword">BEGIN</span>
       oauth.grant_client_role(
                              p_client_name =&gt; <span class="hljs-string">'rob-api-client'</span>
                            , p_role_name =&gt; <span class="hljs-string">'empinfo-api-role'</span>
       );
       <span class="hljs-keyword">COMMIT</span>;
    <span class="hljs-keyword">END</span>;
</code></pre>
<ol start="6">
<li><p><strong>Verify Client Credentials</strong>:</p>
<ul>
<li><p>After creating and configuring the OAuth client, you can query the client credentials for verification.</p>
</li>
<li><p>Execute the following SQL query in Oracle APEX to view client details:</p>
</li>
</ul>
</li>
</ol>
<pre><code class="lang-sql">    <span class="hljs-keyword">SELECT</span>
       <span class="hljs-keyword">id</span>
     , <span class="hljs-keyword">name</span>
     , auth_flow
     , response_type
     , client_id
     , client_secret
    <span class="hljs-keyword">FROM</span>
       user_ords_clients
    <span class="hljs-keyword">WHERE</span>
       <span class="hljs-keyword">name</span> = <span class="hljs-string">'CLIENT_NAME'</span>;
</code></pre>
<h2 id="heading-steps-to-test-the-web-service-in-postman"><strong>Steps to Test the Web Service in Postman</strong></h2>
<ol>
<li><p><strong>Open Postman</strong>:</p>
<ul>
<li>Launch Postman and navigate to <strong>File</strong> &gt; <strong>New</strong> &gt; <strong>HTTP Request</strong> to create a new request.</li>
</ul>
</li>
<li><p><strong>Set Up the HTTP Request</strong>:</p>
<ul>
<li><p><strong>Request Method</strong>: Select the HTTP method for your request (e.g., <strong>GET</strong>).</p>
</li>
<li><p><strong>URL</strong>: Enter the URL of your secured REST API. This should point to the specific endpoint you want to test.</p>
</li>
</ul>
</li>
<li><p><strong>Configure Authorization Settings</strong>:</p>
<ul>
<li><p>Go to the <strong>Authorization</strong> tab within the request setup.</p>
</li>
<li><p><strong>Type</strong>: Select <strong>OAuth 2.0</strong> from the dropdown.</p>
</li>
<li><p><strong>Add authorization data to</strong>: Choose <strong>Request Headers</strong> to include the OAuth token in the headers.</p>
</li>
</ul>
</li>
<li><p><strong>Configure and Use New Access Token:</strong></p>
<p> To authenticate with your REST web service, follow these steps to configure and use a new access token in Postman:</p>
<ol>
<li><p><strong>Enter Token Details:</strong></p>
<ul>
<li><p><strong>Token Name:</strong> Provide a name to identify this token in Postman.</p>
</li>
<li><p><strong>Grant Type:</strong> Select <strong>Client Credentials</strong>.</p>
</li>
<li><p><strong>Access Token URL:</strong> Enter the token endpoint URL in the following format:<br />  <a target="_blank" href="https://your-host/your-web-server/your-workspace/oauth/token%EF%BF%BCReplace"><code>https://your-host/your-web-server/your-workspace/oauth/token</code><br />  Replace</a> <code>your-host</code>, <code>your-web-server</code>, and <code>your-workspace</code> with the specific details of your APEX environment.</p>
</li>
<li><p><strong>Client ID:</strong> Enter the <strong>Client ID</strong> generated earlier in Oracle APEX.</p>
</li>
<li><p><strong>Client Secret:</strong> Enter the <strong>Client Secret</strong> generated earlier in Oracle APEX.</p>
</li>
</ul>
</li>
<li><p><strong>Obtain and Apply the Access Token:</strong></p>
<ul>
<li><p>Click <strong>Get New Access Token</strong> to request a new token.</p>
</li>
<li><p>When prompted by Postman, click <strong>Proceed</strong> to confirm.</p>
</li>
<li><p>Once the token is retrieved, click <strong>Use Token</strong> to add it to your request headers automatically.</p>
</li>
</ul>
</li>
</ol>
</li>
</ol>
<p>        <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1731869074037/517f52c4-885f-46b8-a1ef-20961348e2bd.jpeg" alt class="image--center mx-auto" /></p>
<ol start="5">
<li><p><strong>Send the Request</strong>:</p>
<ul>
<li><p>Click <strong>Send</strong> to execute the request and call your REST API.</p>
</li>
<li><p>Review the response to ensure the web service is functioning as expected.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1731868133454/396dbf54-d4e9-4f53-8d11-c61432f11bf4.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
</li>
</ol>
<p>This process allows you to securely access and test your Oracle APEX web service in Postman. If the request is successful, the web service is properly secured and accessible via OAuth 2.0.</p>
]]></content:encoded></item></channel></rss>