AzureAD / MSAL.PS

MIT License
159 stars 29 forks source link

New-MsalClientApplication : Cannot convert argument "builder" #63

Closed robinmalik closed 1 year ago

robinmalik commented 1 year ago

Hi,

I was working all morning with the following code executing successfully:

$connectionDetails = @{
    'TenantId'    = $TenantId
    'ClientId'    = $ClientId
    'Interactive' = $true
    'Scopes'      = 'openid'
    'ErrorAction' = 'Stop'
}

Write-Output "Clearing MSAL token cache"
Clear-MsalTokenCache

Write-Output "Attempting to get token"
try
{
    $token = Get-MsalToken @connectionDetails
        $token.ClaimsPrincipal.Claims | Select-Object type, value
}
catch
{
    throw $_
}

And for some reason, I'm now getting the following error:

New-MsalClientApplication : Cannot convert argument "builder", with value:
"Microsoft.Identity.Client.PublicClientApplicationBuilder", for "WithDesktopFeatures" to type
"Microsoft.Identity.Client.PublicClientApplicationBuilder": "Cannot convert the
"Microsoft.Identity.Client.PublicClientApplicationBuilder" value of type
"Microsoft.Identity.Client.PublicClientApplicationBuilder" to type
"Microsoft.Identity.Client.PublicClientApplicationBuilder"."
At C:\Program Files\WindowsPowerShell\Modules\MSAL.PS\4.37.0.0\Select-MsalClientApplication.ps1:56 char:29
+ ... plication = New-MsalClientApplication -ErrorAction Stop @paramNewMsal ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-MsalClientApplication], MethodException
    + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument,New-MsalClientApplication

This happens with both PS 5.1 and 7.3.3 using version 4.37.0.0 of MSAL.PS.

PSVersionTable:


Name                           Value                                                                                   
----                           -----                                                                                   
PSVersion                      5.1.22621.1037                                                                          
PSEdition                      Desktop                                                                                 
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                 
BuildVersion                   10.0.22621.1037                                                                         
CLRVersion                     4.0.30319.42000                                                                         
WSManStackVersion              3.0                                                                                     
PSRemotingProtocolVersion      2.3                                                                                     
SerializationVersion           1.1.0.1      

Name                           Value
----                           -----
PSVersion                      7.3.3
PSEdition                      Core
GitCommitId                    7.3.3
OS                             Microsoft Windows 10.0.22624
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0                                                                          

I've tried rebooting. Anything else I can look at?

Thank you :)

robinmalik commented 1 year ago

Attempting the following and letting all the errors return to the screen: Get-MsalToken -ClientId $ClientId -TenantId $TenantId -Interactive -Scopes 'openid' -Prompt ForceLogin gives:

New-MsalClientApplication : Cannot convert argument "builder", with value:
"Microsoft.Identity.Client.PublicClientApplicationBuilder", for "WithDesktopFeatures" to type
"Microsoft.Identity.Client.PublicClientApplicationBuilder": "Cannot convert the
"Microsoft.Identity.Client.PublicClientApplicationBuilder" value of type
"Microsoft.Identity.Client.PublicClientApplicationBuilder" to type
"Microsoft.Identity.Client.PublicClientApplicationBuilder"."
At C:\Program Files\WindowsPowerShell\Modules\MSAL.PS\4.37.0.0\Select-MsalClientApplication.ps1:56 char:29
+ ... plication = New-MsalClientApplication -ErrorAction Stop @paramNewMsal ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [New-MsalClientApplication], MethodException
    + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument,New-MsalClientApplication

The property 'AppConfig' cannot be found on this object. Verify that the property exists.
At C:\Program Files\WindowsPowerShell\Modules\MSAL.PS\4.37.0.0\Select-MsalClientApplication.ps1:88 char:9
+         Write-Debug ('Adding Application with ClientId [{0}] and Redi ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException
    + FullyQualifiedErrorId : PropertyNotFoundStrict

Add-MsalClientApplication : Cannot bind argument to parameter 'PublicClientApplication' because it is null.
At C:\Program Files\WindowsPowerShell\Modules\MSAL.PS\4.37.0.0\Select-MsalClientApplication.ps1:89 char:35
+         Add-MsalClientApplication $ClientApplication
+                                   ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Add-MsalClientApplication], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Add-MsalClientApplication

You cannot call a method on a null-valued expression.
At C:\Program Files\WindowsPowerShell\Modules\MSAL.PS\4.37.0.0\Get-MsalToken.ps1:258 char:21
+ ...             $AquireTokenParameters = $PublicClientApplication.Acquire ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Program Files\WindowsPowerShell\Modules\MSAL.PS\4.37.0.0\Get-MsalToken.ps1:264 char:68
+ ... r]::Zero) { [void] $AquireTokenParameters.WithParentActivityOrWindow( ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At C:\Program Files\WindowsPowerShell\Modules\MSAL.PS\4.37.0.0\Get-MsalToken.ps1:268 char:36
+ ... ($Prompt) { [void] $AquireTokenParameters.WithPrompt([Microsoft.Ident ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

The variable '$AquireTokenParameters' cannot be retrieved because it has not been set.
At C:\Program Files\WindowsPowerShell\Modules\MSAL.PS\4.37.0.0\Get-MsalToken.ps1:338 char:45
+ ...            elseif ($TenantId) { [void] $AquireTokenParameters.WithAut ...
+                                            ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (AquireTokenParameters:String) [], RuntimeException
    + FullyQualifiedErrorId : VariableIsUndefined

The property 'ClientId' cannot be found on this object. Verify that the property exists.
At C:\Program Files\WindowsPowerShell\Modules\MSAL.PS\4.37.0.0\Get-MsalToken.ps1:343 char:17
+ ...             Write-Debug ('Aquiring Token for Application with ClientI ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], PropertyNotFoundException
    + FullyQualifiedErrorId : PropertyNotFoundStrict

The variable '$AquireTokenParameters' cannot be retrieved because it has not been set.
At C:\Program Files\WindowsPowerShell\Modules\MSAL.PS\4.37.0.0\Get-MsalToken.ps1:385 char:280
+ ... lureAuthenticationError' -TargetObject $AquireTokenParameters -ErrorA ...
+                                            ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (AquireTokenParameters:String) [], RuntimeException
    + FullyQualifiedErrorId : VariableIsUndefined
robinmalik commented 1 year ago

I've no idea why, but things have started working again. Closing.

JorgaWetzel commented 1 year ago

same problem here but unfortunately it does not simply disappear by itself

seanadams9 commented 10 months ago

Also seeing the same problem in PowerShell 7.3.x