Skip to content

Commit abf1209

Browse files
committed
CEXT-3897: Documentation update for webhooks signature verification
1 parent fe8ecde commit abf1209

File tree

1 file changed

+36
-3
lines changed

1 file changed

+36
-3
lines changed

src/pages/webhooks/signature-verification.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,28 @@ To verify the signature in the App Builder action, set the `raw-http` annotation
8888
raw-http: true
8989
```
9090
91+
Store the public key in the `PUBLIC_KEY` parameter in the `.env` file in the same format as provided in the Adobe Commerce admin UI:
92+
93+
```env
94+
# Other secrets and configuration
95+
# ...............................
96+
97+
PUBLIC_KEY="-----BEGIN PUBLIC KEY-----
98+
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtglXYVz5pVn3HDluGG5T
99+
t9coO5NKSWjx3xCDMHVa3CEqVM76PKg8UJH9fQOA57xoNv7Llc916pF0UswtudQh
100+
Fyg+WQCFFadqGZOyL2nUKI9xWBiUi4dN8+9yMd3TE1fszVUBnk/XdLKNDQn4O6ic
101+
doQZi5arrjNjInkimtcT2jPXs34p9G9P5CvCubPUmbGsWDgwo5an9LEX/nJfnCdZ
102+
R10XPkRWzEM7o1OGzf7CYo06Xl+msGVM02Er265PsMAWB11cWwKmyg6dLPa8q+Qh
103+
KNXZiEMvdVusV8aA6EkCZYFdWSBXv+jltn6NnY5qvYcuQ3SujQ9xKEANjeMWcW90
104+
PwIDAQAB
105+
-----END PUBLIC KEY-----"
106+
```
107+
108+
**Note:** The `.env` file should not be committed to version control.
109+
110+
More information on [.env file usage](https://developer.adobe.com/app-builder/docs/guides/configuration/#env).
111+
112+
91113
The following code example below shows how the signature can be verified in the App Builder action:
92114

93115
```javascript
@@ -109,9 +131,20 @@ async function main (params) {
109131
if (isSignatureValid) {
110132
logger.info('The signature is valid.');
111133
// Here will be performed real action logic
112-
operations.push({
113-
op: 'success'
114-
});
134+
// payload is base64 encoded, so we need to decode it before using
135+
const payload = JSON.parse(atob(params.__ow_body))
136+
137+
// a simple validation if the provided postcode from Commerce webhook is less than 50000
138+
if (payload.address.postcode > 50000) {
139+
operations.push({
140+
op: 'exception',
141+
message: 'The postcode is not allowed. Provided postcode: ' + payload.address.postcode
142+
});
143+
} else {
144+
operations.push({
145+
op: 'success'
146+
});
147+
}
115148
} else {
116149
logger.info('The signature is invalid.');
117150
operations.push({

0 commit comments

Comments
 (0)