feat: merchant API key auth for POST /payments and GET /payments#60
Merged
Merged
Conversation
- Add merchants table (id, api_key_hash) to migrate() - POST /merchants provisions a merchant and returns a one-time raw key - auth_middleware validates Bearer token via SHA-256 hash lookup - Derive merchant_id from the authenticated key; removed free-text field - Scope GET /payments list to authenticated merchant only - GET /payments/:id remains public (poll by payment id without key) - Add tests: 401 on missing/invalid key, merchant list isolation, idempotency key scoping per merchant Closes StellarGateLabs#9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #9
Every write and list endpoint was unauthenticated. This PR adds Bearer token auth backed by hashed API keys, with merchant-scoped payment visibility.
Changes
src/db.rsmerchantstable creation tomigrate()(id,api_key_hash,created_at)create_merchant(id, raw_key)— hashes key with SHA-256, stores digest onlyfind_merchant_by_key(raw_key)— hashes input and looks up matching merchant idsrc/api/mod.rsPOST /merchants— provisions a merchant, returns one-timeapi_keyauth_middleware— validatesAuthorization: Bearer <key>, injectsAuthenticatedMerchantextensionPOST /paymentsandGET /payments;GET /payments/:idand webhook routes stay publicsrc/api/payments.rscreateandlisthandlers extract merchant id fromAuthenticatedMerchantextension (no free-text field)listscopes DB query to authenticated merchanttests/api_tests.rstest_unauthenticated_create_returns_401test_unauthenticated_list_returns_401test_invalid_api_key_returns_401test_merchant_list_scoped_to_own_paymentsAcceptance criteria
POST /payments→ 401GET /payments→ 401GET /paymentsGET /payments/:idremains public (status polling without a key)