3

I have been given the following directions to pull a JSON list of data from a webservice.

GET /criminal_api/1.0/service/requests
HTTP Header: Authorization: Bearer 6EDC52118E164AE659EA2C772F3B9804

The following values in the header Bearer 6EDC52118E164AE659EA2C772F3B9804 are dynamic and will be set using the following content variable

 <cfset content = deserializeJSON(    {
       "access_token": "84F224956C6AB5287038C0209EBAC5AB",
       "token_type": "bearer",
       "refresh_token": "E48BB9C164FE2125D3BE2CD602E4A692",
       "expires_in": 7199,
       "scope": "read write"
    })>

So I am tried the following:

<cfhttp method="get" url="https://test.mywebsite.com/criminal_api//1.0/service/requests" result="orderList">
    <cfhttpparam type="HEADER" name="Authorization" value="#content.token_type# #content.access_token#">
</cfhttp>

But when I check the filecontent instead of getting a JSON list I get: Connection Failure

I have a feeling it is how I am setting the header value I am just not sure what I am doing wrong.

EDIT: When I added a ":" in between the token type and access token I got a new error:

struct
error   -1
error_description   Invalid access token: : 82D773278FB69CFBCFB4CB8CEF8AC03D

Obviously it thinks the ":" is part of the access token so it is connecting I am just not sure how to have both values in the value= field so it is read correctly.

Denoteone
  • 4,043
  • 21
  • 96
  • 150
  • 1
    Connection failure typically means you are not making a connection at all. If it where something to do with a required header or content issue I would expect a different message. Check to see if: A) you your cert is installed in the keystore - that Java can handshake with the site in question using SSL/TLS B) That the server is correctly resolving the IP address. – Mark A Kruger Apr 28 '16 at 18:16
  • Mark the previous cfhttp get to the same address to pull the access_token JSON data was able to connect with no issues. Only when I hit the same url but a different method "requests" and I am supposed to pass the info in the previous call in the header do I get the no connection failure. Sorry I am not sure if I understand about the JAVA since I am doing this in coldfusion. please explain and I would be happy to follow up on that. Thanks for your response. – Denoteone Apr 28 '16 at 18:53
  • I added an edit to my question which may help narrow down what is going on. – Denoteone Apr 28 '16 at 19:09
  • 2
    How particular is the webservice? The directions show a capital 'B' for the token type `Bearer` but your example is passing a lower case 'b' for the token type `bearer`. – Miguel-F Apr 28 '16 at 19:14
  • I am spitting it back to its self. The first call to the webservice gets the bearer term in that case I just save it to a variable. So i kept it that way. Do you think the deserializeJSON would change the case? – Denoteone Apr 28 '16 at 19:19
  • No I do not think deserializeJSON would change the case. I am just going by the information that you provided. One is upper and the other lower. `HTTP Header: Authorization: Bearer 6EDC52118E164AE659EA2C772F3B9804` versus `"token_type": "bearer",` – Miguel-F Apr 28 '16 at 19:27
  • RE my first comment - if you can make _any_ successful TLS connection to the URL then you are ok with the cert issue and can disregard my suggestion. – Mark A Kruger Apr 29 '16 at 14:38

1 Answers1

1

Have you tried:

<cfhttp method="get" url="https://test.mywebsite.com/criminal_api//1.0/service/requests" result="orderList" username="#content.token_type#" password="#content.access_token#">

This will produce an authorization header of "Basic Bearer:6EDC52118E164AE659EA2C772F3B9804"

Manually, that would be:

<cfhttp method="get" url="https://test.mywebsite.com/criminal_api//1.0/service/requests" result="orderList">
<cfhttpparam type="HEADER" name="Authorization" value="Basic #content.token_type#:#content.access_token#">

There's also the question of what that hex value contains. Take a look at Getting Basic Authentication to work with ColdFusion - maybe this more closely reflects your situation.

Community
  • 1
  • 1
GumbyG
  • 488
  • 4
  • 8