Skip to content

Instantly share code, notes, and snippets.

@peted70
Created February 17, 2018 13:01
Show Gist options
  • Save peted70/302a667437f782e6bbef9471ad0efd31 to your computer and use it in GitHub Desktop.
Save peted70/302a667437f782e6bbef9471ad0efd31 to your computer and use it in GitHub Desktop.
auth with the Azure translator api
private async Task<string> GetTokenAsync()
{
string key = "--- YOUR API KEY HERE ---";// Environment.GetEnvironmentVariable("SKYPE_KEY");
if (string.IsNullOrEmpty(key))
{
Debug.Log("Please set an environment variable named 'SKYPE_KEY' to your Skype api key");
return string.Empty;
}
// First retrieve a time-restricted key to use to access the API (will need to write code
// to refresh this later).
_http = new HttpClient();
_http.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", key);
Debug.Log(key);
var url = string.Format("https://api.cognitive.microsoft.com/sts/v1.0/issueToken");
Debug.Log(url);
var resp = await _http.PostAsync(url, null);
resp.EnsureSuccessStatusCode();
var token = await resp.Content.ReadAsStringAsync();
return token;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment