Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

apex_web_service.oauth_authenticate returning ORA-20001: Authentication failed.

Parul JainMar 5 2024

Hi,

I am calling OIC Integration API from Oracle apex 23.2 using Oauth2.0.

In IDCS , created one confidential application and below is the configuration:

  1. Redirect URL I have added OIC callback URL, eg:
    https://OIC_instance_URL.region.ocp.oraclecloud.com/icsapis/agent/oauth/callback
  2. Selected grant type Authorization Code and refresh token
  3. Added scope: urn:opc:resource:consumer::all and /ic/api/
  4. Added ServiceUser role .
  5. Have the client ID and secret generated.

In Postman, by having above configuration I am able to generate token and OIC integration response is 200 OK.

In Apex I am using PLSQL code to call the Integration and below is the code:

DECLARE
l_response CLOB;
l_req_body CLOB;
l_oic_url VARCHAR2(300);
BEGIN
apex_web_service.g_request_headers.DELETE;
dbms_output.put_line('Starting the code.');
l_oic_url := 'https://OIC_INTEGRATION_API_ENDPOINT';
-- call the oauth_authenticate procedure to get a Token,
-- based on your Client_Id and Client_Secret
apex_web_service.oauth_authenticate(p_token_url => 'https://IDCS-URL/oauth2/v1/token',
p_client_id => '1234abcd', p_client_secret => '9876xyz1'
, p_scope => 'https://SCOPE_URLurn:opc:resource:consumer::all');

-- set the request Authorization header
apex_web_service.g_request_headers(1).name := 'Authorization';
apex_web_service.g_request_headers(1).value := 'Bearer ' || apex_web_service.oauth_get_last_token;
apex_web_service.g_request_headers(2).name := 'Content-Type';
apex_web_service.g_request_headers(2).value := 'application/json';

--create the JSON request body
apex_json.initialize_clob_output();
apex_json.open_object();
apex_json.write('param1', '12345');
apex_json.close_all();
l_req_body := apex_json.get_clob_output();
apex_json.free_output();
dbms_output.put_line('l_req_body=' || l_req_body);
l_response := apex_web_service.make_rest_request(p_url => l_oic_url,
p_http_method => 'POST',
p_transfer_timeout => 10,
p_body => l_req_body
);
dbms_output.put_line('Response Status : ' || apex_web_service.g_status_code);
dbms_output.put_line('Response Payload: ' || l_response);
END;

And I am getting Error: ORA-20001: Authentication failed.

Please help me to resolve the issue.

This post has been answered by Carsten Czarski-Oracle on Mar 5 2024
Jump to Answer
Comments
Post Details
Added on Mar 5 2024
3 comments
1,524 views