Basic authentication is very simple authentication scheme and built-in with HTTP protocol. The client needs to send requests with Authorization header with Basic
and base64 encoded string of username and password.
Authorization: Basic ZGVtbzpwQDU1dzByZA==
This is secure only if used with HTTPS or SSL.
API Keys - They are token and known only to client and server. For every API call client has to send api-key, it can be in url or header. This is also secure only if used with HTTPS or SSL.
Instead of sending credentials or api-keys for every request, tokens are used. In a few words, an authentication scheme based on tokens follow these steps:
Authorization: Bearer <token>
In above steps we see server is storing tokens. To truely have stateless authentication we can use signed tokens like JWT(JSON Web Token). The JWT has 3 sections header, payload and signature. In header it has type of token and signing algorithm. The payload has user related information. While signature has encoded header and payload, along with secret key to sign it.