Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save joerodgers/2913b83847414332657f0ccdf093a71c to your computer and use it in GitHub Desktop.

Select an option

Save joerodgers/2913b83847414332657f0ccdf093a71c to your computer and use it in GitHub Desktop.
Uses Microsoft.Identity.Client assembly loaded via the "Microsoft.PowerApps.Administration.PowerShell" module to generate an Entra access token
#requires -modules "Microsoft.PowerApps.Administration.PowerShell"
$clientId = $env:CDX_CLIENTID
$tenantId = $env:CDX_TENANTID
[string[]]$scopes = "https://api.powerplatform.com/.default", "openid", "profile offline_access"
$pca = [Microsoft.Identity.Client.PublicClientApplicationBuilder]::Create($clientId).WithAuthority( "https://login.microsoftonline.com/$tenantId", $true).
WithRedirectUri( "http://localhost" ).
Build()
$task = $pca.AcquireTokenInteractive($scopes).WithUseEmbeddedWebView($false).ExecuteAsync()
while (-not $task.AsyncWaitHandle.WaitOne(200)) { }
$task.GetAwaiter().GetResult()
$authResult.AccessToken | Set-Clipboard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment