-
-
Save neil-sabol/3ceab9221500261bbda76e0893b8734e to your computer and use it in GitHub Desktop.
# Your OneTimeSecret Username and API key from https://onetimesecret.com/account#apikey-tab | |
$apiUsername = "username@example.com" | |
$apiPassword = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" | |
# Invoke-RestMethod is a little "tempermental" with Basic Authentication - the "-Credential" parameter specifically | |
# See https://stackoverflow.com/questions/24672760/powershells-invoke-restmethod-equivalent-of-curl-u-basic-authentication - thanks Borek Bernard | |
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $apiUsername,$apiPassword))) | |
# Specify parameters for random password generation - in this case, a Time to Live in seconds (7 days) | |
$Body = @{ | |
ttl = 604800 | |
} | |
# Call the OneTimeSecret API to generate a random password | |
$oneTimeSecret=Invoke-RestMethod -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method 'Post' -Uri "https://onetimesecret.com/api/v1/generate" -Body $body | |
# Print the generated secret and a URL you can share | |
write-host "$($oneTimeSecret.value)" | |
write-host "https://onetimesecret.com/secret/$($oneTimeSecret.secret_key)" | |
# Clear variables | |
$oneTimeSecret = "" | |
$apiPassword = "" | |
$base64AuthInfo = "" |
Hello Aleksandr - good question. Speaking candidly, this gist is unfortunately not aligned with "...create solutions for the masses, not just sloppy code to brag..."
It aims to address a very specific use case/workflow and eliminate clicks.
It generates and stores a random secret on the Onetimesecret service, then returns the secret (and a Onetimesecret link to it) to the console of the user executing the snippet. Then (as an example), the executor would reset an account password in some system (to the random, generated secret) and provide the Onetimesecret link to the account's owner so they could retrieve it, login, and reset the account password to something they want.
In my case, it saves the clicks of generating a random password (via a separate tool or script), opening a browser, and creating a Onetimesecret link for the password.
I see, Neil, thank you for the explanation.
And where is the message itself, which should be sent to the server?