feat: update OAuth2 callback functions to include access token handling for DingTalk and Lark
parent
79fbc52741
commit
087f707002
|
|
@ -138,11 +138,12 @@ const getDingCallback: (code: string, accessToken: string, loading?: Ref<boolean
|
||||||
return get('auth/dingtalk', {code, accessToken: accessToken}, loading)
|
return get('auth/dingtalk', {code, accessToken: accessToken}, loading)
|
||||||
}
|
}
|
||||||
|
|
||||||
const getDingOauth2Callback: (code: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
|
const getDingOauth2Callback: (code: string, accessToken: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
|
||||||
code,
|
code,
|
||||||
|
accessToken,
|
||||||
loading,
|
loading,
|
||||||
) => {
|
) => {
|
||||||
return get('auth/dingtalk/oauth2', {code}, loading)
|
return get('auth/dingtalk/oauth2', {code, accessToken: accessToken}, loading)
|
||||||
}
|
}
|
||||||
|
|
||||||
const getWecomCallback: (code: string, accessToken: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
|
const getWecomCallback: (code: string, accessToken: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
|
||||||
|
|
@ -152,11 +153,12 @@ const getWecomCallback: (code: string, accessToken: string, loading?: Ref<boolea
|
||||||
) => {
|
) => {
|
||||||
return get('auth/wecom', {code, accessToken: accessToken}, loading)
|
return get('auth/wecom', {code, accessToken: accessToken}, loading)
|
||||||
}
|
}
|
||||||
const getLarkCallback: (code: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
|
const getLarkCallback: (code: string, accessToken: string, loading?: Ref<boolean>) => Promise<Result<any>> = (
|
||||||
code,
|
code,
|
||||||
|
accessToken,
|
||||||
loading,
|
loading,
|
||||||
) => {
|
) => {
|
||||||
return get('auth/lark/oauth2', {code}, loading)
|
return get('auth/lark/oauth2', {code, accessToken: accessToken}, loading)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import { defineStore } from 'pinia'
|
import {defineStore} from 'pinia'
|
||||||
import ChatAPI from '@/api/chat/chat'
|
import ChatAPI from '@/api/chat/chat'
|
||||||
import type { ChatProfile, ChatUserProfile } from '@/api/type/chat'
|
import type {ChatProfile, ChatUserProfile} from '@/api/type/chat'
|
||||||
import type { LoginRequest } from '@/api/type/user'
|
import type {LoginRequest} from '@/api/type/user'
|
||||||
import type { Ref } from 'vue'
|
import type {Ref} from 'vue'
|
||||||
import { getBrowserLang } from '@/locales/index'
|
import {getBrowserLang} from '@/locales/index'
|
||||||
|
|
||||||
interface ChatUser {
|
interface ChatUser {
|
||||||
// 用户id
|
// 用户id
|
||||||
|
|
@ -121,8 +121,8 @@ const useChatUserStore = defineStore('chat-user', {
|
||||||
return this.token
|
return this.token
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
async dingOauth2Callback(code: string) {
|
async dingOauth2Callback(code: string, accessToken: string) {
|
||||||
return ChatAPI.getDingOauth2Callback(code).then((ok) => {
|
return ChatAPI.getDingOauth2Callback(code, accessToken).then((ok) => {
|
||||||
this.setToken(ok.data.token)
|
this.setToken(ok.data.token)
|
||||||
return this.token
|
return this.token
|
||||||
})
|
})
|
||||||
|
|
@ -133,8 +133,8 @@ const useChatUserStore = defineStore('chat-user', {
|
||||||
return this.token
|
return this.token
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
async larkCallback(code: string) {
|
async larkCallback(code: string, accessToken: string) {
|
||||||
return ChatAPI.getLarkCallback(code).then((ok) => {
|
return ChatAPI.getLarkCallback(code, accessToken).then((ok) => {
|
||||||
this.setToken(ok.data.token)
|
this.setToken(ok.data.token)
|
||||||
return this.token
|
return this.token
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -179,8 +179,9 @@ import {useI18n} from 'vue-i18n'
|
||||||
import QrCodeTab from '@/views/chat/user-login/scanCompinents/QrCodeTab.vue'
|
import QrCodeTab from '@/views/chat/user-login/scanCompinents/QrCodeTab.vue'
|
||||||
import {MsgConfirm, MsgError} from '@/utils/message.ts'
|
import {MsgConfirm, MsgError} from '@/utils/message.ts'
|
||||||
import PasswordAuth from '@/views/chat/auth/component/password.vue'
|
import PasswordAuth from '@/views/chat/auth/component/password.vue'
|
||||||
import {isAppIcon} from '@/utils/common'
|
import {isAppIcon, loadScript} from '@/utils/common'
|
||||||
import forge from "node-forge";
|
import forge from "node-forge";
|
||||||
|
import * as dd from "dingtalk-jsapi";
|
||||||
|
|
||||||
useResize()
|
useResize()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
@ -423,6 +424,82 @@ onBeforeMount(() => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
declare const window: any
|
||||||
|
onMounted(() => {
|
||||||
|
const route = useRoute()
|
||||||
|
const currentUrl = ref(route.fullPath)
|
||||||
|
const params = new URLSearchParams(currentUrl.value.split('?')[1])
|
||||||
|
const client = params.get('client')
|
||||||
|
|
||||||
|
const handleDingTalk = () => {
|
||||||
|
const code = params.get('corpId')
|
||||||
|
if (code) {
|
||||||
|
dd.runtime.permission.requestAuthCode({corpId: code}).then((res) => {
|
||||||
|
console.log('DingTalk client request success:', res)
|
||||||
|
chatUser.dingOauth2Callback(res.code, accessToken).then(() => {
|
||||||
|
router.push({name: 'home'})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleLark = () => {
|
||||||
|
const appId = params.get('appId')
|
||||||
|
const callRequestAuthCode = () => {
|
||||||
|
window.tt?.requestAuthCode({
|
||||||
|
appId: appId,
|
||||||
|
success: (res: any) => {
|
||||||
|
chatUser.larkCallback(res.code, accessToken).then(() => {
|
||||||
|
router.push({name: 'home'})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
fail: (error: any) => {
|
||||||
|
MsgError(error)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
loadScript('https://lf-scm-cn.feishucdn.com/lark/op/h5-js-sdk-1.5.35.js', {
|
||||||
|
jsId: 'lark-sdk',
|
||||||
|
forceReload: true,
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
if (window.tt) {
|
||||||
|
window.tt.requestAccess({
|
||||||
|
appID: appId,
|
||||||
|
scopeList: [],
|
||||||
|
success: (res: any) => {
|
||||||
|
chatUser.larkCallback(res.code, accessToken).then(() => {
|
||||||
|
router.push({name: 'home'})
|
||||||
|
})
|
||||||
|
},
|
||||||
|
fail: (error: any) => {
|
||||||
|
const {errno} = error
|
||||||
|
if (errno === 103) {
|
||||||
|
callRequestAuthCode()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
callRequestAuthCode()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error('SDK 加载失败:', error)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (client) {
|
||||||
|
case 'dingtalk':
|
||||||
|
handleDingTalk()
|
||||||
|
break
|
||||||
|
case 'lark':
|
||||||
|
handleLark()
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
break
|
||||||
|
}
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.user-login {
|
.user-login {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue