Created
February 17, 2018 13:01
-
-
Save peted70/302a667437f782e6bbef9471ad0efd31 to your computer and use it in GitHub Desktop.
auth with the Azure translator api
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> 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