diff --git a/src/MSAL.PS.psm1 b/src/MSAL.PS.psm1 index 9e2eb3c..0d1946f 100644 --- a/src/MSAL.PS.psm1 +++ b/src/MSAL.PS.psm1 @@ -25,6 +25,15 @@ $script:ModuleFeatureSupport = [ordered]@{ AuthBrokerSupport = [System.Environment]::OSVersion.Platform -eq 'Win32NT' -and $PSVersionTable.PSVersion -lt [version]'7.0' } +## Get Device Registration Status +[hashtable] $Dsreg = @{} +#if ([System.Environment]::OSVersion.Platform -eq 'Win32NT' -and [System.Environment]::OSVersion.Version -ge '10.0') { + try { + Dsregcmd /status | foreach { if ($_ -match '\s*(.+) : (.+)') { $Dsreg.Add($Matches[1], $Matches[2]) } } + } + catch {} +#} + ## PowerShell Desktop 5.1 does not dot-source ScriptsToProcess when a specific version is specified on import. This is a bug. # if ($PSEdition -eq 'Desktop') { # $ModuleManifest = Import-PowershellDataFile (Join-Path $PSScriptRoot $MyInvocation.MyCommand.Name.Replace('.psm1','.psd1')) @@ -41,3 +50,6 @@ $script:ModuleFeatureSupport = [ordered]@{ ## Global Variables [System.Collections.Generic.List[Microsoft.Identity.Client.IPublicClientApplication]] $PublicClientApplications = New-Object 'System.Collections.Generic.List[Microsoft.Identity.Client.IPublicClientApplication]' [System.Collections.Generic.List[Microsoft.Identity.Client.IConfidentialClientApplication]] $ConfidentialClientApplications = New-Object 'System.Collections.Generic.List[Microsoft.Identity.Client.IConfidentialClientApplication]' +$script:ModuleState = @{ + UseWebView2 = $script:ModuleFeatureSupport.WebView2Support -and ($Dsreg['AzureAdPrt'] -eq 'NO' -or !$script:ModuleFeatureSupport.WebView1Support) +} diff --git a/src/New-MsalClientApplication.ps1 b/src/New-MsalClientApplication.ps1 index 601c3a0..db3ebb6 100644 --- a/src/New-MsalClientApplication.ps1 +++ b/src/New-MsalClientApplication.ps1 @@ -92,22 +92,11 @@ function New-MsalClientApplication { else { $ClientApplicationBuilder = [Microsoft.Identity.Client.PublicClientApplicationBuilder]::Create($ClientId) } - - ## Get Device Registration Status - [hashtable] $Dsreg = @{} - #if ([System.Environment]::OSVersion.Platform -eq 'Win32NT' -and [System.Environment]::OSVersion.Version -ge '10.0') { - try { - Dsregcmd /status | foreach { if ($_ -match '\s*(.+) : (.+)') { $Dsreg.Add($Matches[1], $Matches[2]) } } - } - catch {} - #} - [bool] $UseWebView2 = $script:ModuleFeatureSupport.WebView2Support -and ($Dsreg['AzureAdPrt'] -eq 'NO' -or !$script:ModuleFeatureSupport.WebView1Support) - if ($PSBoundParameters.ContainsKey('EnableExperimentalFeatures')) { [void] $ClientApplicationBuilder.WithExperimentalFeatures($EnableExperimentalFeatures) } # Must be called before other experimental features - if ($UseWebView2) { [void] [Microsoft.Identity.Client.Desktop.DesktopExtensions]::WithDesktopFeatures($ClientApplicationBuilder) } + if ($script:ModuleState.UseWebView2) { [void] [Microsoft.Identity.Client.Desktop.DesktopExtensions]::WithDesktopFeatures($ClientApplicationBuilder) } if ($RedirectUri) { [void] $ClientApplicationBuilder.WithRedirectUri($RedirectUri.AbsoluteUri) } elseif (!$PublicClientOptions -or !$PublicClientOptions.RedirectUri) { - if ($UseWebView2) { [void] $ClientApplicationBuilder.WithRedirectUri('https://login.microsoftonline.com/common/oauth2/nativeclient') } + if ($script:ModuleState.UseWebView2) { [void] $ClientApplicationBuilder.WithRedirectUri('https://login.microsoftonline.com/common/oauth2/nativeclient') } else { [void] $ClientApplicationBuilder.WithDefaultRedirectUri() } } if ($PSBoundParameters.ContainsKey('AuthenticationBroker')) {