Skip to content

Commit 2028c89

Browse files
committed
Update switchbot-openapi.ts
1 parent 838176f commit 2028c89

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/switchbot-openapi.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export class SwitchBotOpenAPI extends EventEmitter {
170170
* - `t`: The current timestamp in milliseconds since the Unix epoch.
171171
* - `Content-Type`: The content type of the request, set to `application/json`.
172172
*/
173-
private generateHeaders = (): { 'Authorization': string, 'sign': string, 'nonce': `${string}-${string}-${string}-${string}-${string}`, 't': string, 'Content-Type': string } => {
173+
private generateHeaders = (): { 'Authorization': string, 'sign': string, 'nonce': `${string}-${string}-${string}-${string}-${string}`, 't': string, 'Content-Type': string, 'X-Amz-Date': string } => {
174174
const t = `${Date.now()}`
175175
const nonce = randomUUID()
176176
const data = this.token + t + nonce
@@ -179,13 +179,15 @@ export class SwitchBotOpenAPI extends EventEmitter {
179179
.update(Buffer.from(data, 'utf-8'))
180180
.digest()
181181
const sign = signTerm.toString('base64')
182+
const amzDate = new Date().toISOString().replace(/[:-]|\.\d{3}/g, '')
182183

183184
return {
184-
'Authorization': this.token,
185+
'Authorization': `Credential=${this.token}, Signature=${sign}, SignedHeaders=content-type;host;x-amz-date, SignedHeaders=content-type;host;x-amz-date`,
185186
'sign': sign,
186187
'nonce': nonce,
187188
't': t,
188189
'Content-Type': 'application/json',
190+
'X-Amz-Date': amzDate,
189191
}
190192
}
191193

0 commit comments

Comments
 (0)