Powershell API code

  1. Install PS version 7.2 https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.2
  2. Install module PSPGP GitHub - EvotecIT/PSPGP: PSPGP is a PowerShell module that provides PGP functionality in PowerShell. It allows encrypting and decrypting files/folders and strings using PGP.
    quick code
$Server = 'https://passbolt.domain.local'
$UriLogin = '/auth/login.json'
$UriResourse = '/resources.json'
$UriUsers = '/users.json'
$MyFingerPrint = '73A618F461779F195C6E864E6BBF4D67D25EDB05'
$Password = Read-Host "Enter a passphrase" -MaskInput
$PrivateKeyPath = 'Full_path_for_passbolt_private.asc'

# skip stage0
#stage1
$Body = @{
    'data[gpg_auth][keyid]' = $MyFingerPrint
}
$Response1 = Invoke-WebRequest -Uri ($Server+$UriLogin) -Method Post -ContentType 'multipart/form-data' -Form ($Body)
$DecryptedToken = Unprotect-PGP -FilePathPrivate $PrivateKeyPath -Password $Password -String ([System.Web.HttpUtility]::UrlDecode($Response1.Headers.'X-GPGAuth-User-Auth-Token').Replace('\ ',' '))

$Body = @{
    'data[gpg_auth][keyid]' = $MyFingerPrint
    'data[gpg_auth][user_token_result]' = $DecryptedToken
}

$Response2 = Invoke-WebRequest -Uri ($Server+$UriLogin) -Method Post -ContentType 'multipart/form-data' -Form ($Body) -SessionVariable WebSession
$Response3 = Invoke-WebRequest -Uri ($Server) -Method Get -WebSession $WebSession
$csrfToken = ($WebSession.Cookies.GetAllCookies() | Where-Object {$_.Name -eq 'csrfToken'}).value
$Headers = @{
    'X-CSRF-Token' = $csrfToken
}
$Resources = ((Invoke-WebRequest -Uri ($Server+$UriResourse) -Method Get -Headers $Headers -WebSession $WebSession) |ConvertFrom-Json).Body
$Users = ((Invoke-WebRequest -Uri ($Server+$UriUsers) -Method Get -Headers $Headers -WebSession $WebSession) |ConvertFrom-Json).Body