43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
const {
|
|
unstable_v2_authenticate: authenticate,
|
|
} = require("@tencent-ai/agent-sdk");
|
|
|
|
function redactUserinfo(userinfo) {
|
|
if (!userinfo || typeof userinfo !== "object") return userinfo;
|
|
const copy = { ...userinfo };
|
|
if ("token" in copy) copy.token = "<redacted>";
|
|
return copy;
|
|
}
|
|
|
|
async function main() {
|
|
const environment = process.env.CODEBUDDY_AUTH_ENV || "internal";
|
|
const endpoint = process.env.CODEBUDDY_AUTH_ENDPOINT || undefined;
|
|
const methodId = process.env.CODEBUDDY_AUTH_METHOD || environment;
|
|
|
|
const result = await authenticate({
|
|
environment,
|
|
endpoint,
|
|
methodId,
|
|
timeout: Number(process.env.CODEBUDDY_AUTH_TIMEOUT_MS || 300000),
|
|
env: process.env,
|
|
onAuthUrl: async (authState) => {
|
|
console.log("AUTH_URL_BEGIN");
|
|
console.log(authState.authUrl);
|
|
console.log("AUTH_URL_END");
|
|
console.error("Open the URL above in your browser and finish login.");
|
|
},
|
|
});
|
|
|
|
console.log(JSON.stringify({
|
|
ok: true,
|
|
environment,
|
|
endpoint,
|
|
userinfo: redactUserinfo(result.userinfo),
|
|
}, null, 2));
|
|
}
|
|
|
|
main().catch((error) => {
|
|
console.error(error && error.stack ? error.stack : String(error));
|
|
process.exit(1);
|
|
});
|