Check the API key on every request that a customer sends to your API
Each Lanternfish Maps customer sends their account ID in the X-Lanternfish-Account header and their API key as a bearer token. The requireCustomerKey function in the sample passes both to verifyCredential, which checks the key against that account and adds one to the usage count of the key when the key is valid.
Impact
Since the SDK places the account ID in the URL path of its request to Auth, the function answers with 401 when that ID is missing or contains a character other than a letter, a digit, an underscore, or a hyphen. The function also answers with 401 whenever Auth rejects the key, for example because the secret is wrong or because the key is revoked or expired. When a key goes over the rate limit that you set on it, Auth answers with HTTP 429, so the function returns 429 to the customer.
Prompt for a coding agent: Check the API key on every customer request, and return 429 when a key reaches its limit.
Select a file to view its contents