My need is to obtain a token from Oracle ORDS with an already authenticated user. I am following this documentation to dev a javascript using fetch.

I am stuck at the point

$ curl -i -k --user 3NvJRo_a0UwGKx7Q-kivtA..:F5WVwyrWxXj3ykmhSONldQ.. --data "grant_type=client_credentials" https://ol7-121.localdomain:8443/ords/pdb1/testuser1/oauth/token HTTP/1.1 200 OK Server: Apache-Coyote/1.1 X-Frame-Options: SAMEORIGIN Content-Type: application/json Transfer-Encoding: chunked Date: Wed, 29 Jun 2016 12:07:02 GMT

{"access_token":"-zYl-sFyB2iLicAHw2TsRA..","token_type":"bearer","expires_in":3600} $

Based on this example i set my curl as below and test it in my host's command line and it responds with a valid token as expected

curl -i -k --user Uj1xXqz5pNRoSubJ6v3Hdg..:Npvid_qzM75NrO978NKl0A.. --data "grant_type=client_credentials" http://myhost:8080/ords/myrest/oauth/token

Next I try to convert the verified curl commad as a fetch request in this way but it responds with a 500 Internal Server Error:

fetch('http://myhost:8080/ords/myrest/oauth/token',
{
    method: 'POST',
    headers: {
        'Authorization': 'Basic Uj1xXqz5pNRoSubJ6v3Hdg..:Npvid_qzM75NrO978NKl0A..'
    },
    body: 'grant_type=client_credentials'
})...

I can't figure it out what I am doing wrong or what I am missing although I am searching and trying different variations. Advices and suggestions will be appreciated.

************ EDIT : Following advices in comments I try to go some steps further ************

About the OPTIONS request I inspect the network activity (as a first try I use developer tools of browser) and I found the headers with method OPTIONS and status code 200.

After that considering that I have deployed ORDS via Tomcat, I modify default.xml in /app/oracle/ora_rest/params as stated in this documentation. Now I am able to retrive e full description of the error and I am still trying to config/inspect logs.

The full trace of the error is :

InternalServerException [statusCode=500, reasons=[An unexpected error with the following message occurred: String length must be a multiple of four.]] at oracle.dbtools.http.errors.ServletResponseExceptionMapper.mapError(ServletResponseExceptionMapper.java:84) at oracle.dbtools.http.errors.ErrorPageRenderer.(ErrorPageRenderer.java:43) at oracle.dbtools.http.errors.ErrorPageRenderer.(ErrorPageRenderer.java:35) at oracle.dbtools.http.errors.ErrorPageFilter.doFilter(ErrorPageFilter.java:119) at oracle.dbtools.http.filters.HttpFilter.doFilter(HttpFilter.java:47) at oracle.dbtools.http.filters.FilterChainImpl.doFilter(FilterChainImpl.java:64) at oracle.dbtools.http.auth.ForceAuthFilter.doFilter(ForceAuthFilter.java:44) at oracle.dbtools.http.filters.HttpFilter.doFilter(HttpFilter.java:47) at oracle.dbtools.http.filters.FilterChainImpl.doFilter(FilterChainImpl.java:64) at oracle.dbtools.http.filters.Filters.filter(Filters.java:47) at oracle.dbtools.http.entrypoint.EntryPoint.service(EntryPoint.java:82) at oracle.dbtools.http.entrypoint.EntryPointServlet.service(EntryPointServlet.java:49) at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) at oracle.dbtools.rt.web.HttpEndpointBase.dispatchableServices(HttpEndpointBase.java:116) at oracle.dbtools.rt.web.HttpEndpointBase.service(HttpEndpointBase.java:81) at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:475) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:495) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:767) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1354) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:745) Caused by: java.lang.IllegalArgumentException: String length must be a multiple of four. at oracle.dbtools.common.util.Base64.base64ToByteArray(Base64.java:43) at oracle.dbtools.common.util.Base64.base64ToByteArray(Base64.java:23) at oracle.dbtools.http.auth.HttpBasicAuthenticationHandler.extractCredentials(HttpBasicAuthenticationHandler.java:38) at oracle.dbtools.http.auth.HttpBasicAuthenticationHandler.(HttpBasicAuthenticationHandler.java:21) at oracle.dbtools.http.auth.HttpBasicAuthentication.(HttpBasicAuthentication.java:15) at oracle.dbtools.http.auth.AuthenticationFilter.authenticate(AuthenticationFilter.java:69) at oracle.dbtools.http.auth.AuthenticationFilter.doFilter(AuthenticationFilter.java:62) at oracle.dbtools.http.filters.HttpFilter.doFilter(HttpFilter.java:47) at oracle.dbtools.http.filters.FilterChainImpl.doFilter(FilterChainImpl.java:64) at oracle.dbtools.url.mapping.RequestMapperImpl.doFilter(RequestMapperImpl.java:125) at oracle.dbtools.url.mapping.URLMappingBase.doFilter(URLMappingBase.java:103) at oracle.dbtools.url.mapping.filter.URLMappingFilter.doFilter(URLMappingFilter.java:124) at oracle.dbtools.http.filters.HttpFilter.doFilter(HttpFilter.java:47) at oracle.dbtools.http.filters.FilterChainImpl.doFilter(FilterChainImpl.java:64) at oracle.dbtools.http.cors.CORSResponseFilter.doFilter(CORSResponseFilter.java:83) at oracle.dbtools.http.filters.HttpResponseFilter.doFilter(HttpResponseFilter.java:45) at oracle.dbtools.http.filters.FilterChainImpl.doFilter(FilterChainImpl.java:64) at oracle.dbtools.http.errors.ErrorPageFilter.doFilter(ErrorPageFilter.java:94) ... 34 more

1

There are 1 best solutions below

0
On

The line

[...]Caused by: java.lang.IllegalArgumentException: String length must be a multiple of four. at oracle.dbtools.common.util.Base64.base64ToByteArray(Base64.java:43) [...]

lead me to modify the request headers passing the client_id:client_secret (authdata) base64 converted (window.btoa(authdata)), like this way:

fetch('http://myhost:8080/ords/myrest/oauth/token',
    {
        method: 'POST',
        headers: {
            'Authorization': 'Basic ' + window.btoa(authdata),
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        body: 'grant_type=client_credentials'
    })...

The fetch is now responding correctly with the access_token value and I can use it to make authorized GET requests.