mirror of
https://github.com/Thumbscrew/PSMatrix.git
synced 2024-11-09 23:53:51 +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"
|
[string]$DeviceDisplayName="PSMatrix"
|
||||||
)
|
)
|
||||||
|
|
||||||
$apiPath = "_matrix/client/v3/login"
|
$url = New-MatrixUrl -ServerUrl $ServerUrl -ApiPath "_matrix/client/v3/login"
|
||||||
$apiMethod = "Post"
|
$apiMethod = "Post"
|
||||||
|
|
||||||
$reqBody = @{
|
$reqBody = @{
|
||||||
@ -44,7 +44,7 @@ function New-MatrixAccessToken {
|
|||||||
initial_device_display_name = $DeviceDisplayName
|
initial_device_display_name = $DeviceDisplayName
|
||||||
} | ConvertTo-Json
|
} | 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
|
$token = $res.access_token | ConvertTo-SecureString -AsPlainText
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ function Remove-MatrixAccessToken {
|
|||||||
[SecureString]$AccessToken
|
[SecureString]$AccessToken
|
||||||
)
|
)
|
||||||
|
|
||||||
$apiPath = "_matrix/client/v3/logout"
|
$url = New-MatrixUrl -ServerUrl $ServerUrl -ApiPath "_matrix/client/v3/logout"
|
||||||
$apiMethod = "Post"
|
$apiMethod = "Post"
|
||||||
|
|
||||||
$headers = @{
|
$headers = @{
|
||||||
@ -32,7 +32,7 @@ function Remove-MatrixAccessToken {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Try {
|
Try {
|
||||||
Invoke-RestMethod -Uri "$ServerUrl/$apiPath" -Method $apiMethod -Headers $headers
|
Invoke-RestMethod -Uri $url -Method $apiMethod -Headers $headers
|
||||||
return $true
|
return $true
|
||||||
}
|
}
|
||||||
Catch {
|
Catch {
|
||||||
|
Loading…
Reference in New Issue
Block a user