Skip to content

Commit 842efed

Browse files
authored
improve provided cert/key docs for CAP Node.js (#38)
1 parent 03bee1e commit 842efed

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

docs/Authorization/AuthorizationBundle.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,23 @@ const ams = AuthorizationManagementService
101101
```
102102

103103
```js [Node.js (CAP)]
104+
// server.js
105+
const cds = require('@sap/cds');
104106
const { amsCapPluginRuntime } = require("@sap/ams");
105107

106-
// Update the credentials of the AMS CAP plugin runtime
107-
// with the certificate information.
108-
// cert and key must be PEM-encoded strings
109-
amsCapPluginRuntime.credentials = {
110-
...amsCapPluginRuntime.credentials,
111-
cert,
112-
key
113-
}
108+
// Extend the AMS CAP plugin runtime credentials with the provided certificate/key.
109+
cds.on('served', async () => {
110+
// assuming cert and key are PEM-encoded strings
111+
amsCapPluginRuntime.credentials.certificate = cert;
112+
amsCapPluginRuntime.credentials.key = key;
113+
});
114+
115+
// If certificate/key change during runtime, update the properties inside the credentials object again.
116+
someCredentialsWatcher.on('change', (newCert, newKey) => {
117+
// assuming newCert and newKey are PEM-encoded strings
118+
amsCapPluginRuntime.credentials.certificate = newCert;
119+
amsCapPluginRuntime.credentials.key = newKey;
120+
});
114121
```
115122

116123
```java [Java]

0 commit comments

Comments
 (0)