This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Graph; | |
static async Task getUsersUsingGraphServiceClient() | |
{ | |
var graphServiceClient = new GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) => | |
{ | |
requestMessage | |
.Headers | |
.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken); | |
return Task.FromResult(0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.IdentityModel.Clients.ActiveDirectory; | |
static async Task getAccessToken() | |
{ | |
int retryCount = 0; | |
bool retry = false; | |
authContext = new AuthenticationContext(authority + tenantID); | |
do | |
{ | |
retry = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Main(string[] args) | |
{ | |
getAccessToken().Wait(); | |
// GetMembers utilizes HTTP Client, will print JSON Prettified in method | |
getMembers().Wait(); | |
Console.WriteLine("\n Press Enter to exit the program \n"); | |
Console.ReadLine(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IdentityModel.Tokens.Jwt; | |
static async Task prettyJWTPrint(String myToken) | |
{ | |
//Assume the input is in a control called txtJwtIn, | |
//and the output will be placed in a control called txtJwtOut | |
var jwtHandler = new JwtSecurityTokenHandler(); | |
var jwtInput = myToken; | |
String prettyPrint = ""; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.IdentityModel.Clients.ActiveDirectory; | |
using System.Net.Http; | |
using System.Net.Http.Headers; | |
static async Task getMembers() | |
{ | |
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken); | |
Console.WriteLine("\n \n Retrieving users {0}", DateTime.Now.ToString()); | |
HttpResponseMessage response = await httpClient.GetAsync(resourceUri + "/v1.0/users?$top=5"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json; | |
public static string JsonPrettify(string json) | |
{ | |
using (var stringReader = new StringReader(json)) | |
using (var stringWriter = new StringWriter()) | |
{ | |
var jsonReader = new JsonTextReader(stringReader); | |
var jsonWriter = new JsonTextWriter(stringWriter) { Formatting = Formatting.Indented }; | |
jsonWriter.WriteToken(jsonReader); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static string resourceUri = "https://graph.microsoft.com"; //Insert your resource here, I will keep this as the MSFT Graph resource | |
private static string clientId = "<your-client-id>"; // Insert your Client ID here | |
private static string redirectUri = "<your-redirect-uri>"; // Insert your redirect URI here (Reply URL of AAD Application Registration) | |
private static string authority = "https://login.microsoftonline.com/"; | |
private static string tenantID = "<your-tenant-id>"; // Insert Your Tenant ID here | |
private static AuthenticationContext authContext = null; | |
private static AuthenticationResult result = null; | |
private static HttpClient httpClient = new HttpClient(); |
NewerOlder