intercom-java icon indicating copy to clipboard operation
intercom-java copied to clipboard

HttpClient tries to assemble incorrect header, can't connect

Open ddrennan-dch opened this issue 5 years ago • 0 comments

Seems to be the same as #238 .

Basically, the HttpClient tries to construct the Authorization header as follows:

  1. Add colon to the end of the Intercom token
  2. Encode that in base64
  3. Add it to a Basic header

So it ends up being

Authorization:Basic [newly encoded token value]

I believe Basic is used when you want to send a username/password, but since we just have a token, it should be Bearer. Also the colon is not needed, the token value should be used as-is.

Version info

  • intercom-java version: 2.7.1
  • Java version: 1.7, 1.8

Expected behavior

API connects to Intercom and pulls data.

Actual behavior

HttpClient fails to make connection due to bad header.

Steps to reproduce

Intercom.setToken("token");
CompanyCollection companies = Company.list();

Logs

SEVERE: Servlet.service() for servlet [datacenterhawk] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: Illegal character(s) in message header value: Basic W0JANzAwOTFhYTI6
] with root cause
java.lang.IllegalArgumentException: Illegal character(s) in message header value: Basic W0JANzAwOTFhYTI6

	at sun.net.www.protocol.http.HttpURLConnection.checkMessageHeader(HttpURLConnection.java:541)
	at sun.net.www.protocol.http.HttpURLConnection.isExternalMessageHeaderAllowed(HttpURLConnection.java:492)
	at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(HttpURLConnection.java:3075)
	at sun.net.www.protocol.https.HttpsURLConnectionImpl.setRequestProperty(HttpsURLConnectionImpl.java:325)
	at io.intercom.api.HttpClient.applyHeaders(HttpClient.java:224)
	at io.intercom.api.HttpClient.initializeConnection(HttpClient.java:145)
	at io.intercom.api.HttpClient.executeHttpMethod(HttpClient.java:106)
	at io.intercom.api.HttpClient.get(HttpClient.java:86)
	at io.intercom.api.HttpClient.get(HttpClient.java:82)
	at io.intercom.api.DataResource.list(DataResource.java:66)
	at io.intercom.api.Company.list(Company.java:59)

ddrennan-dch avatar Feb 10 '20 22:02 ddrennan-dch