飞书二维码登录注意点

1.前端SDK版本

bash 复制代码
  第一个手机端授权后、网页端还需要点击一次授权 授权后会跳转到redirect_uri页面,连接会携带code
  <script src="https://lf-package-cn.feishucdn.com/obj/feishu-static/lark/passport/qrcode/LarkSSOSDKWebQRCode-1.0.3.js"></script>
  只需要在手机上点击授权
  <script src="https://sf3-cn.feishucdn.com/obj/static/lark/passport/qrcode/LarkSSOSDKWebQRCode-1.0.1.js"></script> 

2. 流程是生成二维码,redirect_uri地址填写一个页面用来接收授权码,传递授权码给后端、后端再进行鉴权 返回token,redirect_uri 地址需要和后台飞书接口的redirect_uri地址保持一致

bash 复制代码
// 初始化扫码登录
    initQRCodeLogin() {
      console.log(window.QRLogin)
      if (window.QRLogin) {
        // 清空之前的二维码容器内容,防止生成多个二维码
        const loginContainer = document.getElementById("login_container");
        loginContainer.innerHTML = "";
        // 调起扫码
        var goto = `https://passport.feishu.cn/suite/passport/oauth/authorize?client_id=cli_a7b076f0a172d00c&redirect_uri=http://xxxxx/login&response_type=code&state=code`;

		// redirect_uri

        const QRLoginObj = QRLogin({
          id: "login_container",
          goto: goto,
          width: "280",
          height: "280",
          style: "width:280px;height:280px;border:none"
        });

        var handleMessage = function (event) {
        var origin = event.origin;
        // 使用 matchOrigin 方法来判断 message 是否来自飞书页面
        if (QRLoginObj.matchOrigin(origin)) {
          var loginTmpCode = event.data;
          // 在授权页面地址上拼接上参数 tmp_code,并跳转
          window.location.href = `${goto}&tmp_code=${loginTmpCode}`;
          console.log(loginTmpCode);
        }
      };
      if (typeof window.addEventListener != "undefined") {
        window.addEventListener("message", handleMessage, false);
      } else if (typeof window.attachEvent != "undefined") {
        window.attachEvent("onmessage", handleMessage);
      }
      }
    },

3. 需要注意后台飞书接口"获取用户信息"版本不一样 需要的token 也不一样,

bash 复制代码
// 需要的是 USER_ACCESS_TOKEN
https://open.feishu.cn/open-apis/authen/v1/user_info
// 获取 USER_ACCESS_TOKEN 接口
https://open.feishu.cn/open-apis/authen/v2/oauth/token

注意区分 tenant_access_token 和 USER_ACCESS_TOKEN
接口版本不一样 需要的token也会不一样
相关推荐
大尚来也2 小时前
PHP 反序列化漏洞深度解析:从原理利用到 allowed_classes 防御实战
android·开发语言·php
雕刻刀2 小时前
ERROR: Failed to build ‘natten‘ when getting requirements to build wheel
开发语言·python
qq_416018722 小时前
高性能密码学库
开发语言·c++·算法
小碗羊肉2 小时前
【从零开始学Java | 第十八篇】BigInteger
java·开发语言·新手入门
宵时待雨2 小时前
C++笔记归纳14:AVL树
开发语言·数据结构·c++·笔记·算法
执笔画流年呀2 小时前
PriorityQueue(堆)续集
java·开发语言
山川行2 小时前
关于《项目C语言》专栏的总结
c语言·开发语言·数据结构·vscode·python·算法·visual studio code
呜喵王阿尔萨斯2 小时前
C and C++ code
c语言·开发语言·c++
左左右右左右摇晃2 小时前
JDK 1.7 ConcurrentHashMap——分段锁
java·开发语言·笔记
xcLeigh2 小时前
Python入门:Python3基础练习题详解,从入门到熟练的 25 个实例(六)
开发语言·python·教程·python3·练习题