private IEnumerator GetAccessToken(Action <StringWrapper> result) { //Dictionary<string, string> content = new Dictionary<string, string>(); //Fill key and value //content.Add("postman-token", "994d47cb-ec45-71f0-1455-503bf5a8e0b1"); WWWForm form = new WWWForm(); UnityWebRequest www = UnityWebRequest.Post(auth_url, form); www.SetRequestHeader("nep-application-key", "8a82859f5ef21870015ef2fa5e5f0000"); www.SetRequestHeader("authorization", "Basic L29yZy0xL2FkbWluOkNoYW5nM20zISEtYWRtaW4tb3JnLTE="); //Send request yield return(www.Send()); if (!www.isNetworkError) { string resultContent = www.downloadHandler.text; Debug.Log("getting result from token query " + resultContent); TokenClassName json = JsonUtility.FromJson <TokenClassName>(resultContent); //Return result result(new StringWrapper(json.token)); acces_token.token = json.token; } else { //Return null result(new StringWrapper()); } }
public static IEnumerator getCredentials() { if (!isTokenExpired()) { yield return(null); } string url = "https://api.athenahealth.com/oauthpreview/token"; Dictionary <string, string> content = new Dictionary <string, string> (); //Fill key and value content.Add("grant_type", "client_credentials"); content.Add("client_id", clientID); content.Add("client_secret", secret); UnityWebRequest www = UnityWebRequest.Post(url, content); yield return(www.Send()); if (www.responseCode == 200) { string resultContent = www.downloadHandler.text; Debug.Log(resultContent); TokenClassName json = JsonUtility.FromJson <TokenClassName>(resultContent); //Return result token = json.access_token; } else { Debug.Log("Network Error" + www.responseCode); } }