Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting HTTP400 error using oauth2 #20

Closed
jigsheth57 opened this issue Apr 23, 2015 · 11 comments
Closed

getting HTTP400 error using oauth2 #20

jigsheth57 opened this issue Apr 23, 2015 · 11 comments

Comments

@jigsheth57
Copy link

Bad response code: 400 on request:
POST https://login.salesforce.com/services/oauth2/token

@jesperfj
Copy link
Owner

You're going to have to provide a bit more info.

@jigsheth57
Copy link
Author

Hi Jesper,

Here’s the error I’m getting when I use the ForceApi. It works fine using curl or wiztool.org http://wiztool.org/ rest client. Thanks for your help.

curl https://login.salesforce.com/services/oauth2/token -d 'grant_type=password&client_id=3MVG9A2kN3Bn17hv8siDyJtftcr88aXG3TpBJIqO8QZac_dpXPEoQy08vgi651aB8y6QdfgCkW0HsDIyQeH1V&client_secret=4631320832041516337&username=jigsheth@sfdc.com&password=' -H "X-PrettyPrint: 1"

{
"id" : "https://login.salesforce.com/id/00Di0000000kAFYEA2/005i0000002Z43XAAS",
"issued_at" : "1429788782137",
"token_type" : "Bearer",
"instance_url" : "https://na15.salesforce.com",
"signature" : "aIKixWUZsLAZLaa72mfVDCmaBxzZGyO7ZUol5z0xdgM=",
"access_token" : "00Di0000000kAFY!AQUAQGV_gZBjcCTZXY_nKLWo0x1t0iFTmB1f_w.GjIZgyfyW8IT3oMDW4VRaTZ.bYLMrPWp0Pfy120ShyhnY2EuVDkYHg1Ry"
}

    ApiConfig apiConfig = new ApiConfig()
    .setUsername("jigsheth@sfdc.com")
    .setPassword(“<password><token>")
    .setClientId("3MVG9A2kN3Bn17hv8siDyJtftcr88aXG3TpBJIqO8QZac_dXPEoQy08vgi651aB8y6QdfgCkW0HsDIyQeH1V")
    .setClientSecret("4631320832041516337");
    ForceApi api = new ForceApi(apiConfig);

Error Log >>>>>>>>>>>>>>>>

Bad response code: 400 on request:
POST https://login.salesforce.com/services/oauth2/token
Content-Type: application/x-www-form-urlencoded; charset=UTF-8

grant_type=password&client_id=3MVG9A2kN3Bn17hv8siDyJtftcr88aXG3TpBJIqO8QZac_dXPEoQy08vgi651aB8y6QdfgCkW0HsDIyQeH1V&client_secret=4631320832041516337&username=jigsheth%40sfdc.com&password=

2015-04-23 06:28:27.445 ERROR 37528 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: java.io.EOFException: No content to map to Object due to end of input] with root cause

java.io.EOFException: No content to map to Object due to end of input
at org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2775)
at org.codehaus.jackson.map.ObjectMapper._readMapAndClose(ObjectMapper.java:2718)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1909)
at com.force.api.Auth.oauthLoginPasswordFlow(Auth.java:31)
at com.force.api.Auth.authenticate(Auth.java:206)
at com.force.api.ForceApi.(ForceApi.java:66)
at io.pivotal.example.sfdc.controller.SFDCController.token(SFDCController.java:111)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)

Best Regards,
Jignesh Sheth | Sr. Field Engineer | Pivotal
Phone: (847)970-0298 | jigsheth@pivotal.io mailto:jigsheth@pivotal.io

Platform as a Service | Agile Development | Big Data
www.Pivotal.io http://www.pivotal.io/

On Apr 23, 2015, at 1:26 AM, Jesper Joergensen notifications@github.com wrote:

You're going to have to provide a bit more info.


Reply to this email directly or view it on GitHub #20 (comment).

