-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGet-AutRefreshToken.ps1
More file actions
39 lines (32 loc) · 1.08 KB
/
Get-AutRefreshToken.ps1
File metadata and controls
39 lines (32 loc) · 1.08 KB
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
29
30
31
32
33
34
35
36
37
38
39
#
# Get-AutRefreshToken.ps1
#
Function Get-AutRefreshToken {
[cmdletbinding()]
Param($appid,
$appSecret,
$tenantId,
[Validateset("outlook.office.com/.default",
"manage.office.com",
"graph.microsoft.com",
"management.core.windows.net",
"vault.azure.net")]$api = "graph.microsoft.com"
)
$Authority = "https://login.microsoftonline.com/$tenantId"
$tokenEndpointUri = "$authority/oauth2/token"
$Contentbody = @{"grant_type" = "client_credentials";
"Client_Id" = $AppId;
"Client_Secret" = $AppSecret;
"Resource" = "https://$api"
}
# Try to collect an access token using your app.
try {
$response = Invoke-RestMethod -Uri $tokenEndpointUri -Body $Contentbody -Method Post -UseBasicParsing -ErrorAction Stop
return $response.access_token
}
Catch {
Write-Output "Unable to request access token."
Write-Output $error[0].exception
}
}
Write-Output "Performed on host: $($env:ComputerName)"