Last active
February 21, 2018 21:20
-
-
Save jtourlamain/f456e4f1d402bc713d85 to your computer and use it in GitHub Desktop.
GetTokenFromO365
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
# 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