-
-
Save peted70/9700106d519bb7b749c35240136e814f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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