misc/powershell/BankIDTokenFileWatcher.ps1

38 lines
1.0 KiB
PowerShell
Raw Normal View History

2022-06-05 02:48:59 +02:00
#
# BankIDTokenFileWatcher
#
# Starts BankID when a token is written to $TokenFile.
#
# Run this script on logon together with BankID. This script is intended to be
# used with an SSH server installed on the host so that a client can write this
# token to disk.
#
$Token = $null
$LastToken = $null
2022-06-05 02:50:48 +02:00
$TokenFile = "C:\.bidtoken"
2022-06-05 02:48:59 +02:00
Write-Host "Starting file watcher for '$TokenFile'"
while ($true) {
if (Test-Path $TokenFile) {
$TokenFileData = Get-Item "$TokenFile"
if (((Get-Date) - $TokenFileData.LastWriteTime).totalseconds -le 1){
Write-Host "File modified: $TokenFile"
$Token = Get-Content "$TokenFile"
if ($Token -ne $LastToken) {
Write-Host "New token: $Token"
Start-Process "bankid:///?autostarttoken=$Token&redirect=null"
Start-Sleep -Milliseconds 500
$LastToken = $Token
}
else {
Write-Host "Token unchanged: $Token"
}
}
}
Start-Sleep -Milliseconds 500
}