I am trying to get the token value,they are using Oauth 2.0 authorization method they are using for authentication purpose
I am passing the username,password,cient authentication and grant_type
I have set the proxy and oracle wallet,there is no issue with this as other HTTPS requests are going hard coded token value
can you please advise what is wrong with the Procedure?
can you share sample program for Oauth 2.0 Token authenetication request
I
PROCcreate or replace PROCEDURE tokenreq IS
l_http_auth_req UTL_HTTP.req;
l_http_auth_resp UTL_HTTP.resp;
buffer VARCHAR2(32766);
error_message CLOB;
l_response CLOB;
l_response_tmp varchar2(1024);
content VARCHAR2 (32766);
l_http_auth_url VARCHAR2(300) := '
https://api.a2zinc.net/Token'; l_http_ver VARCHAR2(20) := 'HTTP/1.1';
l_http_req_mthd VARCHAR2(20) := 'POST';
l_token_req_payload varchar2(4000);
l_username VARCHAR2(100) := 'username';
l_password VARCHAR2(100) := 'password';
l_clientcred VARCHAR2(200) := l_username|| ':'||l_password;
l_auth_value VARCHAR2(100) := 'Basic '||utl_raw.cast_to_varchar2(utl_encode.base64_encode(utl_i18n.string_to_raw(l_clientcred)));
BEGIN
UTL_HTTP.set_detailed_excp_support(TRUE);
UTL_HTTP.SET_RESPONSE_ERROR_CHECK(TRUE);
l_token_req_payload := 'client_id=iplus&client_secret=CLIENT_SECRET&grant_type=password&scope=client:SCOPE';
UTL_HTTP.set_proxy('
http://hkmacedonia.globalsources.com:3333', '
https://api.a2zinc.net:443' );
UTL_HTTP.set_wallet('file:/ndb3000/oracle/software/product/db/12.2.0.1_SE/network/admin/wallet', 'WalletPasswd123');
UTL_HTTP.set_transfer_timeout(180);
l_http_auth_req := utl_http.begin_request(l_http_auth_url, l_http_req_mthd );
UTL_HTTP.set_authentication(l_http_auth_req, l_auth_value);
dbms_output.put_line('setting header...');
UTL_HTTP.set_header (l_http_auth_req, 'Content-Length', LENGTH(l_token_req_payload));
UTL_HTTP.set_header(l_http_auth_req, 'Content-Type', 'application/x-www-form-urlencoded');
-- Write request text data in the HTTP request
--UTL_HTTP.write_text (l_http_auth_req, utl_url.escape(l_token_req_payload));
UTL_HTTP.write_text (l_http_auth_req, l_token_req_payload);
dbms_output.put_line('get response...');
l_http_auth_resp := UTL_HTTP.get_response(l_http_auth_req);
dbms_output.enable(100000000);
dbms_output.put_line('RESPONSE: ');
dbms_output.put_line('HTTP response status code: ' || l_http_auth_resp.status_code);
dbms_output.put_line('HTTP response reason phrase: ' || l_http_auth_resp.reason_phrase);
DBMS_OUTPUT.put_line('GETTING RESPONSE HEADERS! ');
BEGIN
LOOP
utl_http.read_line(l_http_auth_resp, l_response_tmp, FALSE);
l_response := l_response || l_response_tmp;
dbms_output.put_line(l_response);
END LOOP;
EXCEPTION
WHEN UTL_HTTP.end_of_body THEN
UTL_HTTP.end_response(l_http_auth_resp);
error_message := UTL_HTTP.get_detailed_sqlerrm;
dbms_output.put_line(error_message);
WHEN Utl_Http.request_failed THEN
DBMS_OUTPUT.put_line ('Request_Failed: ' || Utl_Http.get_detailed_sqlerrm);
Utl_Http.end_request (r => l_http_auth_req);
WHEN Utl_Http.http_server_error THEN
DBMS_OUTPUT.put_line ('Http_Server_Error: ' || Utl_Http.get_detailed_sqlerrm);
Utl_Http.end_request (r => l_http_auth_req);
WHEN Utl_Http.http_client_error THEN
DBMS_OUTPUT.put_line ('Http_Client_Error: ' || Utl_Http.get_detailed_sqlerrm);
Utl_Http.end_request (r => l_http_auth_req);
when others then
DBMS_OUTPUT.put_line('HTTP ERROR: ' || utl_http.get_detailed_sqlerrm);
END;
END tokenreq;
ErrorBEGIN tokenreq; END;
Error report -
ORA-29269: HTTP server error 500 - Internal Server Error
ORA-06512: at "SYS.UTL_HTTP", line 1267
ORA-06512: at "SYS.UTL_HTTP", line 651
ORA-06512: at "SYS.UTL_HTTP", line 1257
ORA-06512: at "WWW_ASM.TOKENREQ", line 39
ORA-06512: at line 1
29269. 00000 - "HTTP server error %s"
*Cause: The HTTP response indicated that the HTTP server error occurred.
*Action: Fix the HTTP server error and retry the HTTP request. Contact
the admistrator of the HTTP server when necessary.