Skip to content

Commit

Permalink
update telemetry, clean-up, and improve perf
Browse files Browse the repository at this point in the history
  • Loading branch information
jazuntee committed Jan 11, 2023
1 parent b0b9796 commit c4c167e
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions src/internal/Confirm-ModuleAuthentication.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ function Confirm-ModuleAuthentication {
$Stopwatch.Stop()
if ($MsGraphToken) {
$AuthDetail = [ordered]@{
ClientId = $ClientApplication.ClientId
TokenType = $MsGraphToken.TokenType
ExpiresOn = $MsGraphToken.ExpiresOn
CorrelationId = $MsGraphToken.CorrelationId
Expand All @@ -87,16 +88,6 @@ function Confirm-ModuleAuthentication {
Write-AppInsightsDependency 'GET Access Token' -Type 'Azure AD' -Data 'GET Access Token' -Duration $Stopwatch.Elapsed -Success ($null -ne $MsGraphToken) -OrderedProperties $AuthDetail
}
}
if (!$script:ConnectState.MsGraphToken -or ($script:ConnectState.MsGraphToken.AccessToken -ne $MsGraphToken.AccessToken)) {
Write-Verbose 'Connecting Modules...'
#Connect-MgGraph -Environment $CloudEnvironment -TenantId $MsGraphToken.TenantId -AccessToken $MsGraphToken.AccessToken | Out-Null
if ($script:MsGraphSession.Headers.ContainsKey('Authorization')) {
$script:MsGraphSession.Headers['Authorization'] = $MsGraphToken.CreateAuthorizationHeader()
}
else {
$script:MsGraphSession.Headers.Add('Authorization', $MsGraphToken.CreateAuthorizationHeader())
}
}
}
else {
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.'
Expand All @@ -110,6 +101,7 @@ function Confirm-ModuleAuthentication {
if (!$script:ConnectState.MsGraphToken -or ($script:ConnectState.MsGraphToken.AccessToken -ne $MsGraphToken.AccessToken)) {
if ($MsGraphToken) {
$AuthDetail = [ordered]@{
ClientId = $ClientApplication.ClientId
TokenType = $MsGraphToken.TokenType
ExpiresOn = $MsGraphToken.ExpiresOn
CorrelationId = $MsGraphToken.CorrelationId
Expand All @@ -120,20 +112,20 @@ function Confirm-ModuleAuthentication {
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
}
}
if (!$script:ConnectState.MsGraphToken -or ($script:ConnectState.MsGraphToken.AccessToken -ne $MsGraphToken.AccessToken)) {
Write-Verbose 'Connecting Modules...'
#Connect-MgGraph -Environment $CloudEnvironment -TenantId $MsGraphToken.TenantId -AccessToken $MsGraphToken.AccessToken | Out-Null
if ($script:MsGraphSession.Headers.ContainsKey('Authorization')) {
$script:MsGraphSession.Headers['Authorization'] = $MsGraphToken.CreateAuthorizationHeader()
}
else {
$script:MsGraphSession.Headers.Add('Authorization', $MsGraphToken.CreateAuthorizationHeader())
}
}
if (!$script:ConnectState.MsGraphToken -or ($script:ConnectState.MsGraphToken.AccessToken -ne $MsGraphToken.AccessToken)) {
Write-Verbose 'Connecting Modules...'
#Connect-MgGraph -Environment $CloudEnvironment -TenantId $MsGraphToken.TenantId -AccessToken $MsGraphToken.AccessToken | Out-Null
if ($script:MsGraphSession.Headers.ContainsKey('Authorization')) {
$script:MsGraphSession.Headers['Authorization'] = $MsGraphToken.CreateAuthorizationHeader()
}
else {
$script:MsGraphSession.Headers.Add('Authorization', $MsGraphToken.CreateAuthorizationHeader())
}
}
$script:ConnectState.MsGraphToken = $MsGraphToken

if ($MsGraphSession) {
Write-Output $script:MsGraphSession
return $script:MsGraphSession
}
}

0 comments on commit c4c167e

Please sign in to comment.