Skip to content

Commit c4c167e

Browse files
committed
update telemetry, clean-up, and improve perf
1 parent b0b9796 commit c4c167e

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

src/internal/Confirm-ModuleAuthentication.ps1

+12-20
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ function Confirm-ModuleAuthentication {
7373
$Stopwatch.Stop()
7474
if ($MsGraphToken) {
7575
$AuthDetail = [ordered]@{
76+
ClientId = $ClientApplication.ClientId
7677
TokenType = $MsGraphToken.TokenType
7778
ExpiresOn = $MsGraphToken.ExpiresOn
7879
CorrelationId = $MsGraphToken.CorrelationId
@@ -87,16 +88,6 @@ function Confirm-ModuleAuthentication {
8788
Write-AppInsightsDependency 'GET Access Token' -Type 'Azure AD' -Data 'GET Access Token' -Duration $Stopwatch.Elapsed -Success ($null -ne $MsGraphToken) -OrderedProperties $AuthDetail
8889
}
8990
}
90-
if (!$script:ConnectState.MsGraphToken -or ($script:ConnectState.MsGraphToken.AccessToken -ne $MsGraphToken.AccessToken)) {
91-
Write-Verbose 'Connecting Modules...'
92-
#Connect-MgGraph -Environment $CloudEnvironment -TenantId $MsGraphToken.TenantId -AccessToken $MsGraphToken.AccessToken | Out-Null
93-
if ($script:MsGraphSession.Headers.ContainsKey('Authorization')) {
94-
$script:MsGraphSession.Headers['Authorization'] = $MsGraphToken.CreateAuthorizationHeader()
95-
}
96-
else {
97-
$script:MsGraphSession.Headers.Add('Authorization', $MsGraphToken.CreateAuthorizationHeader())
98-
}
99-
}
10091
}
10192
else {
10293
Write-Warning 'Using a confidential client is non-interactive and requires that the necessary scopes/permissions be added to the application or have permissions on-behalf-of a user.'
@@ -110,6 +101,7 @@ function Confirm-ModuleAuthentication {
110101
if (!$script:ConnectState.MsGraphToken -or ($script:ConnectState.MsGraphToken.AccessToken -ne $MsGraphToken.AccessToken)) {
111102
if ($MsGraphToken) {
112103
$AuthDetail = [ordered]@{
104+
ClientId = $ClientApplication.ClientId
113105
TokenType = $MsGraphToken.TokenType
114106
ExpiresOn = $MsGraphToken.ExpiresOn
115107
CorrelationId = $MsGraphToken.CorrelationId
@@ -120,20 +112,20 @@ function Confirm-ModuleAuthentication {
120112
Write-AppInsightsDependency 'GET Access Token (Confidential Client)' -Type 'Azure AD' -Data 'GET Access Token (Confidential Client)' -Duration $Stopwatch.Elapsed -Success ($null -ne $MsGraphToken) -OrderedProperties $AuthDetail
121113
}
122114
}
123-
if (!$script:ConnectState.MsGraphToken -or ($script:ConnectState.MsGraphToken.AccessToken -ne $MsGraphToken.AccessToken)) {
124-
Write-Verbose 'Connecting Modules...'
125-
#Connect-MgGraph -Environment $CloudEnvironment -TenantId $MsGraphToken.TenantId -AccessToken $MsGraphToken.AccessToken | Out-Null
126-
if ($script:MsGraphSession.Headers.ContainsKey('Authorization')) {
127-
$script:MsGraphSession.Headers['Authorization'] = $MsGraphToken.CreateAuthorizationHeader()
128-
}
129-
else {
130-
$script:MsGraphSession.Headers.Add('Authorization', $MsGraphToken.CreateAuthorizationHeader())
131-
}
115+
}
116+
if (!$script:ConnectState.MsGraphToken -or ($script:ConnectState.MsGraphToken.AccessToken -ne $MsGraphToken.AccessToken)) {
117+
Write-Verbose 'Connecting Modules...'
118+
#Connect-MgGraph -Environment $CloudEnvironment -TenantId $MsGraphToken.TenantId -AccessToken $MsGraphToken.AccessToken | Out-Null
119+
if ($script:MsGraphSession.Headers.ContainsKey('Authorization')) {
120+
$script:MsGraphSession.Headers['Authorization'] = $MsGraphToken.CreateAuthorizationHeader()
121+
}
122+
else {
123+
$script:MsGraphSession.Headers.Add('Authorization', $MsGraphToken.CreateAuthorizationHeader())
132124
}
133125
}
134126
$script:ConnectState.MsGraphToken = $MsGraphToken
135127

136128
if ($MsGraphSession) {
137-
Write-Output $script:MsGraphSession
129+
return $script:MsGraphSession
138130
}
139131
}

0 commit comments

Comments
 (0)