Skip to content

Instantly share code, notes, and snippets.

@peted70
Created June 17, 2016 10:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peted70/9700106d519bb7b749c35240136e814f to your computer and use it in GitHub Desktop.
Save peted70/9700106d519bb7b749c35240136e814f to your computer and use it in GitHub Desktop.
private async Task<string> MakeRequestAsync(string token, string path, string query = "")
{
var http = new HttpClient();
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
var ub = new UriBuilder("https://api.microsofthealth.net");
ub.Path = ApiVersion + "/" + path;
ub.Query = query;
string resStr = string.Empty;
var resp = await http.GetAsync(ub.Uri);
if (resp.StatusCode == HttpStatusCode.Unauthorized)
{
// If we are unauthorized here assume that our token may have expired and use the
// refresh token to get a new one and then try the request again..
// TODO: handle this - we can cache the refresh token in the same flow as the access token
// just haven't done it.
return "";
// Re-issue the same request (will use new auth token now)
//return await MakeRequestAsync(path, query);
}
if (resp.IsSuccessStatusCode)
{
resStr = await resp.Content.ReadAsStringAsync();
}
return resStr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment