8. September 2014
ADAL v2 was just released. This is a library that makes it super easy to auth against Azure AD in an application. Here’s a link to a very quick demo. http://www.cloudidentity.com/blog/2014/09/08/getting-started-with-adal-for-netquick-video-tutorial/
Well, if it can be done in WPF, surely we can do this in PowerShell. The first thing you have to do is make sure you have the Nuget command line tool installed.
Then you just run this command -
nuget install Microsoft.IdentityModel.Clients.ActiveDirectory
After that, you can find the 2 dll’s you need in the Microsoft.IdentityModel.Clients.ActiveDirectory.2.9.10826.1824\lib\net45 directory.
Now comes the fun part.
Add-Type -Path .\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll
Add-Type -Path .\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll
$tenant = "yourdomainhere.onmicrosoft.com"
$resource = "https://graph.windows.net"
$clientID = "dfbf167a-add-your-own-clientid-here"
$redirect = new-object System.Uri("http://powershell") #as long as this is unique in your tenant, all good
$AuthContext = new-object Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext("https://login.windows.net/$tenant")
$result = $AuthContext.AcquireToken($resource,$clientID,$redirect)