diff --git a/README.md b/README.md index 7de3f97..f62f1f3 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ const client = new Client({ endpoint: "your-instance.cn-hangzhou.ots.aliyuncs.com", accessKeyID: "YOUR_ACCESS_KEY_ID", accessKeySecret: "YOUR_ACCESS_KEY_SECRET", + stsToken: "YOUR_STS_TOKEN", // optional instanceName: "your-instance", }); diff --git a/cspell.config.yml b/cspell.config.yml index 0445c65..35cf4c0 100644 --- a/cspell.config.yml +++ b/cspell.config.yml @@ -9,3 +9,4 @@ words: - aliyun - plainbuffer - alicloud + - ststoken diff --git a/src/const.ts b/src/const.ts index 1040747..0b7276f 100644 --- a/src/const.ts +++ b/src/const.ts @@ -9,6 +9,7 @@ export const H_OTS_API_VERSION = "x-ots-apiversion"; export const H_OTS_CONTENT_MD5 = "x-ots-contentmd5"; export const H_OTS_DATE = "x-ots-date"; export const H_OTS_INSTANCE_NAME = "x-ots-instancename"; +export const H_OTS_STS_TOKEN = "x-ots-ststoken"; export const H_OTS_SIGNATURE = "x-ots-signature"; // OTS API Name diff --git a/src/request.ts b/src/request.ts index b34731d..8c84c32 100644 --- a/src/request.ts +++ b/src/request.ts @@ -1,7 +1,7 @@ import type { ClientConfig, OTSApiName, RequestOptions } from "./type"; import { createHash, createHmac } from "node:crypto"; import ky from "ky"; -import { API_VERSION, H_OTS_ACCESS_KEY_ID, H_OTS_API_VERSION, H_OTS_CONTENT_MD5, H_OTS_DATE, H_OTS_INSTANCE_NAME, H_OTS_PREFIX, H_OTS_SIGNATURE, USER_AGENT } from "./const"; +import { API_VERSION, H_OTS_ACCESS_KEY_ID, H_OTS_API_VERSION, H_OTS_CONTENT_MD5, H_OTS_DATE, H_OTS_INSTANCE_NAME, H_OTS_PREFIX, H_OTS_SIGNATURE, H_OTS_STS_TOKEN, USER_AGENT } from "./const"; const DEFAULT_REQUEST_OPTIONS = { retry: 2, @@ -21,6 +21,10 @@ export class Request { [H_OTS_INSTANCE_NAME]: this.config.instanceName, }, options.headers); + if (this.config.stsToken) { + headers[H_OTS_STS_TOKEN] = this.config.stsToken; + } + headers[H_OTS_SIGNATURE] = this.sign(options.apiName, headers); headers["User-Agent"] = USER_AGENT; diff --git a/src/type.ts b/src/type.ts index 24f4d55..5f7d562 100644 --- a/src/type.ts +++ b/src/type.ts @@ -4,6 +4,7 @@ export interface ClientConfig { endpoint: string; accessKeyID: string; accessKeySecret: string; + stsToken?: string; instanceName: string; }