@@ -32,6 +32,11 @@ Client secret string associated with the service principal.
3232Switch indicating that the command should acquire a token using the
3333Azure Managed Identity assigned to the current VM / App Service / container.
3434
35+ . PARAMETER ManagementEndpoint
36+ Endpoint used for management. This is used for the Audience claim when authenticating to Azure.
37+ For global Azure, this should be left as the default of 'https://management.azure.com'.
38+ For Azure China, use 'https://management.chinacloudapi.cn' and for US Government Cloud use 'https://management.usgovcloudapi.net'.
39+
3540. EXAMPLE
3641# 1. Interactive sign-in (prompts user)
3742Connect-AzResourceGraph
@@ -82,13 +87,20 @@ function Connect-AzResourceGraph {
8287 [string ]$ClientSecret ,
8388
8489 [Parameter (Mandatory , ParameterSetName = ' ManagedIdentity' )]
85- [switch ]$ManagedIdentity
90+ [switch ]$ManagedIdentity ,
91+
92+ [Parameter (ParameterSetName = ' ManagedIdentity' )]
93+ [Parameter (ParameterSetName = ' Interactive' )]
94+ [Parameter (ParameterSetName = ' Certificate' )]
95+ [Parameter (ParameterSetName = ' ClientSecret' )]
96+ $ManagementEndpoint = ' https://management.azure.com'
8697 )
8798
8899 # Set up module-scoped variables for getting tokens
89100 $script :TokenSplat = @ {}
90101 $script :CertificatePath = $null
91102
103+ $script :TokenSplat [' Resource' ] = $ManagementEndpoint
92104 $script :TokenSplat [' ClientId' ] = $ClientId
93105 if ($PSBoundParameters.ContainsKey (' Tenant' )) {
94106 $script :TokenSplat [' TenantId' ] = $Tenant
@@ -109,6 +121,7 @@ function Connect-AzResourceGraph {
109121 }
110122 if ($PSCmdlet.ParameterSetName -eq ' Interactive' ) {
111123 $script :TokenSplat [' Interactive' ] = $true
124+ $script :TokenSplat [' TokenCache' ] = ' AzResourceGraph'
112125 }
113126 if ($ManagedIdentity.IsPresent ) {
114127 $script :TokenSplat [' ManagedIdentity' ] = $true
@@ -117,4 +130,7 @@ function Connect-AzResourceGraph {
117130 $script :Token = Get-AzToken @script :TokenSplat
118131 # Save the source of the token to module scope for AssertAzureConnection to know how to refresh it
119132 $script :TokenSource = ' Module'
133+ if ($script :TokenSplat [' Interactive' ] -eq $true ) {
134+ $script :TokenSplat [' UserName' ] = $script :Token.Identity
135+ }
120136}
0 commit comments