引入<script src="https://sf3-cn.feishucdn.com/obj/static/lark/passport/qrcode/LarkSSOSDKWebQRCode-1.0.1.js"></script>
var QRLoginObj = QRLogin({
id:"login_container",
goto: "https://passport.feishu.cn/suite/passport/oauth/authorize?client_id=CLIENT_ID&redirect_uri=REDIRECT_URI&response_type=code&state=STATE",
width: "500",
height: "500",
});
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}`;//注意此處loginTmpCode不是code,跳轉之后的鏈接上才會返回code
}
};
if (typeof window.addEventListener != 'undefined') {
window.addEventListener('message', handleMessage, false);}
else if (typeof window.attachEvent != 'undefined') {
window.attachEvent('onmessage', handleMessage);
}