Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

Commit

Permalink
Only check for device registration on import
Browse files Browse the repository at this point in the history
  • Loading branch information
jazuntee committed Sep 19, 2021
1 parent c50cfc5 commit 44fae3f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
12 changes: 12 additions & 0 deletions src/MSAL.PS.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
Expand All @@ -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)
}
15 changes: 2 additions & 13 deletions src/New-MsalClientApplication.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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')) {
Expand Down

0 comments on commit 44fae3f

Please sign in to comment.