2022-03-12 22:53:06 +00:00
|
|
|
<#
|
|
|
|
.Synopsis
|
|
|
|
Invalidate the provided Access token.
|
|
|
|
|
|
|
|
.Description
|
|
|
|
Invalidate the provided Access token. See https://spec.matrix.org/v1.2/client-server-api/#post_matrixclientv3logout.
|
|
|
|
|
|
|
|
.Parameter ServerUrl
|
|
|
|
URL for the Matrix server to log into, for example "https://matrix.example.com".
|
|
|
|
|
|
|
|
.Parameter AccessToken
|
|
|
|
The Access token to invalidate.
|
|
|
|
|
|
|
|
.Example
|
|
|
|
Remove-MatrixAccessToken -ServerUrl "https://matrix.example.com" -AccessToken $token
|
|
|
|
#>
|
|
|
|
|
|
|
|
function Remove-MatrixAccessToken {
|
|
|
|
param(
|
|
|
|
[Parameter(Mandatory)]
|
|
|
|
[string]$ServerUrl,
|
|
|
|
|
|
|
|
[Parameter(Mandatory)]
|
|
|
|
[SecureString]$AccessToken
|
|
|
|
)
|
|
|
|
|
2022-03-27 14:29:44 +00:00
|
|
|
$url = New-MatrixUrl -ServerUrl $ServerUrl -ApiPath "_matrix/client/v3/logout"
|
2022-03-12 22:53:06 +00:00
|
|
|
$apiMethod = "Post"
|
|
|
|
|
|
|
|
$headers = @{
|
|
|
|
Authorization="Bearer " + ($AccessToken | ConvertFrom-SecureString -AsPlainText)
|
|
|
|
}
|
|
|
|
|
|
|
|
Try {
|
2022-03-27 14:29:44 +00:00
|
|
|
Invoke-RestMethod -Uri $url -Method $apiMethod -Headers $headers
|
2022-03-12 22:53:06 +00:00
|
|
|
return $true
|
|
|
|
}
|
|
|
|
Catch {
|
|
|
|
Write-Error $_
|
|
|
|
return $false
|
|
|
|
}
|
|
|
|
}
|