Customers can read their results and invite candidates from their own systems through a small JSON API. The interesting part was not the endpoints, it was deciding what a key is allowed to be, and what we are willing to store.
The reference is public if you want to follow along: the API docs .
A key is 240 bits, shown once
A key looks like cpa_ followed by 40 characters from 30 random bytes:
export function generateApiKey ( ) { const key = `${API_KEY_PREFIX}${randomBytes(30).toString('base64url')}` ; return { key , prefix : key . slice ( 0 , VISIBLE_LENGTH ) , hash : hashApiKey ( key ) } ; }
Enter fullscreen mode
Exit fullscreen mode
The owner sees the full key once, when it is created. We store only its SHA-256 hash, plus the first twelve characters in the clear so a person can recognise a key in the list. A copy of the database is therefore no use for calling the API.
A plain SHA-256 is fine here, and a slow password hash would be wrong.…