Files
QAPI/PS1/login.ps1
2026-05-16 23:42:06 +02:00

40 lines
1.2 KiB
PowerShell

# API Configuration
$apiUrl = "https://localhost/action/login"
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
# Headers
$headers = @{
"Content-Type" = "application/json"
}
# Get credentials
$username = Read-Host "Enter username"
$password = Read-Host "Enter password" -AsSecureString
$plainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
# Prepare body
$body = @{
username = $username
password = $plainPassword
} | ConvertTo-Json
# Send request
try {
$response = Invoke-RestMethod -Uri $apiUrl -Method Post -Headers $headers -Body $body
Write-Host "`nAuthentication successful!"
if ($response.isAdmin) {
Write-Host "Admin access granted"
Write-Host "API Token: $($response.token)"
} else {
Write-Host "Regular user access granted"
}
} catch {
Write-Host "`nAuthentication failed. Details:"
Write-Host $_.Exception.Message
if ($_.Exception.Response) {
Write-Host "Status Code:" $_.Exception.Response.StatusCode.value__
}
}