Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using (HttpClient client = new HttpClient())
- {
- var tokenEndpoint = @"https://login.windows.net/<tenant-id>/oauth2/token";
- var accept = "application/json";
- client.DefaultRequestHeaders.Add("Accept", accept);
- string postBody = @"resource=https%3A%2F%2Fgraph.microsoft.com%2F
- &client_id=<client id>
- &grant_type=password
- &username=xxx@xxx.onmicrosoft.com
- &password=<password>
- &scope=openid";
- using (var response = await client.PostAsync(tokenEndpoint, new StringContent(postBody, Encoding.UTF8, "application/x-www-form-urlencoded")))
- {
- if (response.IsSuccessStatusCode)
- {
- var jsonresult = JObject.Parse(await response.Content.ReadAsStringAsync());
- token = (string)jsonresult["access_token"];
- }
- }
- }
Add Comment
Please, Sign In to add comment