mirror of
https://github.com/Thumbscrew/PSMatrix.git
synced 2025-01-18 09:35:44 +00:00
add function to trim and concat homeserver url and path
This commit is contained in:
parent
e7355a5474
commit
366bde4897
11
private/New-MatrixUrl.ps1
Normal file
11
private/New-MatrixUrl.ps1
Normal file
@ -0,0 +1,11 @@
|
||||
function New-MatrixUrl {
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[string]$ServerUrl,
|
||||
|
||||
[Parameter(Mandatory)]
|
||||
[string]$ApiPath
|
||||
)
|
||||
|
||||
return $ServerUrl.Trim("/") + $ApiPath
|
||||
}
|
@ -31,7 +31,7 @@ function New-MatrixAccessToken {
|
||||
[string]$DeviceDisplayName="PSMatrix"
|
||||
)
|
||||
|
||||
$apiPath = "_matrix/client/v3/login"
|
||||
$url = New-MatrixUrl -ServerUrl $ServerUrl -ApiPath "_matrix/client/v3/login"
|
||||
$apiMethod = "Post"
|
||||
|
||||
$reqBody = @{
|
||||
@ -44,7 +44,7 @@ function New-MatrixAccessToken {
|
||||
initial_device_display_name = $DeviceDisplayName
|
||||
} | ConvertTo-Json
|
||||
|
||||
$res = Invoke-RestMethod -Uri "$ServerUrl/$apiPath" -Method $apiMethod -Body $reqBody
|
||||
$res = Invoke-RestMethod -Uri $url -Method $apiMethod -Body $reqBody
|
||||
|
||||
$token = $res.access_token | ConvertTo-SecureString -AsPlainText
|
||||
|
||||
|
@ -24,7 +24,7 @@ function Remove-MatrixAccessToken {
|
||||
[SecureString]$AccessToken
|
||||
)
|
||||
|
||||
$apiPath = "_matrix/client/v3/logout"
|
||||
$url = New-MatrixUrl -ServerUrl $ServerUrl -ApiPath "_matrix/client/v3/logout"
|
||||
$apiMethod = "Post"
|
||||
|
||||
$headers = @{
|
||||
@ -32,7 +32,7 @@ function Remove-MatrixAccessToken {
|
||||
}
|
||||
|
||||
Try {
|
||||
Invoke-RestMethod -Uri "$ServerUrl/$apiPath" -Method $apiMethod -Headers $headers
|
||||
Invoke-RestMethod -Uri $url -Method $apiMethod -Headers $headers
|
||||
return $true
|
||||
}
|
||||
Catch {
|
||||
|
Loading…
Reference in New Issue
Block a user