Loading...
Loading...
Compare original and translation side by side
@cloudbase/js-sdkskills/web-auth-skillskills/auth-http-api-skill@cloudbase/js-sdkskills/web-auth-skillskills/auth-http-api-skillenv@cloudbase/node-sdkimport tcb from "@cloudbase/node-sdk";
const app = tcb.init({ env: "your-env-id" });
const auth = app.auth();getUserInfogetEndUserInfoqueryUserInfocreateTicketgetClientIPauth.*env@cloudbase/node-sdkimport tcb from "@cloudbase/node-sdk";
const app = tcb.init({ env: "your-env-id" });
const auth = app.auth();getUserInfogetEndUserInfoqueryUserInfocreateTicketgetClientIPauth.*auth.getUserInfo()uidopenIdcustomUserIdauth.getEndUserInfo(uid)uidauth.queryUserInfo({ platform, platformId, uid? })auth.createTicket(customUserId, options)auth.getClientIP()auth.getUserInfo()uidopenIdcustomUserIduidauth.getEndUserInfo(uid)auth.queryUserInfo({ platform, platformId, uid? })auth.createTicket(customUserId, options)auth.getClientIP()authgetUserInfo(): IGetUserInfoResult{ openId, appId, uid, customUserId }getEndUserInfo(uid?: string, opts?: ICustomReqOpts): Promise<{ userInfo: EndUserInfo; requestId?: string }>uiduidqueryUserInfo(query: IUserInfoQuery, opts?: ICustomReqOpts): Promise<{ userInfo: EndUserInfo; requestId?: string }>platformplatformIduidgetClientIP(): stringcreateTicket(customUserId: string, options?: ICreateTicketOpts): stringcustomUserIdEndUserInfoIUserInfoQueryICreateTicketOptsauthgetUserInfo(): IGetUserInfoResult{ openId, appId, uid, customUserId }getEndUserInfo(uid?: string, opts?: ICustomReqOpts): Promise<{ userInfo: EndUserInfo; requestId?: string }>uiduidqueryUserInfo(query: IUserInfoQuery, opts?: ICustomReqOpts): Promise<{ userInfo: EndUserInfo; requestId?: string }>platformplatformIduidgetClientIP(): stringcreateTicket(customUserId: string, options?: ICreateTicketOpts): stringcustomUserIdEndUserInfoIUserInfoQueryICreateTicketOptsimport tcb from "@cloudbase/node-sdk";
const app = tcb.init({ env: "your-env-id" });
const auth = app.auth();
exports.main = async (event, context) => {
// Your logic here
};envimport tcb from "@cloudbase/node-sdk";
const app = tcb.init({ env: "your-env-id" });
const auth = app.auth();
exports.main = async (event, context) => {
// 你的业务逻辑
};envimport tcb from "@cloudbase/node-sdk";
const app = tcb.init({ env: "your-env-id" });
const auth = app.auth();
exports.main = async (event, context) => {
const { openId, appId, uid, customUserId } = auth.getUserInfo();
console.log("Caller identity", { openId, appId, uid, customUserId });
// Use uid / customUserId for authorization decisions
// e.g. check roles, permissions, or data ownership
};uidcustomUserIdopenIdappIdimport tcb from "@cloudbase/node-sdk";
const app = tcb.init({ env: "your-env-id" });
const auth = app.auth();
exports.main = async (event, context) => {
const { openId, appId, uid, customUserId } = auth.getUserInfo();
console.log("调用者身份", { openId, appId, uid, customUserId });
// 使用uid/customUserId进行授权决策
// 例如检查角色、权限或数据归属
};uidcustomUserIdopenIdappIduidimport tcb from "@cloudbase/node-sdk";
const app = tcb.init({ env: "your-env-id" });
const auth = app.auth();
exports.main = async (event, context) => {
const uid = "user-uid";
try {
const { userInfo } = await auth.getEndUserInfo(uid);
console.log("User profile", userInfo);
} catch (error) {
console.error("Failed to get end user info", error.message);
}
};getEndUserInfouidimport tcb from "@cloudbase/node-sdk";
const app = tcb.init({ env: "your-env-id" });
const auth = app.auth();
exports.main = async (event, context) => {
const uid = "user-uid";
try {
const { userInfo } = await auth.getEndUserInfo(uid);
console.log("用户资料", userInfo);
} catch (error) {
console.error("获取终端用户资料失败", error.message);
}
};getEndUserInfouidimport tcb from "@cloudbase/node-sdk";
const app = tcb.init({ env: "your-env-id" });
const auth = app.auth();
exports.main = async (event, context) => {
try {
const { userInfo } = await auth.getEndUserInfo();
console.log("Current caller profile", userInfo);
} catch (error) {
console.error("Failed to get current caller profile", error.message);
}
};uidimport tcb from "@cloudbase/node-sdk";
const app = tcb.init({ env: "your-env-id" });
const auth = app.auth();
exports.main = async (event, context) => {
try {
const { userInfo } = await auth.getEndUserInfo();
console.log("当前调用者资料", userInfo);
} catch (error) {
console.error("获取当前调用者资料失败", error.message);
}
};import tcb from "@cloudbase/node-sdk";
const app = tcb.init({ env: "your-env-id" });
const auth = app.auth();
exports.main = async (event, context) => {
try {
// Find by phone number
const { userInfo: byPhone } = await auth.queryUserInfo({
platform: "PHONE",
platformId: "+86 13800000000",
});
// Find by email
const { userInfo: byEmail } = await auth.queryUserInfo({
platform: "EMAIL",
platformId: "test@example.com",
});
// Find by customUserId
const { userInfo: byCustomId } = await auth.queryUserInfo({
platform: "CUSTOM",
platformId: "your-customUserId",
});
console.log({ byPhone, byEmail, byCustomId });
} catch (error) {
console.error("Failed to query user info", error.message);
}
};uidqueryUserInfoplatformId+86import tcb from "@cloudbase/node-sdk";
const app = tcb.init({ env: "your-env-id" });
const auth = app.auth();
exports.main = async (event, context) => {
try {
// 通过手机号查找
const { userInfo: byPhone } = await auth.queryUserInfo({
platform: "PHONE",
platformId: "+86 13800000000",
});
// 通过邮箱查找
const { userInfo: byEmail } = await auth.queryUserInfo({
platform: "EMAIL",
platformId: "test@example.com",
});
// 通过customUserId查找
const { userInfo: byCustomId } = await auth.queryUserInfo({
platform: "CUSTOM",
platformId: "your-customUserId",
});
console.log({ byPhone, byEmail, byCustomId });
} catch (error) {
console.error("查询用户资料失败", error.message);
}
};uiduidqueryUserInfoplatformId+86import tcb from "@cloudbase/node-sdk";
const app = tcb.init({ env: "your-env-id" });
const auth = app.auth();
exports.main = async (event, context) => {
const ip = auth.getClientIP();
console.log("Caller IP", ip);
// e.g. block or flag suspicious IPs
};import tcb from "@cloudbase/node-sdk";
const app = tcb.init({ env: "your-env-id" });
const auth = app.auth();
exports.main = async (event, context) => {
const ip = auth.getClientIP();
console.log("调用者IP", ip);
// 例如拦截或标记可疑IP
};import tcb from "@cloudbase/node-sdk";
import path from "node:path";
const app = tcb.init({
env: "your-env-id",
credentials: require(path.join(__dirname, "tcb_custom_login.json")),
});
const auth = app.auth();tcb_custom_login.jsonimport tcb from "@cloudbase/node-sdk";
import path from "node:path";
const app = tcb.init({
env: "your-env-id",
credentials: require(path.join(__dirname, "tcb_custom_login.json")),
});
const auth = app.auth();tcb_custom_login.jsonimport tcb from "@cloudbase/node-sdk";
const app = tcb.init({
env: "your-env-id",
credentials: require("/secure/path/to/tcb_custom_login.json"),
});
const auth = app.auth();
exports.main = async (event, context) => {
const customUserId = "your-customUserId";
const ticket = auth.createTicket(customUserId, {
refresh: 3600 * 1000, // access_token refresh interval (ms)
expire: 24 * 3600 * 1000, // ticket expiration time (ms)
});
// Return the ticket to the trusted client (e.g. via HTTP response)
return { ticket };
};customUserId_-#@(){}[]:.,<>+#~customUserIdcustomUserIdimport tcb from "@cloudbase/node-sdk";
const app = tcb.init({
env: "your-env-id",
credentials: require("/secure/path/to/tcb_custom_login.json"),
});
const auth = app.auth();
exports.main = async (event, context) => {
const customUserId = "your-customUserId";
const ticket = auth.createTicket(customUserId, {
refresh: 3600 * 1000, // access_token刷新间隔(毫秒)
expire: 24 * 3600 * 1000, // 票据过期时间(毫秒)
});
// 将票据返回给受信任的客户端(例如通过HTTP响应)
return { ticket };
};customUserId_-#@(){}[]:.,<>+#~customUserIdcustomUserId@cloudbase/js-sdkticketauth.setCustomSignFunc(async () => ticketFromBackend)auth.signInWithCustomTicket()@cloudbase/js-sdkticketauth.setCustomSignFunc(async () => ticketFromBackend)auth.signInWithCustomTicket()uidcustomUserIduidgetEndUserInfoqueryUserInfoauth.*try/catcherror.messageerror.codetcb_custom_login.jsonuidcustomUserIduidgetEndUserInfoqueryUserInfoauth.*try/catcherror.messageerror.codetcb_custom_login.jsonuid@cloudbase/js-sdkuid@cloudbase/js-sdk