Kiota で Basic 認証したい
kiota の typescript クライアントで basic 認証したい場合は以下の様にすると良い。
const userName = process.env.MY_USERNAME;
const password = process.env.MY_PASSWORD;
if (!userName || !password) {
throw new Error("Environment variables MY_USERNAME and MY_PASSWORD must be set");
}
const headerValue = "Basic " + Buffer.from(`${userName}:${password}`).toString("base64");
const authProvider = new ApiKeyAuthenticationProvider(headerValue, "Authorization", ApiKeyLocation.Header);
const adapter = new FetchRequestAdapter(authProvider);
adapter.baseUrl = "リクエスト先の URL をここに指定する";
const client = createMyGreatClient(adapter);
const got = await client.things.get();
Published: 2024-12-12(Wed) 07:32