From 28c3a417e7e0e8c6f7ac37b95967dbb1f1f6798b Mon Sep 17 00:00:00 2001 From: FFFreak <38145587+FFFreak@users.noreply.github.com> Date: Mon, 1 Nov 2021 12:36:06 -0700 Subject: [PATCH] Update to allow multiple sessions in same PoSh Session I left some debug code in the prior suggestion. This is without the 2 lines of debug code. This edits _oktaMakeCall to check a state variable based on uri passed to the function to make a unique variable to hold state of websessions. This allows the global:mywebsession variable to be saved at end of function and recalled for EACH org in the Okta_org.ps1. TODO: There might be invalid characters possible in variable names, I did not validate if URL host characters can be the same space as powershell variable names. --- Okta.psm1 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Okta.psm1 b/Okta.psm1 index 94cbf76..c0d5ba0 100644 --- a/Okta.psm1 +++ b/Okta.psm1 @@ -440,6 +440,14 @@ function _oktaMakeCall() [parameter(Mandatory=$false)][String]$userAgent, [parameter(Mandatory=$false)][String]$contentType = "application/json" ) + <# Lets build in a websession switcher #> + $oOrgVar = $uri.split(".")[0].split("//")[-1] # holds oOrg Info for state save + if ((Get-Variable -Name $("myWebSession" + $oOrgVar) -Scope Global -ErrorAction SilentlyContinue) -ne $null) { + $Global:myWebSession = (Get-Variable -Name $("myWebSession" + $oOrgVar) -Scope Global).value + } else { + # First Run Through + } + <# End Switcher #> if (!$userAgent) { @@ -634,7 +642,11 @@ function _oktaMakeCall() } if ($rateLimt){ _oktaRateLimitCheck } - + + <# Variable Switcher - save state #> + Set-Variable -Name $("myWebSession" + $oOrgVar) -value $(Get-Variable -Name "myWebSession" -Scope Global).value -Scope Global + <# End - Save state#> + return @{ result = $result ; next = $next ; ratelimit = $rateLimt } }