forked from edemilliere/Misc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNew-GraphToken.ps1
28 lines (25 loc) · 953 Bytes
/
New-GraphToken.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Function New-GraphToken {
#Requires -Module AzureRM
[CmdletBinding()]
Param(
$TenantName = 'ItForDummies.net'
)
try{
Import-Module AzureRM -ErrorAction Stop
}
catch{
Write-Error 'Can''t load AzureRM module.'
break
}
$clientId = "1950a258-227b-4e31-a9cf-717495945fc2" #PowerShell ClientID
$redirectUri = "urn:ietf:wg:oauth:2.0:oob"
$resourceAppIdURI = "https://graph.windows.net"
$authority = "https://login.windows.net/$TenantName"
$authContext = New-Object "Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext" -ArgumentList $authority
#$authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId,$redirectUri, "Auto")
$authResult = $authContext.AcquireToken($resourceAppIdURI, $clientId,$redirectUri, "Always")
@{
'Content-Type'='application\json'
'Authorization'=$authResult.CreateAuthorizationHeader()
}
}