microsoft-teams-apps-requestateam
microsoft-teams-apps-requestateam copied to clipboard
I think I found an error in your code in one spot where you blame the errors on an always $null response
I noticed inside this function, you made the comment below...
630 # NOTE: errors ignored as this appears to error due to a null response
If you look from lines 618-624 you can see the mistake/typo... I am adding the line numbers for your reference, but just for those 7 lines :). You appear to define $url, and then use $uri.
function AuthoriseLogicAppConnection($resourceId) {
$parameters = @{
"parameters" = , @{
"parameterName" = "token";
"redirectUrl" = "http://localhost"
}
}
# Get the links needed for consent
$consentResponse = Invoke-AzResourceAction -Action "listConsentLinks" -ResourceId $resourceId -Parameters $parameters -Force
618 $url = $consentResponse.Value.Link
619
620 # Show sign-in prompt window and grab the code after auth
621 ShowOAuthWindow -URL $url
622
623 $regex = '(code=)(.*)$'
624 $code = ($uri | Select-string -pattern $regex).Matches[0].Groups[2].Value
# Write-output "Received an accessCode: $code"
if (-Not [string]::IsNullOrEmpty($code)) {
$parameters = @{ }
$parameters.Add("code", $code)
# NOTE: errors ignored as this appears to error due to a null response
#confirm the consent code
Invoke-AzResourceAction -Action "confirmConsentCode" -ResourceId $resourceId -Parameters $parameters -Force -ErrorAction Ignore
}
# Retrieve the connection
$connection = Get-AzResource -ResourceId $resourceId
Write-Host "Connection " $connection.Name " now " $connection.Properties.Statuses[0]
}
If I am wrong and it's just way over my head, I apologize!
I have screwed up so many times this weekend being so NEW to all the Cloud stuff, I have drilled into the PowerShell code which I do have some experience with, and it caught my eye.
May I ask you a question or two, if it is not TOO complicated to explain?
At the very beginning of that Function, you define a nested Object....
$parameters = @{
"parameters" = , @{
"parameterName" = "token";
"redirectUrl" = "http://localhost"
}
}
-
Now, I THINK I follow what you are trying to do there... $Parameters contains a second hash "parameters' which contains two properties of "parameterName" and "redirectUrl", which are also defined with values. But WHY go the extra depth? I can imagine needing to do this if passing the first $Parameters through a locally defined function, so the Value Resources which holds your two properties perfectly, would be passed to the local function as an Object in Tact, but I don't understand it here. I am weak on REST though, so surely that is why, I just do not understand, and hoped you might enlighten me :).
-
This one may be much easier to explain, again likely just my lack of understanding but it stands out to me.... On the second line of the same code... how on earth does the COMMA not completely error that whole operation out?
"parameters" = , @{
@Tyrranny Thanks for this - I appreciate it. To be honest this code was 'reused' from elsewhere in the community. I am planning on removing it as it is unreliable and doesn't always work.
I was going to update the documentation to ask the user to authorise the API connections manually as this is far more reliable.
I'll keep this issue open until I get that done.
Thanks