Oracle ORDS OAuth2, 500 error with “String length must be a multiple of four” from...
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
java oracle oauth fetch-api oracle-ords
add a comment |
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
java oracle oauth fetch-api oracle-ords
1
Try insteadcurl -X OPTIONSwith that same URL and parameters — because your browser is sending an OPTIONS request before ever even trying the POST request from your code. A CORS preflight OPTIONS request. And it’s doing that because you’re adding an Authorization header to the request.
– sideshowbarker
Nov 23 '18 at 11:07
@sideshowbarker : thanks for your reply, I edit my question because of your comment. Maybe I don't focus on what was my problem. I don't need a curl command but from a verified one I need to set a javascript fetch option object.
– AlexMI
Nov 23 '18 at 13:20
1
do you have access to the ords logs? it should show what's happening behind the 500s
– thatjeffsmith
Nov 23 '18 at 14:23
1
I realize you don’t need a curl command. What I’m telling you is that if you want to try to reproduce the 500 error with curl, you need to make curl send an OPTIONS request. Because the 500 error you’re getting in the browser is a response to an OPTIONS request, not a response to a POST request. Anyway, as @thatjeffsmith points out, you should inspect that server logs to see what information the server is logging when whatever internal server failure happens that causes the server to respond with a 500 error.
– sideshowbarker
Nov 23 '18 at 20:49
At this point I edit/update my answer for better documentation
– AlexMI
Nov 27 '18 at 8:11
add a comment |
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
java oracle oauth fetch-api oracle-ords
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
java oracle oauth fetch-api oracle-ords
java oracle oauth fetch-api oracle-ords
edited Nov 28 '18 at 15:45
AlexMI
asked Nov 23 '18 at 10:13
AlexMIAlexMI
2401317
2401317
1
Try insteadcurl -X OPTIONSwith that same URL and parameters — because your browser is sending an OPTIONS request before ever even trying the POST request from your code. A CORS preflight OPTIONS request. And it’s doing that because you’re adding an Authorization header to the request.
– sideshowbarker
Nov 23 '18 at 11:07
@sideshowbarker : thanks for your reply, I edit my question because of your comment. Maybe I don't focus on what was my problem. I don't need a curl command but from a verified one I need to set a javascript fetch option object.
– AlexMI
Nov 23 '18 at 13:20
1
do you have access to the ords logs? it should show what's happening behind the 500s
– thatjeffsmith
Nov 23 '18 at 14:23
1
I realize you don’t need a curl command. What I’m telling you is that if you want to try to reproduce the 500 error with curl, you need to make curl send an OPTIONS request. Because the 500 error you’re getting in the browser is a response to an OPTIONS request, not a response to a POST request. Anyway, as @thatjeffsmith points out, you should inspect that server logs to see what information the server is logging when whatever internal server failure happens that causes the server to respond with a 500 error.
– sideshowbarker
Nov 23 '18 at 20:49
At this point I edit/update my answer for better documentation
– AlexMI
Nov 27 '18 at 8:11
add a comment |
1
Try insteadcurl -X OPTIONSwith that same URL and parameters — because your browser is sending an OPTIONS request before ever even trying the POST request from your code. A CORS preflight OPTIONS request. And it’s doing that because you’re adding an Authorization header to the request.
– sideshowbarker
Nov 23 '18 at 11:07
@sideshowbarker : thanks for your reply, I edit my question because of your comment. Maybe I don't focus on what was my problem. I don't need a curl command but from a verified one I need to set a javascript fetch option object.
– AlexMI
Nov 23 '18 at 13:20
1
do you have access to the ords logs? it should show what's happening behind the 500s
– thatjeffsmith
Nov 23 '18 at 14:23
1
I realize you don’t need a curl command. What I’m telling you is that if you want to try to reproduce the 500 error with curl, you need to make curl send an OPTIONS request. Because the 500 error you’re getting in the browser is a response to an OPTIONS request, not a response to a POST request. Anyway, as @thatjeffsmith points out, you should inspect that server logs to see what information the server is logging when whatever internal server failure happens that causes the server to respond with a 500 error.
– sideshowbarker
Nov 23 '18 at 20:49
At this point I edit/update my answer for better documentation
– AlexMI
Nov 27 '18 at 8:11
1
1
Try instead
curl -X OPTIONS with that same URL and parameters — because your browser is sending an OPTIONS request before ever even trying the POST request from your code. A CORS preflight OPTIONS request. And it’s doing that because you’re adding an Authorization header to the request.– sideshowbarker
Nov 23 '18 at 11:07
Try instead
curl -X OPTIONS with that same URL and parameters — because your browser is sending an OPTIONS request before ever even trying the POST request from your code. A CORS preflight OPTIONS request. And it’s doing that because you’re adding an Authorization header to the request.– sideshowbarker
Nov 23 '18 at 11:07
@sideshowbarker : thanks for your reply, I edit my question because of your comment. Maybe I don't focus on what was my problem. I don't need a curl command but from a verified one I need to set a javascript fetch option object.
– AlexMI
Nov 23 '18 at 13:20
@sideshowbarker : thanks for your reply, I edit my question because of your comment. Maybe I don't focus on what was my problem. I don't need a curl command but from a verified one I need to set a javascript fetch option object.
– AlexMI
Nov 23 '18 at 13:20
1
1
do you have access to the ords logs? it should show what's happening behind the 500s
– thatjeffsmith
Nov 23 '18 at 14:23
do you have access to the ords logs? it should show what's happening behind the 500s
– thatjeffsmith
Nov 23 '18 at 14:23
1
1
I realize you don’t need a curl command. What I’m telling you is that if you want to try to reproduce the 500 error with curl, you need to make curl send an OPTIONS request. Because the 500 error you’re getting in the browser is a response to an OPTIONS request, not a response to a POST request. Anyway, as @thatjeffsmith points out, you should inspect that server logs to see what information the server is logging when whatever internal server failure happens that causes the server to respond with a 500 error.
– sideshowbarker
Nov 23 '18 at 20:49
I realize you don’t need a curl command. What I’m telling you is that if you want to try to reproduce the 500 error with curl, you need to make curl send an OPTIONS request. Because the 500 error you’re getting in the browser is a response to an OPTIONS request, not a response to a POST request. Anyway, as @thatjeffsmith points out, you should inspect that server logs to see what information the server is logging when whatever internal server failure happens that causes the server to respond with a 500 error.
– sideshowbarker
Nov 23 '18 at 20:49
At this point I edit/update my answer for better documentation
– AlexMI
Nov 27 '18 at 8:11
At this point I edit/update my answer for better documentation
– AlexMI
Nov 27 '18 at 8:11
add a comment |
1 Answer
1
active
oldest
votes
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.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53444681%2foracle-ords-oauth2-500-error-with-string-length-must-be-a-multiple-of-four-fr%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 28 '18 at 15:46
AlexMIAlexMI
2401317
2401317
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53444681%2foracle-ords-oauth2-500-error-with-string-length-must-be-a-multiple-of-four-fr%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Try instead
curl -X OPTIONSwith that same URL and parameters — because your browser is sending an OPTIONS request before ever even trying the POST request from your code. A CORS preflight OPTIONS request. And it’s doing that because you’re adding an Authorization header to the request.– sideshowbarker
Nov 23 '18 at 11:07
@sideshowbarker : thanks for your reply, I edit my question because of your comment. Maybe I don't focus on what was my problem. I don't need a curl command but from a verified one I need to set a javascript fetch option object.
– AlexMI
Nov 23 '18 at 13:20
1
do you have access to the ords logs? it should show what's happening behind the 500s
– thatjeffsmith
Nov 23 '18 at 14:23
1
I realize you don’t need a curl command. What I’m telling you is that if you want to try to reproduce the 500 error with curl, you need to make curl send an OPTIONS request. Because the 500 error you’re getting in the browser is a response to an OPTIONS request, not a response to a POST request. Anyway, as @thatjeffsmith points out, you should inspect that server logs to see what information the server is logging when whatever internal server failure happens that causes the server to respond with a 500 error.
– sideshowbarker
Nov 23 '18 at 20:49
At this point I edit/update my answer for better documentation
– AlexMI
Nov 27 '18 at 8:11