@jesperfj
Copy link
Owner

I am having the same problem. Diving into this after not having touched this repo in a looong time. I can't even get a successful curl authentication to work right now. Not sure what I am doing wrong:

curl -i https://login.salesforce.com/services/oauth2/token --data 'grant_type=password&client_id=3MVG9sG9Z3Q1RlbdJV2erYnyIAAiBExOOVdE6Rtj1kk1Y._5_4owWF_45_I81zdvzuMxUn0t035CQ1J6ott_1&client_secret=<client_secret>&username=jesper%40forcerestapi.dev&password=<password><security_token>'
HTTP/1.1 400 Bad Request
Date: Thu, 23 Apr 2015 15:45:41 GMT
Set-Cookie: BrowserId=_htjNjevTtmO-WXbu1oXIg;Path=/;Domain=.salesforce.com;Expires=Mon, 22-Jun-2015 15:45:41 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Pragma: no-cache
Cache-Control: no-cache, no-store
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked

{"error_description":"authentication failure","error":"invalid_grant"}

@jigsheth57
Copy link
Author

don’t url encode the data .. (userid, password, client_id or client_secret). I see your userid is encoded. just use .. jesper@forcerestapi.dev

Best Regards,
Jignesh Sheth | Sr. Field Engineer | Pivotal
Phone: (847)970-0298 | jigsheth@pivotal.io mailto:jigsheth@pivotal.io

Platform as a Service | Agile Development | Big Data
www.Pivotal.io http://www.pivotal.io/

On Apr 23, 2015, at 10:46 AM, Jesper Joergensen notifications@github.com wrote:

I am having the same problem. Diving into this after not having touched this repo in a looong time. I can't even get a successful curl authentication to work right now. Not sure what I am doing wrong:

curl -i https://login.salesforce.com/services/oauth2/token --data 'grant_type=password&client_id=3MVG9sG9Z3Q1RlbdJV2erYnyIAAiBExOOVdE6Rtj1kk1Y._5_4owWF_45_I81zdvzuMxUn0t035CQ1J6ott_1&client_secret=7484909531894844764&username=jesper%40forcerestapi.dev&password=<security_token>'
HTTP/1.1 400 Bad Request
Date: Thu, 23 Apr 2015 15:45:41 GMT
Set-Cookie: BrowserId=_htjNjevTtmO-WXbu1oXIg;Path=/;Domain=.salesforce.com;Expires=Mon, 22-Jun-2015 15:45:41 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Pragma: no-cache
Cache-Control: no-cache, no-store
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked

{"error_description":"authentication failure","error":"invalid_grant"}

Reply to this email directly or view it on GitHub #20 (comment).

@jesperfj
Copy link
Owner

Ok. I finally got curl working. Not sure what I did wrong. Created new OAuth clients and reset security token. It works whether @ is url encoded or not btw.

@jesperfj
Copy link
Owner

I fixed some issues in 2805b42 and most tests are passing now. The code now uses "Bearer" in the authorization header. I suspect this might have been the issue, but I am not sure. I also added a missing Accept header. Let me know if you're able to test it and see if it fixes your issue.

@jesperfj
Copy link
Owner

Fix is now included in 0.0.21

@jigsheth57
Copy link
Author

Hi Jesper,

I’m still having issue. I'm still getting 400 error …

Bad response code: 400 on request:
POST https://login.salesforce.com/services/oauth2/token
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept: application/json

grant_type=password&client_id=3MVG9A2kN3Bn17hv8siDyJtftcr88aXG3TpBJIqO8QZac_dXPEoQy08vgi651aB8y6QdfgCkW0HsDIyQeH1V&client_secret=4631320832041516337&username=jigsheth%40sfdc.com&password=Test1234dDumeVuL111zfI0AGwfL1QG4

2015-04-25 19:26:23.093 ERROR 52860 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.RuntimeException: java.io.EOFException: No content to map to Object due to end of input] with root cause

