Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Clear-Host
# Client ID obtained after registering here https://upgrade.yubico.com/getapikey/
$clientID = '12345'
# Read in the key
$getKey = Read-Host 'Insert your YubiKey and touch it until the OTP is received (~2 seconds)'
$credentialID = $getKey.Substring(0, 12)
# Generate a Nonce
$nonce = -join ((65..90) + (97..122) | Get-Random -Count 32 | ForEach-Object { [char]$_ })
$nonce = $nonce.ToLower()
# Send Validation Request
$response = Invoke-RestMethod -Method Post -Uri "https://api.yubico.com/wsapi/2.0/verify?otp=$($getKey)&id=$($clientID)&timeout=8&sl=50&nonce=$($nonce)" -Headers @{'Content-Type' = 'application/json' }
$status = $response -split ("`r`n")
# Check the response and output
if ($status.Contains("status=OK")) {
# SUCCESSFUL
write-host "***********SUCCESS****************"
write-host "Credential ID $($credentialID)"
write-host "Status: $($status[5].Split("=")[1])"
write-host "OTP: $($status[2].Split("=")[1])"
write-host "Signature: $($status[0].Split("=")[1])"
write-host "Timestamp: $($status[1].Split("=")[1])"
write-host "Nonce: $($status[3].Split("=")[1])"
}
else {
# ERROR
write-host "============ERROR==============="
write-host "Credential ID $($credentialID)"
write-host "Status: $($status[4].Split("=")[1])"
write-host "OTP: $($status[2].Split("=")[1])"
write-host "Signature: $($status[0].Split("=")[1])"
write-host "Timestamp: $($status[1].Split("=")[1])"
write-host "Nonce: $($status[3].Split("=")[1])"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment