Advertisement
Guest User

Untitled

a guest
Aug 9th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. HttpClient client = new HttpClient();
  2. var tokenEndpoint = "https://login.microsoftonline.com/testdir.onmicrosoft.com/oauth2/token";
  3. var body = "resource=www.graph.microsoft.com&client_id=" + App.ClientId + "&grant_type=password&username=" + UsernameEntry.Text + "&password=" + PasswordEntry.Text + "";
  4. var stringContent = new StringContent(body, Encoding.UTF8, "application/x-www-form-urlencoded");
  5. var result = await client.PostAsync(tokenEndpoint, stringContent).ContinueWith<string>(response => response.Result.Content.ReadAsStringAsync().Result);
  6. var jobject = JObject.Parse(result);
  7. App.AccessToken = jobject["access_token"].Value<string>();
  8.  
  9. tokenEndpoint = "https://login.microsoftonline.com/testdir.onmicrosoft.com/oauth2/authorize";
  10. body = "client_id=xxxx&response_type=code&redirect_uri=https://testapi.azurewebsites.net/";
  11. result = await client.PostAsync(tokenEndpoint, stringContent).ContinueWith<string>(response => response.Result.Content.ReadAsStringAsync().Result);
  12. jobject = JObject.Parse(result);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement