Skip to content

Commit 9eab6bc

Browse files
feat(X-Pack): Add Larksuite Support
1 parent a1c6f0d commit 9eab6bc

File tree

5 files changed

+114
-3
lines changed

5 files changed

+114
-3
lines changed

frontend/src/views/login/xpack/Handler.vue

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,39 @@ const wecomLogin = () => {
445445
}, 1500)
446446
})
447447
}
448+
const larksuiteLogin = () => {
449+
const urlParams = getUrlParams()
450+
urlParams['redirect_uri'] = encodeURIComponent(getSQLBotAddr())
451+
request
452+
.post('/system/platform/sso/9', urlParams)
453+
.then((res: any) => {
454+
const token = res.access_token
455+
// const platform_info = res.platform_info
456+
if (token && isPlatformClient()) {
457+
wsCache.set('sqlbot-platform-client', true)
458+
}
459+
userStore.setToken(token)
460+
userStore.setExp(res.exp)
461+
userStore.setTime(Date.now())
462+
userStore.setPlatformInfo({
463+
flag: 'larksuite',
464+
// data: platform_info ? JSON.stringify(platform_info) : '',
465+
origin: 9,
466+
})
467+
const queryRedirectPath = getCurLocation()
468+
router.push({ path: queryRedirectPath })
469+
})
470+
.catch((e: any) => {
471+
userStore.setToken('')
472+
setTimeout(() => {
473+
// logoutHandler(true, true)
474+
platformLoginMsg.value = e?.message || e
475+
setTimeout(() => {
476+
window.location.href = getSQLBotAddr() + window.location.hash
477+
}, 2000)
478+
}, 1500)
479+
})
480+
}
448481
const larkLogin = () => {
449482
const urlParams = getUrlParams()
450483
urlParams['redirect_uri'] = encodeURIComponent(getSQLBotAddr())
@@ -689,6 +722,8 @@ onMounted(() => {
689722
wecomLogin()
690723
} else if (state?.includes('dingtalk')) {
691724
dingtalkLogin()
725+
} else if (state?.includes('larksuite')) {
726+
larksuiteLogin()
692727
} else if (state?.includes('lark')) {
693728
larkLogin()
694729
} else {
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<template>
2+
<div id="de2-larksuite-qr" :class="{ 'de2-larksuite-qr': !isBind }" />
3+
</template>
4+
5+
<script lang="ts" setup>
6+
import { loadScript } from '@/utils/RemoteJs'
7+
import { propTypes } from '@/utils/propTypes'
8+
import { queryClientInfo } from './platformUtils'
9+
import { getSQLBotAddr } from '@/utils/utils'
10+
import { ref } from 'vue'
11+
interface LarksuiteQrInfo {
12+
client_id?: string
13+
state?: string
14+
redirect_uri?: string
15+
}
16+
const origin = ref(9)
17+
const props = defineProps({
18+
isBind: propTypes.bool.def(false),
19+
})
20+
const remoteJsUrl =
21+
'https://lf-package-us.larksuitecdn.com/obj/lark-static-us/lark/passport/qrcode/LarkSSOSDKWebQRCode-1.0.3.js'
22+
const jsId = 'de-larksuite-qr-id'
23+
const init = () => {
24+
loadScript(remoteJsUrl, jsId).then(() => {
25+
queryClientInfo(origin.value).then((res) => {
26+
const data: any = formatQrResult(res)
27+
loadQr(data.client_id, data.state, data.redirect_uri)
28+
})
29+
})
30+
}
31+
32+
const formatQrResult = (data: any): LarksuiteQrInfo => {
33+
const result = { client_id: null, state: null, redirect_uri: null } as unknown as LarksuiteQrInfo
34+
result.client_id = data.client_id
35+
result.state = 'fit2cloud-larksuite-qr'
36+
result.redirect_uri = data.redirect_uri || getSQLBotAddr()
37+
if (props.isBind) {
38+
result.state += '_de_bind'
39+
}
40+
return result
41+
}
42+
43+
const loadQr = (CLIENT_ID: string, STATE: string, REDIRECT_URI: string) => {
44+
let url = `https://passport.larksuite.com/suite/passport/oauth/authorize?client_id=${CLIENT_ID}&response_type=code&state=${STATE}&redirect_uri=${REDIRECT_URI}`
45+
// eslint-disable-next-line
46+
// @ts-ignore
47+
const QRLoginObj = window['QRLogin']({
48+
id: 'de2-larksuite-qr',
49+
goto: url,
50+
style: 'border:none;background-color:#FFFFFF;width: 266px;height: 266px;',
51+
})
52+
const handleMessage = function (event: any) {
53+
const origin = event.origin
54+
if (QRLoginObj.matchOrigin(origin) && QRLoginObj.matchData(event.data)) {
55+
const loginTmpCode = event.data.tmp_code
56+
url += '&tmp_code=' + loginTmpCode
57+
window.location.href = url
58+
}
59+
}
60+
if (typeof window.addEventListener != 'undefined') {
61+
window.addEventListener('message', handleMessage, false)
62+
// eslint-disable-next-line
63+
// @ts-ignore
64+
} else if (typeof window['attachEvent'] != 'undefined') {
65+
// eslint-disable-next-line
66+
// @ts-ignore
67+
window['attachEvent']('onmessage', handleMessage)
68+
}
69+
}
70+
init()
71+
</script>
72+
<style lang="less" scoped>
73+
.de2-larksuite-qr {
74+
margin-top: -15px;
75+
}
76+
</style>

frontend/src/views/login/xpack/QrTab.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import logo_dingtalk from '@/assets/svg/logo_dingtalk.svg'
5757
import logo_lark from '@/assets/svg/logo_lark.svg'
5858
import { ref } from 'vue'
5959
import LarkQr from './LarkQr.vue'
60-
/* import LarksuiteQr from './LarksuiteQr.vue' */
60+
import LarksuiteQr from './LarksuiteQr.vue'
6161
import DingtalkQr from './DingtalkQr.vue'
6262
import WecomQr from './WecomQr.vue'
6363
import { propTypes } from '@/utils/propTypes'

frontend/src/views/system/platform/PlatformInfo.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ const edit = () => {
142142
editor?.value.edit(data)
143143
}
144144
const validate = () => {
145-
if (info.value?.agent_id && info.value?.corpsecret) {
145+
if (info.value) {
146146
validateHandler()
147147
}
148148
}

frontend/src/views/system/platform/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const loadData = () => {
2929
item.config = JSON.parse(item.config)
3030
return item
3131
})
32-
.filter((card: any) => card.type < 9)
32+
.filter((card: any) => card.type < 10)
3333
})
3434
}
3535
onMounted(() => {

0 commit comments

Comments
 (0)