Guest User

Untitled

a guest
Jun 25th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. var values = new Dictionary<string, string>
  2. {
  3. { "client_id", ClientId },
  4. { "scope", "openid offline_access https://graph.microsoft.com/.default" },
  5. { "client_secret", clientSecret },
  6. { "grant_type", "client_credentials" }
  7. };
  8.  
  9. var content = new FormUrlEncodedContent(values);
  10.  
  11. var response = await client.PostAsync($"https://login.microsoftonline.com/{**tenantID**}/oauth2/v2.0/token", content);
  12.  
  13. string token = await response.Content.ReadAsStringAsync();
  14.  
  15. JObject accessToken = JObject.Parse(token);
  16. string access = (string)accessToken["access_token"];
  17. return access;
  18.  
  19. var url = $"https://login.microsoftonline.com/{tenantDomain}/adminconsent?"
  20. + $"client_id={ClientId}"
  21. + "&state=12345"
  22. + "&redirect_uri=http://localhost";
  23.  
  24. var verifyButtonClick = function () {
  25. var url = $"https://login.microsoftonline.com/{tenantDomain}/adminconsent?"
  26. + "client_id=" + $("#clientID").val()
  27. + "&state=12345"
  28. + "&redirect_uri="+ window.location.href.split("?")[0];
  29. window.open(url);
  30. }
  31.  
  32. HttpClient client = new HttpClient();
  33. client.BaseAddress = new Uri(url);
  34. client.DefaultRequestHeaders.Accept.Add(new
  35. MediaTypeWithQualityHeaderValue("application/json"));
  36. HttpResponseMessage response = client.GetAsync(url).Result;
Add Comment
Please, Sign In to add comment