From bf2223b6f630347aaca363f6402c3aa8fb893e2f Mon Sep 17 00:00:00 2001 From: AWBbox Date: Mon, 10 Jun 2019 12:58:04 +0100 Subject: [PATCH 1/8] New function oktaUpdateGroupProfilebyID --- Okta.psm1 | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/Okta.psm1 b/Okta.psm1 index 00beb5c..34fd0bb 100644 --- a/Okta.psm1 +++ b/Okta.psm1 @@ -991,6 +991,50 @@ function oktaUpdateUserbyID() return $request } +function oktaUpdateGroupProfilebyID() +{ + param + ( + [parameter(Mandatory=$false)][ValidateLength(1,100)][String]$oOrg=$oktaDefOrg, + [parameter(Mandatory=$true)][ValidateLength(20,20)][String]$gid, + [parameter(Mandatory=$false)][ValidateLength(1,255)][String]$name, + [parameter(Mandatory=$false)][ValidateLength(1,1024)][String]$description + ) + [string]$method = "Put" + [string]$resource = "/api/v1/groups/" + $gid + if (!$name -and !$description) + { + throw ("Must specify name and/or description") + } + if (!$name) + { + $name = (oktaGetGroupbyId -oOrg $oOrg -gid $gid).profile.name + } + if (!$description) + { + $description = (oktaGetGroupbyId -oOrg $oOrg -gid $gid).profile.description + } + $psobj = @{ + profile = @{ + name = $name + description = $description + } + } + try + { + $request = _oktaNewCall -oOrg $oOrg -method $method -resource $resource -body $psobj + } + catch + { + if ($oktaVerbose -eq $true) + { + Write-Host -ForegroundColor red -BackgroundColor white $_.TargetObject + } + throw $_ + } + return $request +} + function oktaChangePasswordbyID() { param From f3ee234461ee997298cb6a09c577bc4e22b0989a Mon Sep 17 00:00:00 2001 From: AWBbox Date: Mon, 10 Jun 2019 13:21:15 +0100 Subject: [PATCH 2/8] New function oktaUpdateGroupProfilebyID --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b310f60..955b9e8 100644 --- a/README.md +++ b/README.md @@ -226,6 +226,7 @@ catch - oktaUpdateApp - oktaUpdateAppExternalIdbyUserId - oktaUpdateAppProfilebyUserId +- oktaUpdateGroupProfilebyID - oktaUpdateUserbyID - oktaUpdateUserProfilebyID - oktaVerifyMFAnswerbyUser From 30da61772072c36e2714eb65cb24666c49413ce5 Mon Sep 17 00:00:00 2001 From: AWBbox Date: Tue, 23 Jul 2019 12:26:06 +0100 Subject: [PATCH 3/8] Bugfix for oktaUpdateGroupProfilebyID --- Okta.psm1 | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Okta.psm1 b/Okta.psm1 index 34fd0bb..67f78fd 100644 --- a/Okta.psm1 +++ b/Okta.psm1 @@ -1011,9 +1011,16 @@ function oktaUpdateGroupProfilebyID() $name = (oktaGetGroupbyId -oOrg $oOrg -gid $gid).profile.name } if (!$description) - { - $description = (oktaGetGroupbyId -oOrg $oOrg -gid $gid).profile.description - } + { + try + { + $description = (oktaGetGroupbyId -oOrg $oOrg -gid $gid).profile.description + } + catch + { + $description = " " + } + } $psobj = @{ profile = @{ name = $name From 7c2ffe58eb843fd8d2aeebe945aa8a0c59ae6d14 Mon Sep 17 00:00:00 2001 From: AWBbox Date: Tue, 23 Jul 2019 15:51:59 +0100 Subject: [PATCH 4/8] oktaGetRoleTargetsByUserId now works for deactivated users --- Okta.psm1 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Okta.psm1 b/Okta.psm1 index 67f78fd..b5a34fd 100644 --- a/Okta.psm1 +++ b/Okta.psm1 @@ -2565,16 +2565,18 @@ function oktaGetRoleTargetsByUserId() param ( [parameter(Mandatory=$false)][ValidateLength(1,100)][String]$oOrg=$oktaDefOrg, - [parameter(Mandatory=$true)][alias("userId")][ValidateLength(20,20)][String]$uid, - [parameter(Mandatory=$true)][alias("roleId")][ValidateLength(14,24)][String]$rid + [parameter(Mandatory=$true)][alias("userId")][ValidateLength(20,20)][String]$uid ) - [string]$resource = "/api/v1/users/" + $uid + "/roles/" + $rid + "/targets/groups" + [string]$resource = "/api/internal/administrators/" + $uid [string]$method = "Get" try { - $request = _oktaNewCall -method $method -resource $resource -oOrg $oOrg -enablePagination:$true + $roledetails = _oktaNewCall -method $method -resource $resource -oOrg $oOrg -enablePagination:$true + $request = ForEach ($gid in ($roledetails).userAdminGroupIds) { + oktaGetGroupbyId -oOrg $oOrg -gid $gid + } } catch { From 785bacc45aa93d8630fd71ee752d1c31ce2a3104 Mon Sep 17 00:00:00 2001 From: AWBbox Date: Fri, 11 Jun 2021 14:32:07 +0100 Subject: [PATCH 5/8] Fixed function oktaGetRoleTargetsByUserId --- Okta.psm1 | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Okta.psm1 b/Okta.psm1 index 00beb5c..458fc16 100644 --- a/Okta.psm1 +++ b/Okta.psm1 @@ -4631,6 +4631,46 @@ function oktaListAppAssignments() return $request } +function oktaUpdateGroupProfilebyID() +{ + param + ( + [parameter(Mandatory=$false)][ValidateLength(1,100)][String]$oOrg=$oktaDefOrg, + [parameter(Mandatory=$true)][ValidateLength(20,20)][String]$gid, + [parameter(Mandatory=$false)][ValidateLength(1,255)][String]$name, + [parameter(Mandatory=$false)][ValidateLength(1,1024)][String]$description + ) + [string]$method = "Put" + [string]$resource = "/api/v1/groups/" + $gid + if ($null -eq $name) + { + $name = (oktaGetGroupbyId -oOrg $oOrg -gid $gid).profile.name + } + if ($null -eq $description) + { + $description = (oktaGetGroupbyId -oOrg $oOrg -gid $gid).profile.description + } + $psobj = @{ + profile = @{ + name = $name + description = $description + } + } + try + { + $request = _oktaNewCall -oOrg $oOrg -method $method -resource $resource -body $psobj + } + catch + { + if ($oktaVerbose -eq $true) + { + Write-Host -ForegroundColor red -BackgroundColor white $_.TargetObject + } + throw $_ + } + return $request +} + ################## _links ########################### function oktaFetch_link() From 49bd4cf5da89e69f02805af01aef29244f5c1080 Mon Sep 17 00:00:00 2001 From: AWBbox Date: Fri, 11 Jun 2021 14:44:47 +0100 Subject: [PATCH 6/8] Fixed oktaGetRoleTargetsByUserId function --- Okta.psm1 | 61 ++++--------------------------------------------------- 1 file changed, 4 insertions(+), 57 deletions(-) diff --git a/Okta.psm1 b/Okta.psm1 index 5508811..458fc16 100644 --- a/Okta.psm1 +++ b/Okta.psm1 @@ -991,57 +991,6 @@ function oktaUpdateUserbyID() return $request } -function oktaUpdateGroupProfilebyID() -{ - param - ( - [parameter(Mandatory=$false)][ValidateLength(1,100)][String]$oOrg=$oktaDefOrg, - [parameter(Mandatory=$true)][ValidateLength(20,20)][String]$gid, - [parameter(Mandatory=$false)][ValidateLength(1,255)][String]$name, - [parameter(Mandatory=$false)][ValidateLength(1,1024)][String]$description - ) - [string]$method = "Put" - [string]$resource = "/api/v1/groups/" + $gid - if (!$name -and !$description) - { - throw ("Must specify name and/or description") - } - if (!$name) - { - $name = (oktaGetGroupbyId -oOrg $oOrg -gid $gid).profile.name - } - if (!$description) - { - try - { - $description = (oktaGetGroupbyId -oOrg $oOrg -gid $gid).profile.description - } - catch - { - $description = " " - } - } - $psobj = @{ - profile = @{ - name = $name - description = $description - } - } - try - { - $request = _oktaNewCall -oOrg $oOrg -method $method -resource $resource -body $psobj - } - catch - { - if ($oktaVerbose -eq $true) - { - Write-Host -ForegroundColor red -BackgroundColor white $_.TargetObject - } - throw $_ - } - return $request -} - function oktaChangePasswordbyID() { param @@ -2565,18 +2514,16 @@ function oktaGetRoleTargetsByUserId() param ( [parameter(Mandatory=$false)][ValidateLength(1,100)][String]$oOrg=$oktaDefOrg, - [parameter(Mandatory=$true)][alias("userId")][ValidateLength(20,20)][String]$uid + [parameter(Mandatory=$true)][alias("userId")][ValidateLength(20,20)][String]$uid, + [parameter(Mandatory=$true)][alias("roleId")][ValidateLength(14,24)][String]$rid ) - [string]$resource = "/api/internal/administrators/" + $uid + [string]$resource = "/api/v1/users/" + $uid + "/roles/" + $rid + "/targets/groups" [string]$method = "Get" try { - $roledetails = _oktaNewCall -method $method -resource $resource -oOrg $oOrg -enablePagination:$true - $request = ForEach ($gid in ($roledetails).userAdminGroupIds) { - oktaGetGroupbyId -oOrg $oOrg -gid $gid - } + $request = _oktaNewCall -method $method -resource $resource -oOrg $oOrg -enablePagination:$true } catch { From 461f4b91fd4b5a313a0eca8c0474eba2a3cab40a Mon Sep 17 00:00:00 2001 From: AWBbox Date: Fri, 11 Jun 2021 14:46:27 +0100 Subject: [PATCH 7/8] New functions by @unhappyfred --- Okta.psm1 | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/Okta.psm1 b/Okta.psm1 index 458fc16..c928f0f 100644 --- a/Okta.psm1 +++ b/Okta.psm1 @@ -2509,6 +2509,60 @@ function oktaDelUserFromRoles() return $request } +function oktaAddgroupIDtoAppID +{ + param + ( + [parameter(Mandatory=$false)][ValidateLength(1,100)][String]$oOrg=$oktaDefOrg, + [parameter(Mandatory=$true)][alias("groupID")][ValidateLength(20,20)][String]$gid, + [parameter(Mandatory=$true)][ValidateLength(20,20)][String]$aid + ) + + [string]$resource = "/api/v1/apps/" + $aid + "/groups/" + $gid + [string]$method = "Put" + + try + { + $request = _oktaNewCall -method $method -resource $resource -oOrg $oOrg + } + catch + { + if ($oktaVerbose -eq $true) + { + Write-Host -ForegroundColor red -BackgroundColor white $_.TargetObject + } + throw $_ + } + return $request +} + +function oktaDelGroupIDfromAppID +{ + param + ( + [parameter(Mandatory=$false)][ValidateLength(1,100)][String]$oOrg=$oktaDefOrg, + [parameter(Mandatory=$true)][alias("groupID")][ValidateLength(20,20)][String]$gid, + [parameter(Mandatory=$true)][ValidateLength(20,20)][String]$aid + ) + + [string]$resource = "/api/v1/apps/" + $aid + "/groups/" + $gid + [string]$method = "Delete" + + try + { + $request = _oktaNewCall -method $method -resource $resource -oOrg $oOrg + } + catch + { + if ($oktaVerbose -eq $true) + { + Write-Host -ForegroundColor red -BackgroundColor white $_.TargetObject + } + throw $_ + } + return $request +} + function oktaGetRoleTargetsByUserId() { param From 24105dfba7d7b2f14c3a91c1871635cedca8bf18 Mon Sep 17 00:00:00 2001 From: AWBbox Date: Tue, 23 Nov 2021 14:23:10 +0000 Subject: [PATCH 8/8] Added oktaUpdateRoleNotification function, amend oktaMakeCall --- Okta.psm1 | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/Okta.psm1 b/Okta.psm1 index 37b502c..53ec5e0 100644 --- a/Okta.psm1 +++ b/Okta.psm1 @@ -460,13 +460,15 @@ function _oktaMakeCall() Write-Verbose("Req-Hdr: " + "User-Agent" + " -> " + $userAgent) try { + if ($body.Count -gt 0) { + $postData = ConvertTo-Json $body -Depth 10 + Write-Verbose($postData) + } if (!$Global:myWebSession) { Write-Verbose("Creating myWebSession first") if ( ($method -eq "Post") -or ($method -eq "Put") ) { - $postData = ConvertTo-Json $body -Depth 10 - Write-Verbose($postData) $request2 = Invoke-WebRequest -Uri $uri -Method $method -UserAgent $userAgent -Headers $headers ` -ContentType $contentType -Verbose:$oktaVerbose -Body $postData -ErrorVariable evar -SessionVariable Global:myWebSession } else { @@ -476,8 +478,6 @@ function _oktaMakeCall() } else { if ( ($method -eq "Post") -or ($method -eq "Put") ) { - $postData = ConvertTo-Json $body -Depth 10 - Write-Verbose($postData) $request2 = Invoke-WebRequest -Uri $uri -Method $method -UserAgent $userAgent -Headers $headers ` -ContentType $contentType -Verbose:$oktaVerbose -Body $postData -ErrorVariable evar -WebSession $Global:myWebSession } else { @@ -2627,6 +2627,45 @@ function oktaDelUserFromRoles() return $request } +function oktaUpdateRoleNotification() +{ + param( + [parameter(ParameterSetName="user", mandatory=$true)] + [ValidateLength(20,20)][string]$uid, + [parameter(ParameterSetName="group", mandatory=$true)] + [ValidateLength(20,20)][string]$gid, + [parameter(ParameterSetName="user", mandatory=$true)] + [parameter(ParameterSetName="group", mandatory=$true)] + [ValidateSet('true','false')][string]$notification, + [parameter(ParameterSetName="user", mandatory=$false)] + [parameter(ParameterSetName="group", mandatory=$false)] + [ValidateLength(1,100)][string]$oOrg=$oktaDefOrg + ) + + [string]$method = "Post" + + if($uid) { + [string]$resource = "/api/v1/users/" + $uid + "/roles?disableNotifications=" + $notification + } + elseif($gid) { + [string]$resource = "/api/v1/groups/" + $gid + "/roles?disableNotifications=" + $notification + } + + try + { + $request = _oktaNewCall -oOrg $oOrg -method $method -resource $resource -WarningAction SilentlyContinue + } + catch + { + if ($oktaVerbose -eq $true) + { + Write-Host -ForegroundColor red -BackgroundColor white $_.TargetObject + } + throw $_ + } + return $request +} + function oktaAddgroupIDtoAppID { param