With NKeys the server can verify identity without ever storing secrets on the server. The authentication system works by requiring a connecting client to provide its public key and digitally sign a challenge with its private key. The server generates a random challenge with every connection request, making it immune to playback attacks. The generated signature is validated a public key, thus proving the identity of the client. If the public key validation succeeds, authentication succeeds.
NKey is an awesome replacement for token authentication, because a connecting client will have to prove it controls the private key for the authorized public key.
go get github.com/nats-io/nkeys/nk
To generate a User NKEY:
nk -gen user -pubout
The first output line starts with the letter
Sfor Seed. The second letter
Ustands for User. Seeds are private keys; you should treat them as secrets and guard them with care.
The second line starts with the letter
Ufor User, and is a public key which can be safely shared.