@@ -94,6 +94,65 @@ 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 via the Servient
123+ using ` addCredentials() ` . The credentials are associated with the
124+ Thing's ` id ` and are automatically applied based on the TD security
125+ configuration.
126+
127+ ``` js
128+ const { Servient } = require (" @node-wot/core" );
129+ const { CoapsClientFactory } = require (" @node-wot/binding-coap" );
130+
131+ const servient = new Servient ();
132+ servient .addClientFactory (new CoapsClientFactory ());
133+
134+ servient .start ().then (async (WoT ) => {
135+ const td = await WoT .requestThingDescription (" coaps://example.com/secure-thing" );
136+
137+ // Configure PSK credentials for this Thing
138+ servient .addCredentials ({
139+ [td .id ]: {
140+ identity: " Client_identity" ,
141+ psk: " secretPSK" ,
142+ },
143+ });
144+
145+ const thing = await WoT .consume (td);
146+
147+ await thing .invokeAction (" someAction" );
148+ });
149+ ```
150+
151+ The ` identity ` and ` psk ` values must match the configuration of the
152+ CoAPs server.
153+
154+ > ** Note:** Only the psk security scheme is currently supported for CoAPs.
155+
97156### More Details
98157
99158See < https://github.com/eclipse-thingweb/node-wot/ >
0 commit comments