北京邮电大学统一身份认证。
# pnpm
pnpm dlx jsr add @byrdocs/bupt-auth
# bun
bunx jsr add @byrdocs/bupt-authimport { login } from "@byrdocs/bupt-auth";
login(bupt_id, bupt_pass, {
onCaptcha: async (url, cookie) => {
console.log("需要验证码");
console.log("\t验证码 URL:", url);
console.log("\tCookie:", cookie);
return await input("请输入验证码: ");
}
}).then((res) => {
console.log("登录成功!");
console.log("用户名:", res.user_name);
console.log("姓名:", res.real_name);
console.log("角色:", res.roles.map(r => r.roleName).join(", "));
}).catch((err) => {
console.error("登录失败:", err);
});如果只需要学号、姓名、身份类型,不需要 ucloud 的 token 和角色信息,可以传入
cas: true,此时直接通过统一认证的 serviceValidate 校验获取信息。
返回类型会根据 cas 选项自动推导为 CASUserInfo。
import { login } from "@byrdocs/bupt-auth";
const res = await login(bupt_id, bupt_pass, { cas: true });
console.log("学号:", res.user_name); // 2021xxxxxx
console.log("姓名:", res.real_name); // 张三
console.log("身份:", res.type); // 例如 L0103
console.log("全部属性:", res.attributes);