java.io.EOFException: No content to map to Object due to end of input
at org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2775)

I’m basically trying to get list of Accounts and associated Contacts & Opportunities. I can access it using Wiztool.org http://wiztool.org/ REST Client, but not having luck with your force-rest-api or using Apache HTTP Client. Any help would be greatly appreciated. Thanks.

Best Regards,
Jignesh Sheth | Sr. Field Engineer | Pivotal
Phone: (847)970-0298 | jigsheth@pivotal.io mailto:jigsheth@pivotal.io

Platform as a Service | Agile Development | Big Data
www.Pivotal.io http://www.pivotal.io/

On Apr 25, 2015, at 7:12 PM, Jesper Joergensen notifications@github.com wrote:

Fix is now included in 0.0.21


Reply to this email directly or view it on GitHub #20 (comment).

@jigsheth57
Copy link
Author

Hi Jasper,

It was user error. My client id had character missing. It works and get the token. However, I’m still having issue with deserializing. Does the POJO have to exact as the SFDC Account object? I have following annotation "@JsonIgnoreProperties(ignoreUnknown = true)”, but still get error. Any Idea??

2015-04-25 19:43:24.341 ERROR 52931 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.force.api.ResourceException: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "Id" (Class io.pivotal.example.sfdc.Account), not marked as ignorable
at [Source: N/A; line: -1, column: -1](through reference chain: io.pivotal.example.sfdc.Account["Id"])] with root cause

org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "Id" (Class io.pivotal.example.sfdc.Account), not marked as ignorable
at [Source: N/A; line: -1, column: -1](through reference chain: io.pivotal.example.sfdc.Account["Id"])
at org.codehaus.jackson.map.exc.UnrecognizedPropertyException.from(UnrecognizedPropertyException.java:53)
at org.codehaus.jackson.map.deser.StdDeserializationContext.unknownFieldException(StdDeserializationContext.java:267)
at org.codehaus.jackson.map.deser.std.StdDeserializer.reportUnknownProperty(StdDeserializer.java:673)
at org.codehaus.jackson.map.deser.std.StdDeserializer.handleUnknownProperty(StdDeserializer.java:659)
at org.codehaus.jackson.map.deser.BeanDeserializer.handleUnknownProperty(BeanDeserializer.java:1365)
at org.codehaus.jackson.map.deser.BeanDeserializer._handleUnknown(BeanDeserializer.java:725)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:703)
at org.codehaus.jackson.map.deser.BeanDeserializer.deserialize(BeanDeserializer.java:580)
at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2704)
at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1999)
at com.force.api.ForceApi.queryAny(ForceApi.java:235)
at com.force.api.ForceApi.query(ForceApi.java:197)
at io.pivotal.example.sfdc.controller.SFDCController.getAccountList(SFDCController.java:42)

Best Regards,
Jignesh Sheth | Sr. Field Engineer | Pivotal
Phone: (847)970-0298 | jigsheth@pivotal.io mailto:jigsheth@pivotal.io

Platform as a Service | Agile Development | Big Data
www.Pivotal.io http://www.pivotal.io/

On Apr 25, 2015, at 7:33 PM, Jignesh Sheth jigsheth@pivotal.io wrote:

sfdc.com http://40sfdc.com/&password=Test1234dDumeVuL111zfI0AGwfL1QG4

@jesperfj
Copy link
Owner

How does your class compare to the Account class in the test suite?

@jigsheth57
Copy link
Author

Thanks for all your help. I was using wrong import class for JsonIgnoreProperties.

Thanks,
Jig

On Apr 25, 2015, at 8:59 PM, Jesper Joergensen notifications@github.com wrote:

How does your class compare to the Account https://github.com/jesperfj/force-rest-api/blob/master/src/test/java/com/force/api/Account.java class in the test suite?


Reply to this email directly or view it on GitHub #20 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants