File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Modules/CIPPCore/Public/Authentication Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1+ function Get-CIPPAzIdentityToken {
2+ <#
3+ . SYNOPSIS
4+ Get the Azure Identity token for Managed Identity
5+ . DESCRIPTION
6+ This function retrieves the Azure Identity token using the Managed Identity endpoint
7+ . EXAMPLE
8+ Get-CIPPAzIdentityToken
9+ #>
10+ [CmdletBinding ()]
11+ param ()
12+
13+ $Endpoint = $env: IDENTITY_ENDPOINT
14+ $Secret = $env: IDENTITY_HEADER
15+ $ResourceURI = ' https://management.azure.com/'
16+
17+ if (-not $Endpoint -or -not $Secret ) {
18+ throw ' Managed Identity environment variables (IDENTITY_ENDPOINT/IDENTITY_HEADER) not found. Is Managed Identity enabled on the Function App?'
19+ }
20+
21+ $TokenUri = " $ ( $Endpoint ) ?resource=$ ( $ResourceURI ) &api-version=2019-08-01"
22+ $Headers = @ {
23+ ' X-IDENTITY-HEADER' = $Secret
24+ }
25+
26+ $TokenResponse = Invoke-RestMethod - Method Get - Headers $Headers - Uri $TokenUri
27+ return $TokenResponse.access_token
28+ }
You can’t perform that action at this time.
0 commit comments