标签:pre nes 说明 ring code javascrip await 及授权 prope
cube.js 的认证以及授权是基于security context
的,以下是参考图
cube.js 是基于jwt token 处理的,同时关于用户的信息是在存储在u 中的,同时可以通过USER_CONTEXT
访问
同时authInfo 变量可以在多租户中方便的使用
{
"sub": "1234567890",
"iat": 1516239022,
"u": {
"user_id": 131
}
}
cube(`Orders`, {
sql: `SELECT * FROM public.orders WHERE ${USER_CONTEXT.user_id.filter(‘user_id‘)}`,
?
measures: {
count: {
type: `count`,
},
},
});
const jwt = require(‘jsonwebtoken‘);
const fetch = require(‘node-fetch‘);
?
module.exports = {
checkAuth: async (req, auth) => {
// Replace `region` and `userPoolId` with your own
const jwks = await fetch(
‘https://cognito-idp.{region}.amazonaws.com/{userPoolId}/.well-known/jwks.json‘
).then((r) => r.json());
const decoded = jwt.decode(auth, { complete: true });
const jwk = _.find(jwks.keys, (x) => x.kid === decoded.header.kid);
const pem = jwkToPem(jwk);
req.authInfo = jwt.verify(auth, pem);
},
};
https://cube.dev/docs/security
https://cube.dev/docs/config#options-reference-check-auth
标签:pre nes 说明 ring code javascrip await 及授权 prope
原文地址:https://www.cnblogs.com/rongfengliang/p/14221100.html