54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
// 飞书脚本
|
|
export function qr_load() {
|
|
return new Promise<void>((resolve, reject) => {
|
|
const script = document.createElement("script")
|
|
script.type = "text/javascript"
|
|
script.src =
|
|
"https://sf3-cn.feishucdn.com/obj/feishu-static/lark/passport/qrcode/LarkSSOSDKWebQRCode-1.0.2.js"
|
|
script.onerror = reject
|
|
script.onload = () => {
|
|
resolve()
|
|
}
|
|
document.head.appendChild(script)
|
|
})
|
|
}
|
|
|
|
export async function qr_login(
|
|
appId: string,
|
|
redirect_url: string,
|
|
state: string
|
|
) {
|
|
const gotoUrl = `https://passport.feishu.cn/suite/passport/oauth/authorize?client_id=${appId}&redirect_uri=${encodeURIComponent(
|
|
redirect_url
|
|
)}&response_type=code&state=${encodeURIComponent(state)}`
|
|
const QRLogin = (<any>window).QRLogin
|
|
const QRLoginObj = QRLogin({
|
|
// eslint-disable-next-line prettier/prettier
|
|
id: "login_container",
|
|
goto: gotoUrl,
|
|
style: `width: 270px;height: 270px;border: 0;border-radius:12px;background-color: #E4F2FF;
|
|
background-image:
|
|
radial-gradient(at 47% 33%, hsl(212.37, 72%, 59%) 0, transparent 59%),
|
|
radial-gradient(at 82% 65%, hsl(198.00, 100%, 50%) 0, transparent 55%);`,
|
|
})
|
|
const handleMessage = function (event: any) {
|
|
const origin = event.origin
|
|
if (
|
|
QRLoginObj.matchOrigin(origin) &&
|
|
window.location.href.indexOf("login") > -1
|
|
) {
|
|
const loginTmpCode = event.data
|
|
window.location.href = `${gotoUrl}&tmp_code=${loginTmpCode}`
|
|
}
|
|
}
|
|
if (typeof window.addEventListener !== "undefined") {
|
|
window.addEventListener("message", handleMessage, false)
|
|
} else if (typeof (<any>window).attachEvent !== "undefined") {
|
|
// eslint-disable-next-line prettier/prettier
|
|
;(<any>window).attachEvent("onmessage", handleMessage)
|
|
}
|
|
}
|
|
|
|
export const APP_ID = "cli_a9a902d6c3b95ceb"
|
|
export const APP_SECRECT = "zVbsYlJa3nzK5DwabshHFgcWQdnp4HLu"
|