Skip to content

Instantly share code, notes, and snippets.

@jtourlamain
Last active February 21, 2018 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtourlamain/f456e4f1d402bc713d85 to your computer and use it in GitHub Desktop.
Save jtourlamain/f456e4f1d402bc713d85 to your computer and use it in GitHub Desktop.
GetTokenFromO365
# Load ADAL Assemblies
$adal = "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
$adalforms = "${env:ProgramFiles(x86)}\Microsoft SDKs\Azure\PowerShell\ServiceManagement\Azure\Services\Microsoft.IdentityModel.Clients.ActiveDirectory.WindowsForms.dll"
[System.Reflection.Assembly]::LoadFrom($adal)
[System.Reflection.Assembly]::LoadFrom($adalforms)
# Set Azure AD Tenant name
$adTenant = "devprotocol.onmicrosoft.com"
# Set well-known client ID for AzurePowerShell
$clientId = "45c1b239-339f-4b9a-b9fe-6e087e37f549"
# Set redirect URI for Azure PowerShell
$redirectUri = "http://myphotodemo.devprotocol.com"
# Set Resource URI to Azure Service Management API
$resourceAppIdURI = "https://devprotocol.sharepoint.com/"
# Set Authority to Azure AD Tenant
$authority = "https://login.windows.net/$adTenant"
# Create Authentication Context tied to Azure AD Tenant
$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority
# Acquire token
$authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId, $redirectUri, "Auto")
$authHeader = $authResult.CreateAuthorizationHeader()
$authHeader | Out-File jwt.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment