Closed bchap1n closed 4 years ago
ahhh... i see your notes about the runspace error now. :)
[Microsoft.Identity.Client.AuthenticationResult] $AuthenticationResult = $null
switch -Wildcard ($PSCmdlet.ParameterSetName) {
"PublicClient*" {
if ($PSBoundParameters.ContainsKey("UserCredential") -and $UserCredential) {
$AquireTokenParameters = $PublicClientApplication.AcquireTokenByUsernamePassword($Scopes, $UserCredential.UserName, $UserCredential.Password)
}
elseif ($PSBoundParameters.ContainsKey("DeviceCode") -and $DeviceCode) {
# ToDo: Get callback working in the right runspace
# Some links that might be helpful:
# https://powershell.github.io/Polaris/docs/api/New-ScriptblockCallback.html
# https://github.com/PowerShell/Polaris/blob/master/Public/New-ScriptblockCallback.ps1
# https://stackoverflow.com/questions/49737016/powershell-runspace-delegates
[System.Func[Microsoft.Identity.Client.DeviceCodeResult, System.Threading.Tasks.Task]] $deviceCodeResultCallback = {
param([Microsoft.Identity.Client.DeviceCodeResult]$deviceCodeResult)
Write-Console $deviceCodeResult.Message
return [System.Threading.Tasks.Task]::FromResult(0)
}
$AquireTokenParameters = $PublicClientApplication.AcquireTokenWithDeviceCode($Scopes, $deviceCodeResultCallback) # This is not working. No Runspace error.```
This is now working for Windows PowerShell.
I noticed you have parameters commented out for making use of the Device Code flow in Get-MsalToken.ps1. I am very interested in using this feature so that I can easily get tokens with Delegated permissions for a script running on a headless server.