飞书二维码联合登录,对接起来太简单了

1.先创建一个飞书应用

2.引入 JS 库


3. 自定义 js

 const goto = "https://passport.feishu.cn/suite/passport/oauth/authorize?client_id=cli_&redirect_uri=httindex&response_type=code&state=STATE";
    const QRLoginObj = QRLogin({
        id: "login_container",
        goto: goto,
        width: "400",
        height: "400",
        style: "background-color: #eee;"
    });
    const handleMessage = function (event) {
        try {
            if (QRLoginObj.matchOrigin(event.origin) && QRLoginObj.matchData(event.data)) {
                const loginTmpCode = event.data.tmp_code;
                console.log(loginTmpCode);
                //window.location.href = `${goto}&tmp_code=${loginTmpCode}`;
            }
        } catch (error) {
            console.error('处理消息时发生错误:', error);
        }
    };
    if (window.addEventListener) {
        window.addEventListener('message', handleMessage, false);
    } else if (window.attachEvent) {
        window.attachEvent('onmessage', handleMessage);
    }

4.html代码


    

请使用手机扫描二维码登录

你可能感兴趣的:(飞书)