Last active
October 31, 2018 05:42
-
-
Save TheWorstProgrammerEver/d721fc8d414bec3e5e8c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var ClientSecret = "kSRsdf7rU323rf2ff2gfdssfdAnKI1mcOf98djfidIGx38="; // A key you add for your AAD app. | |
var ClientId = "17dfab36-1c33-4ffe-9ddd-533ddddfs378"; // The unique identifier for your AAD app.. | |
var userObjectId = "12345667-1234-1234-1234-123412341234"; // LET'S SAY YOU WANNA GET A USER'S GROUPS... You'll need their ObjectId for querying later. | |
var authority = "https://login.microsoftonline.com/{tenant guid}/oauth2/authorize?api-version=1.0"; // This is the "OAuth Authorize" Endpoint for your AAD app. | |
var authContext = new AuthenticationContext(authority); | |
// Graph endpoint comes from Azure Portal "Graph Connection Endpoint" | |
var client = new ActiveDirectoryClient(new Uri("https://graph.windows.net/{tenant guid}"), () => | |
{ | |
var credential = new ClientCredential(ClientId, ClientSecret); | |
var result = authContext | |
.AcquireToken( | |
"https://graph.windows.net", // NFI about this; just do it. | |
credential) | |
.AccessToken; | |
return Task.FromResult(result); | |
}); | |
var user = await client.Users.GetByObjectId(userObjectId).ExecuteAsync(); | |
var allUsers = await client.Users.ExecuteAsync(); | |
allUsers.Dump(); | |
var allGroups = await client.Groups.ExecuteAsync(); | |
allGroups.Dump(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment