Getting "UNAUTHORIZED" response when api calls to api/users/current request

2,658 views
Skip to first unread message

rajbha...@gmail.com

unread,
Apr 26, 2016, 10:11:27 AM4/26/16
to drchrono Medical Healthcare API SDK
I am using Dr. Chrono api to facilitate login using external provider.

I have made several api call to get current users info, but each time I get "UNAUTHORIZED" response.

var userRequest = new HttpRequestMessage(HttpMethod.Get, "https://drchrono.com/api/users/current");
userRequest.Headers.Add("Authorization", "Bearer " + access_token);
var userResponse = await _httpClient.SendAsync(userRequest, Request.CallCancelled);

and I am always getting response like below:-

{StatusCode: 401, ReasonPhrase: 'UNAUTHORIZED', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Transfer-Encoding: chunked
Connection: keep-alive
X-XSS-Protection: 1
X-Content-Options: nosniff
Strict-Transport-Security: max-age=31536000 ; includeSubDomains ; preload
Vary: User-Agent
Vary: Authorization
Vary: Cookie
X-Frame-Options: sameorigin
CF-RAY: 2999cd05ac4d2dcd-BOM
Date: Tue, 26 Apr 2016 11:47:36 GMT
Server: cloudflare-nginx
WWW-Authenticate: Bearer
Content-Type: text/html; charset=utf-8
}}


However, using same access_token I get all patients list, so its not that access_token is not authorized.

like below request

var userRequest = new HttpRequestMessage(HttpMethod.Get, "https://drchrono.com/api/patients");
userRequest.Headers.Add("Authorization", "Bearer " + access_token);
var userResponse = await _httpClient.SendAsync(userRequest, Request.CallCancelled);

Please help what things are missing?

alle...@drchrono.com

unread,
May 5, 2016, 6:36:47 PM5/5/16
to drchrono Medical Healthcare API SDK
I suspect you are not handling the redirect properly. From the documentation:

> Some endpoints may return a 302 redirect response. Most libraries handle this incorrectly by resending the response with different headers or a different HTTP method; you need to resend the original request with the right HTTP method and headers to the new Location specified by the 302 response.

https://alifelesatra.drchrono.com/api-docs/v2015_08/documentation

Raj Bhagat

unread,
May 6, 2016, 9:01:56 AM5/6/16
to drchrono Medical Healthcare API SDK, alle...@drchrono.com
Thank you for helping in this issue,

 It gets fixed by resending request to new Location specified by the 302 response.
Reply all
Reply to author
Forward
0 new messages