Skip to content

Commit 775b1a8

Browse files
authored
Merge pull request AdobeDocs#294 from oshmyheliuk/CEXT-3897
CEXT-3897: Documentation update for webhooks signature verification
2 parents fe8ecde + dc6346f commit 775b1a8

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

src/pages/webhooks/signature-verification.md

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,27 @@ 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 using the same format as provided in the Adobe Commerce Admin:
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:** Do not commit the `.env` file to version control.
109+
110+
[App Builder Configuration Files](https://developer.adobe.com/app-builder/docs/guides/configuration/#env) describes `.env` file usage in detail.
111+
91112
The following code example below shows how the signature can be verified in the App Builder action:
92113

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

0 commit comments

Comments
 (0)