add Remove-MatrixAccessToken

This commit is contained in:
James 2022-03-12 22:53:06 +00:00
parent 605a50b713
commit e7355a5474
2 changed files with 44 additions and 1 deletions

View File

@ -70,7 +70,8 @@ PowerShellVersion = '7.0'
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
FunctionsToExport = @( FunctionsToExport = @(
'New-MatrixAccessToken' 'New-MatrixAccessToken',
'Remove-MatrixAccessToken'
) )
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.

View File

@ -0,0 +1,42 @@
<#
.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
)
$apiPath = "_matrix/client/v3/logout"
$apiMethod = "Post"
$headers = @{
Authorization="Bearer " + ($AccessToken | ConvertFrom-SecureString -AsPlainText)
}
Try {
Invoke-RestMethod -Uri "$ServerUrl/$apiPath" -Method $apiMethod -Headers $headers
return $true
}
Catch {
Write-Error $_
return $false
}
}