用户、会话与权限边界
区分运营账号、C端用户、服务身份和业务资源归属。
谁在执行操作
运营账号由后台用户/角色管理;C端用户由Auth项目与身份目录管理;服务身份表示调用的服务。三者不能用同一个令牌或权限集合互相替代。
读取当前 C 端用户
前台通过AuthSDK.getUser读取经过平台验证的资料,不请求后台用户列表。服务端按请求创建客户端,业务仍检查用户能访问哪些自己的数据。
TypeScript
import type { Shell } from '@mosaic-base/shell';
import type { ArticleSDK, SiteSDK, I18nSDK } from '@mosaic-base/client-sdk';
import type { AuthClient, ServerAuthClient } from '@mosaic-base/auth-sdk';
// Declare once in your application's type contract, never import SDK implementations.
declare module '@mosaic-base/shell/contracts' {
interface SdkRegistry {
'site.config': Pick<SiteSDK, 'getConfig'>;
'content.articles': Pick<ArticleSDK, 'list' | 'getBySlug' | 'getPreview' | 'search'>;
'i18n.messages': Pick<I18nSDK, 'load' | 't' | 'clearCache' | 'refresh'>;
'auth.client': AuthClient | ServerAuthClient;
}
}
export async function readRequestUser(shell: Shell) {
const auth = await shell.getSdk('auth.client');
return auth.getUser();
}
// Create the request Shell with only auth.client's Cookie policy and realmKey option.
// Dispose in the request owner. Node SDK is read-only; renewal is a writable boundary.