Skip to content

Commit

Permalink
Adding HMAC algorith in autorization header
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek Y authored and Abhishek Y committed Jul 5, 2024
1 parent 62fa683 commit d85c648
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,39 @@ This is a Node.js application designed to function as an intermediary layer betw

[URL for Webhook-Sandbox](https://github.com/beckn/beckn-sandbox-webhook)

### Enabling HMAC Verification on BPP Client

To enable HMAC verification on the BPP client, follow these steps:

### Configuration

- Set `useHMACForWebhook` to `true` in the `default.yaml` configuration file.
- Set `sharedKeyForWebhookHMAC` to your shared key in the `default.yaml` configuration file. Ensure that the `sharedKeyForWebhookHMAC` is exactly 256 bits in length.

### HMAC Verification

- When HMAC verification is enabled and the configurations are set to valid values, the protocol server will include an authorization header containing the HMAC in its messages.
- The BPP client can then use the shared key to verify these messages.

### Example Configuration in `default.yaml`

```yaml
useHMACForWebhook: true
sharedKeyForWebhookHMAC: <YOUR_SHARED_KEY>
```
### Example HMAC
```
Message: {"context":{"domain":"retail","action":"search","bap_id":"retail.bap","bap_uri":"https://retail.bap.com","bpp_id":"retail.bpp","bpp_uri":"https://retail.bpp.com","version":"1.1.0","transaction_id":"51e0cce4-5a20-418b-9f10-797031f3b868","message_id":"829b9ab9-0f1b-4177-95a7-987ac1ed8caa"},"message":{"intent":{"item":{"descriptor":{"code":"assembly"}}}}}

Shared Key: juWDOTzzK7Eyrzm6hZwQmlJkolesm8x0

HMAC: HMAC-SHA-256 8d2b129d83512b53ddd6e3657748a2e22cd05de3f7c4780cdf39da564a843884
```
# Prerequisites
To run the application, make sure you have the following installed:
Expand Down
2 changes: 1 addition & 1 deletion src/utils/auth.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ export const createBppWebhookAuthHeaderConfig = async (request: any) => {
const header = await createBppWebhookAuthHeader(request);
const axios_config = {
headers: {
authorization: header
authorization: `HMAC-SHA-256 ${header}`
}
};
logger.info(
Expand Down

0 comments on commit d85c648

Please sign in to comment.