I am trying to do some very quick tests on Azure Active Directory, and I need a tool which will allow me to quickly authenticate to AAD, and make calls to the AAD Graph API.
I have registered a Native Client application in my directory already, and I have set it up to have the appropriate permissions to call the AAD Graph API.
I want to take a look at my AAD Token, and the output from the Graph API after my call. How can I use PowerShell to quickly accomplish this?
PowerShell allows you to load .NET assemblies right into your command line. This means that you are able to load ADAL (Azure Active Directory Authentication Libraries) and use it to really simplify the authentication experience. Once you have acquired a token from ADAL, then you can simply use the
Invoke-RestMethod
cmdlet to make calls to the AAD Graph API.First you need to download and save the .NET dlls for ADAL. The download link can be found on Nuget.
Note: We specifically use ADAL v2 here.
Extract the contents from
\lib\net45\
and copy them into your working directory. I put the files in their own "ADAL" folder, to keep it separate.Then you should be able to create a new PowerShell script with the following:
Note: You will need to update the App ID, Tenant ID, and Reply URL in this script. I have also pre-configured the AAD Graph API call to return the users in my tenant, but you can change this REST call to whatever you want.
After you successfully run the script, you should get 2 new files in your working directory: A text file that contains your encoded JSON access token, which can be base64 decoded on sites like this, and a JSON file with the response from the AAD Graph API.
Let me know if this helps!