Merge pull request #2492 from DaydreamCoding/feat/dingtalk-login

feat(dingtalk): 钉钉 OAuth 登录接入 + internal_only 用户属性同步
This commit is contained in:
Wesley Liddick
2026-05-19 15:36:13 +08:00
committed by GitHub
54 changed files with 5545 additions and 365 deletions
@@ -0,0 +1,61 @@
<template>
<div class="space-y-4">
<button type="button" :disabled="disabled" class="btn btn-secondary w-full" @click="startLogin">
<svg
class="icon mr-2"
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
width="20"
height="20"
aria-hidden="true"
style="flex-shrink: 0"
>
<circle cx="12" cy="12" r="12" fill="#1677FF" />
<text
x="12"
y="17"
font-family="sans-serif"
font-size="13"
font-weight="bold"
fill="white"
text-anchor="middle"
>钉</text>
</svg>
{{ t('auth.dingtalk.signIn') }}
</button>
<div v-if="showDivider" class="flex items-center gap-3">
<div class="h-px flex-1 bg-gray-200 dark:bg-dark-700"></div>
<span class="text-xs text-gray-500 dark:text-dark-400">
{{ t('auth.oauthOrContinue') }}
</span>
<div class="h-px flex-1 bg-gray-200 dark:bg-dark-700"></div>
</div>
</div>
</template>
<script setup lang="ts">
import { useRoute } from 'vue-router'
import { useI18n } from 'vue-i18n'
import { resolveAffiliateReferralCode, storeOAuthAffiliateCode } from '@/utils/oauthAffiliate'
const props = withDefaults(defineProps<{
disabled?: boolean
affCode?: string
showDivider?: boolean
}>(), {
showDivider: true
})
const route = useRoute()
const { t } = useI18n()
function startLogin(): void {
const redirectTo = (route.query.redirect as string) || '/dashboard'
storeOAuthAffiliateCode(resolveAffiliateReferralCode(props.affCode, route.query.aff, route.query.aff_code))
const apiBase = (import.meta.env.VITE_API_BASE_URL as string | undefined) || '/api/v1'
const normalized = apiBase.replace(/\/$/, '')
const startURL = `${normalized}/auth/oauth/dingtalk/start?redirect=${encodeURIComponent(redirectTo)}`
window.location.href = startURL
}
</script>
@@ -2,6 +2,7 @@
<ProfileIdentityBindingsSection
:user="user"
:linuxdo-enabled="linuxdoEnabled"
:dingtalk-enabled="dingtalkEnabled"
:oidc-enabled="oidcEnabled"
:oidc-provider-name="oidcProviderName"
:wechat-enabled="wechatEnabled"
@@ -18,6 +19,7 @@ withDefaults(
defineProps<{
user: User | null
linuxdoEnabled?: boolean
dingtalkEnabled?: boolean
oidcEnabled?: boolean
oidcProviderName?: string
wechatEnabled?: boolean
@@ -26,6 +28,7 @@ withDefaults(
}>(),
{
linuxdoEnabled: false,
dingtalkEnabled: false,
oidcEnabled: false,
oidcProviderName: 'OIDC',
wechatEnabled: false,
@@ -217,6 +217,7 @@ const props = withDefaults(
defineProps<{
user: User | null
linuxdoEnabled?: boolean
dingtalkEnabled?: boolean
oidcEnabled?: boolean
oidcProviderName?: string
wechatEnabled?: boolean
@@ -227,6 +228,7 @@ const props = withDefaults(
}>(),
{
linuxdoEnabled: false,
dingtalkEnabled: false,
oidcEnabled: false,
oidcProviderName: 'OIDC',
wechatEnabled: false,
@@ -406,6 +408,9 @@ function isProviderEnabledForBinding(provider: BindableProvider): boolean {
if (provider === 'linuxdo') {
return props.linuxdoEnabled
}
if (provider === 'dingtalk') {
return props.dingtalkEnabled
}
if (provider === 'oidc') {
return props.oidcEnabled
}
@@ -432,6 +437,17 @@ const providerItems = computed(() => [
canUnbind: Boolean(getBindingStatus('linuxdo') && getBindingDetails('linuxdo')?.can_unbind),
details: getBindingDetails('linuxdo'),
},
{
provider: 'dingtalk' as const,
label: t('profile.authBindings.providers.dingtalk'),
bound: getBindingStatus('dingtalk'),
canBind:
!getBindingStatus('dingtalk') &&
isProviderEnabledForBinding('dingtalk') &&
(getBindingDetails('dingtalk')?.can_bind ?? true),
canUnbind: Boolean(getBindingStatus('dingtalk') && getBindingDetails('dingtalk')?.can_unbind),
details: getBindingDetails('dingtalk'),
},
{
provider: 'oidc' as const,
label: t('profile.authBindings.providers.oidc', { providerName: props.oidcProviderName }),
@@ -460,6 +476,9 @@ function providerInitial(provider: UserAuthProvider): string {
if (provider === 'linuxdo') {
return 'L'
}
if (provider === 'dingtalk') {
return 'D'
}
if (provider === 'wechat') {
return 'W'
}
@@ -473,6 +492,9 @@ function providerIconClass(provider: UserAuthProvider): string {
if (provider === 'linuxdo') {
return 'bg-orange-100 text-orange-600 dark:bg-orange-900/20 dark:text-orange-300'
}
if (provider === 'dingtalk') {
return 'bg-blue-100 text-blue-600 dark:bg-blue-900/20 dark:text-blue-300'
}
if (provider === 'wechat') {
return 'bg-green-100 text-green-600 dark:bg-green-900/20 dark:text-green-300'
}
@@ -139,6 +139,7 @@
<ProfileIdentityBindingsSection
:user="user"
:linuxdo-enabled="linuxdoEnabled"
:dingtalk-enabled="dingtalkEnabled"
:oidc-enabled="oidcEnabled"
:oidc-provider-name="oidcProviderName"
:wechat-enabled="wechatEnabled"
@@ -190,6 +191,7 @@ import type { User, UserAuthBindingStatus, UserAuthProvider, UserProfileSourceCo
const props = withDefaults(defineProps<{
user: User | null
linuxdoEnabled?: boolean
dingtalkEnabled?: boolean
oidcEnabled?: boolean
oidcProviderName?: string
wechatEnabled?: boolean
@@ -197,6 +199,7 @@ const props = withDefaults(defineProps<{
wechatMpEnabled?: boolean
}>(), {
linuxdoEnabled: false,
dingtalkEnabled: false,
oidcEnabled: false,
oidcProviderName: 'OIDC',
wechatEnabled: false,
@@ -262,6 +265,7 @@ const memberSinceLabel = computed(() => {
const providerLabels = computed<Record<UserAuthProvider, string>>(() => ({
email: t('profile.authBindings.providers.email'),
linuxdo: t('profile.authBindings.providers.linuxdo'),
dingtalk: t('profile.authBindings.providers.dingtalk'),
oidc: t('profile.authBindings.providers.oidc', { providerName: props.oidcProviderName }),
wechat: t('profile.authBindings.providers.wechat'),
github: 'GitHub',