Guest User

Untitled

a guest
Jan 16th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. using (HttpClient client = new HttpClient())
  2. {
  3. var tokenEndpoint = @"https://login.windows.net/<tenant-id>/oauth2/token";
  4. var accept = "application/json";
  5.  
  6. client.DefaultRequestHeaders.Add("Accept", accept);
  7. string postBody = @"resource=https%3A%2F%2Fgraph.microsoft.com%2F
  8. &client_id=<client id>
  9. &grant_type=password
  10. &username=xxx@xxx.onmicrosoft.com
  11. &password=<password>
  12. &scope=openid";
  13.  
  14. using (var response = await client.PostAsync(tokenEndpoint, new StringContent(postBody, Encoding.UTF8, "application/x-www-form-urlencoded")))
  15. {
  16. if (response.IsSuccessStatusCode)
  17. {
  18. var jsonresult = JObject.Parse(await response.Content.ReadAsStringAsync());
  19. token = (string)jsonresult["access_token"];
  20. }
  21. }
  22. }
Add Comment
Please, Sign In to add comment