zoukankan      html  css  js  c++  java
  • cube.js 认证以及授权

    cube.js 的认证以及授权是基于security context 的,以下是参考图

    简单说明

    cube.js 是基于jwt token 处理的,同时关于用户的信息是在存储在u 中的,同时可以通过USER_CONTEXT 访问
    同时authInfo 变量可以在多租户中方便的使用

    • 参考u 信息
     
    {
      "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`,
        },
      },
    });
    • 自定义auth
    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

  • 相关阅读:
    编程之美--2.13
    编程之美--2.17
    编程之美--3.8
    编程之美--3.7
    面试金典--9.3
    面试金典--9.2
    面试金典--9.1
    jq插件
    laravel controller
    laravel 登录验证
  • 原文地址:https://www.cnblogs.com/rongfengliang/p/14221100.html
Copyright © 2011-2022 走看看