I'm incredibly new to building API authentication - so wanted to ensure I'm going about this the correct way as there could be major security flaws that I'm not aware of.
It's based on a secret/private key pair, where both the client and the server know the secret key, but it's obviously never passed along the wire.
Any feedback, insights or holes in this method would be greatly appreciated.
Step 1:
The client wants to make a request to the API, so asks for a nonce from the server - passing their public key.
Step 2:
The server lookups the users private key (using the provided public key) and hashes it (sha256) with a random 32 character string (the nonce).
The hashed nonce and public key are then stored to a local array.
The server then responds to the client with the un-hashed version of the nonce.
Step 3:
The client takes the nonce from the response and also hashes it with it's private key (which the client has locally).
It then makes a request to the server (along with the API task it wants to perform) and sends its version of the hashed nonce and public key.
Step 4:
The server takes the clients public key and hashed nonce, then checks the local array to see if the public key/nonce pair exist.
If the pair exist; authentication is passed, the request is allowed and the public key/nonce pair is removed from the local array.