飛書掃碼登錄第三方應用系統


引入<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);
}
 
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM