-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
GetToken-MSAL.ps1
27 lines (17 loc) · 712 Bytes
/
GetToken-MSAL.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
#Requires -Modules "MSAL.PS"
cls
$currentPath = (Split-Path $MyInvocation.MyCommand.Definition -Parent)
$clientId = ""
$tenantId = "common"
$authority = "https://login.microsoftonline.com/$tenantId"
$apiResource = "https://analysis.windows.net/powerbi/api"
$scopes = @("$apiResource/.default")
$app = New-MsalClientApplication -ClientId $clientId -Authority $authority -TenantId $tenantId
$oauthResult = $app | Get-MsalToken -Scopes $scopes
$accessToken = $oauthResult.AccessToken
$headers = @{
'Content-Type'= "application/json"
'Authorization'= "Bearer $accessToken"
}
$response = Invoke-RestMethod -Uri "https://api.powerbi.com/v1.0/myorg/groups" -Headers $headers -Method Get
$response.value