JamesDBartlett3 / PowerBits

A collection of useful, time-saving tools for working with Microsoft Power BI
Open Software License 3.0
48 stars 13 forks source link

Refactor: Auth with Az.Accounts #8

Open JamesDBartlett3 opened 9 months ago

JamesDBartlett3 commented 9 months ago
# Based on [Rui Romano's Set-FabricAuthToken function](https://github.com/RuiRomano/fabricps-pbip/blob/main/FabricPS-PBIP.psm1#L23)
$bearerToken = $null
$azAccountsModule = (Get-InstalledModule -Name "Az.Accounts" -ErrorAction SilentlyContinue | Out-Null)
if($azAccountsModule) {
  $azSession = (Get-AzAccessToken -ResourceUrl "https://api.fabric.microsoft.com")
  $bearerToken = $azSession.Token
} elseif($servicePrincipalId) {
  # Auth with Service Principal
} else {
  # Interactive OAuth
}