Skip to content

Commit cd7b3fd

Browse files
committed
docs(binding-coap): document PSK usage with CoAPs
Add example and explanation for configuring PSK security scheme in CoapsClient. Closes #954 Signed-off-by: Pranav Ghorpade <pranavghorpade61@gmail.com>
1 parent fcaa652 commit cd7b3fd

1 file changed

Lines changed: 54 additions & 0 deletions

File tree

packages/binding-coap/README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,60 @@ servient.start().then((WoT) => {
9494
});
9595
```
9696

97+
## Using CoAPs with PSK
98+
99+
The CoAP binding also supports secure CoAP (`coaps://`) using DTLS with the
100+
`psk` (Pre-Shared Key) security scheme.
101+
102+
Currently, PSK support is implemented in the `CoapsClient` and can be
103+
configured via the Thing Description and client credentials.
104+
105+
### Thing Description Example
106+
107+
To use PSK, the Thing Description must define a `psk` security scheme:
108+
109+
```json
110+
{
111+
"securityDefinitions": {
112+
"psk_sc": {
113+
"scheme": "psk"
114+
}
115+
},
116+
"security": ["psk_sc"]
117+
}
118+
```
119+
120+
### Client Configuration Example
121+
122+
On the client side, credentials must be provided using the `identity`
123+
and `psk` fields:
124+
125+
```js
126+
const { Servient } = require("@node-wot/core");
127+
const { CoapClientFactory } = require("@node-wot/binding-coap");
128+
129+
const servient = new Servient();
130+
servient.addClientFactory(new CoapClientFactory());
131+
132+
servient.start().then(async (WoT) => {
133+
const td = await WoT.requestThingDescription("coaps://example.com/secure-thing");
134+
const thing = await WoT.consume(td);
135+
136+
// Configure PSK credentials
137+
thing.setSecurity(td.securityDefinitions, {
138+
identity: "Client_identity",
139+
psk: "secretPSK",
140+
});
141+
142+
await thing.invokeAction("someAction");
143+
});
144+
```
145+
146+
The `identity` and `psk` values must match the configuration of the
147+
CoAPs server.
148+
149+
> **Note:** Only the psk security scheme is currently supported for CoAPs.
150+
97151
### More Details
98152

99153
See <https://github.com/eclipse-thingweb/node-wot/>

0 commit comments

Comments
 (0)