fix(iam): align cross-app proofs and add native IAM target launch

This commit is contained in:
2026-10-29 18:49:32 +08:00
parent dcb0db8275
commit 7cbc679287
25 changed files with 837 additions and 99 deletions
+13 -5
View File
@@ -16,11 +16,18 @@
<p class="my-3 text-gray-500">
关联只确认同一人的身份,不会复制业务角色或自动授予其他平台权限。
</p>
<el-alert
v-if="!linked && status.protected_account"
class="mb-4"
type="warning"
:closable="false"
title="此账号属于敏感账号,请由本地管理员在 IAM 关联管理发起单人中央复核,不使用个人自助绑定。"
/>
<div class="flex flex-wrap gap-3">
<el-button @click="reauthVisible = true">验证当前身份</el-button>
<el-button @click="wecomRelogin">企业微信重新登录</el-button>
<el-button
v-if="!linked"
v-if="!linked && !status.protected_account"
type="primary"
:loading="busy"
@click="navigate('/self-link/start')"
@@ -54,9 +61,7 @@
仅验证当前账号,验证有效期 5 分钟。密码不会被保存或传给 IAM。
</p>
<template #footer
><el-button
@click="cancelReauth"
>取消</el-button
><el-button @click="cancelReauth">取消</el-button
><el-button type="primary" :loading="busy" @click="reauth"
>验证</el-button
></template
@@ -82,7 +87,10 @@ async function refresh() {
error.value = identityError(e)
}
}
function cancelReauth() { reauthVisible.value = false; password.value = '' }
function cancelReauth() {
reauthVisible.value = false
password.value = ''
}
async function reauth() {
busy.value = true
try {
+1 -1
View File
@@ -81,7 +81,7 @@ const defaultPath = PageEnum.INDEX
const changePasswordPath = '/change-password'
const bindWorkWechatPath = '/bind-work-wechat'
// 免登录白名单
const whiteList: string[] = [PageEnum.LOGIN, PageEnum.ERROR_403]
const whiteList: string[] = [PageEnum.LOGIN, PageEnum.ERROR_403, '/iam/launch']
router.beforeEach(async (to, from, next) => {
document.title = to.meta.title ?? config.title
const userStore = useUserStore()
+5
View File
@@ -23,6 +23,11 @@ export const LAYOUT = () => Promise.resolve(Layout)
export const INDEX_ROUTE_NAME = Symbol()
export const constantRoutes: Array<RouteRecordRaw> = [
{
path: '/iam/launch',
component: () => import('@/views/account/iam-launch.vue'),
meta: { title: '统一身份进入甄养堂', hideTab: true }
},
{
path: '/:pathMatch(.*)*',
component: () => import('@/views/error/404.vue')
+9
View File
@@ -2,6 +2,7 @@ import { defineStore } from 'pinia'
import type { RouteRecordRaw } from 'vue-router'
import { getUserInfo, iamLogin, login, logout, workWechatLogin } from '@/api/user'
import { iamPost } from '@/api/iam-v2'
import { TOKEN_KEY } from '@/enums/cacheEnums'
import { PageEnum } from '@/enums/pageEnum'
import router, { filterAsyncRoutes } from '@/router'
@@ -83,6 +84,14 @@ const useUserStore = defineStore({
})
})
},
async iamLaunchLogin(ticket: string) {
const data = await iamPost('/launch/exchange', { ticket })
this.resetState()
this.token = data.token
this.isPaw = data.is_paw ?? 1
cache.set(TOKEN_KEY, data.token)
return data
},
async iamLogin(ticket: string) {
const data = await iamLogin(ticket)
this.token = data.token
+93
View File
@@ -0,0 +1,93 @@
<template>
<main class="min-h-screen flex items-center justify-center bg-page p-6">
<el-card class="w-full max-w-xl" shadow="never">
<h1 class="text-xl font-semibold mb-4">统一身份进入甄养堂</h1>
<p v-if="busy" class="text-gray-500">正在核验同一身份,请稍候…</p>
<el-alert v-if="error" :title="error" type="warning" :closable="false" show-icon />
<p class="text-gray-500 my-4">
已有 ZYT 账号将进行一致性检查。系统不会自动替换当前已登录的人。
</p>
<div v-if="error" class="flex flex-wrap gap-3">
<el-button v-if="restartUrl" type="primary" @click="back"
>返回 IAM 重新发起</el-button
>
<el-button v-if="restartUrl" :loading="busy" @click="switchAccount"
>退出当前 ZYT 身份并返回 IAM</el-button
>
<router-link to="/login"><el-button>使用原登录方式</el-button></router-link>
</div>
</el-card>
</main>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { iamGet, iamPost, identityError } from '@/api/iam-v2'
import useUserStore from '@/stores/modules/user'
import { clearAuthInfo } from '@/utils/auth'
import feedback from '@/utils/feedback'
const route = useRoute(),
router = useRouter(),
store = useUserStore()
const busy = ref(true),
error = ref(''),
restartUrl = ref('')
let handled = false
const text = (v: unknown) => (typeof v === 'string' ? v : '')
function back() {
if (restartUrl.value) window.location.assign(restartUrl.value)
}
async function switchAccount() {
await feedback.confirm(
'确认退出当前浏览器的 ZYT 身份?其他平台和其他浏览器不受影响。请回 IAM 重新发起。'
)
busy.value = true
try {
await iamPost('/launch/reset')
clearAuthInfo()
back()
} catch (e) {
error.value = identityError(e)
} finally {
busy.value = false
}
}
onMounted(async () => {
if (handled) return
handled = true
const ticket = text(route.query.ticket),
source = text(route.query.source),
intent = text(route.query.intent),
issue = text(route.query.iam_error)
// Strip one-use material before any network/async work; never retain it in history.
window.history.replaceState(window.history.state, '', window.location.pathname)
try {
const config = await iamGet('/launch/config', { source })
restartUrl.value = config.restart_url || ''
if (!config.enabled) throw { error: { code: 'FEATURE_DISABLED' } }
if (issue) throw { error: { code: issue } }
if (ticket) {
const result = await store.iamLaunchLogin(ticket)
await router.replace(
result.is_paw === 0
? '/change-password'
: result.need_bind_work_wechat
? '/bind-work-wechat'
: '/'
)
} else {
if (
!['iam-admin', 'iam-portal'].includes(source) ||
!/^[A-Za-z0-9_-]{32,256}$/.test(intent)
)
throw { error: { code: 'INVALID_REQUEST' } }
const result = await iamPost('/launch/prepare', { source, intent })
window.location.assign(result.url)
}
} catch (e) {
error.value = identityError(e)
} finally {
busy.value = false
}
})
</script>
+50 -17
View File
@@ -81,14 +81,23 @@
<el-button
link
type="primary"
:disabled="!!row.root || row.iam.state === 'verified' || !can('bind')"
:disabled="
(!!row.root && !reviewAllowed) ||
row.iam.state === 'verified' ||
!can(row.iam.state === 'revoked' ? 'rebind' : 'bind')
"
@click="open(row, 'bind')"
>关联</el-button
>
<el-button
link
type="primary"
:disabled="!!row.root || row.iam.state === 'verified' || !can('create')"
:disabled="
(!!row.root && !reviewAllowed) ||
row.iam.state === 'verified' ||
!can('create') ||
(row.iam.state === 'revoked' && !can('rebind'))
"
@click="open(row, 'create_and_bind')"
>创建并关联</el-button
>
@@ -98,12 +107,12 @@
><el-dropdown-menu>
<el-dropdown-item
command="rebind"
:disabled="!!row.root || !can('rebind')"
:disabled="(!!row.root && !reviewAllowed) || !can('rebind')"
>换绑</el-dropdown-item
>
<el-dropdown-item
command="unbind"
:disabled="!!row.root || !can('unbind')"
:disabled="(!!row.root && !reviewAllowed) || !can('unbind')"
>解绑</el-dropdown-item
>
<el-dropdown-item command="audit">审计记录</el-dropdown-item>
@@ -219,6 +228,7 @@
><el-input
class="mt-4"
v-model="operation.reason"
:disabled="!!submittedPayload"
type="textarea"
:rows="3"
maxlength="500"
@@ -237,10 +247,22 @@
<el-alert
v-if="result"
class="mt-4"
:title="`操作 ${result.id}:${result.status}`"
:title="`操作 ${result.id}:${result.status}${result.error?.code ? ' · ' + identityError(result) : ''}`"
:type="result.status === 'succeeded' ? 'success' : 'warning'"
:closable="false"
/>
<div v-if="result?.reviewUrl" class="mt-4">
<a
:href="result.reviewUrl"
target="_blank"
rel="noopener noreferrer"
class="text-primary"
>中央复核 ↗</a
>
<p class="text-gray-500 mt-2">
由中央管理员完成近期验证并批准后,重试原操作;原目标、版本和原因保持不变。
</p>
</div>
<el-button
v-if="result && result.status !== 'succeeded'"
class="mt-4"
@@ -250,7 +272,8 @@
</section>
<template #footer
><el-button @click="drawer = false">关闭</el-button
><el-button v-if="step > 0" @click="step--">上一步</el-button
><el-button v-if="step > 0" :disabled="!!submittedPayload" @click="step--"
>上一步</el-button
><el-button
v-if="step < 2"
type="primary"
@@ -265,7 +288,11 @@
!confirmed || !operation.reason.trim() || result?.status === 'succeeded'
"
@click="submit"
>确认{{ titles[operation.kind] }}</el-button
>{{
result?.reviewUrl
? '完成中央复核后重试原操作'
: '确认' + titles[operation.kind]
}}</el-button
></template
>
</el-drawer>
@@ -387,6 +414,7 @@ const titles: Record<string, string> = {
reconcile: '对账'
}
const enabled = ref(false),
reviewAllowed = ref(false),
caps = ref<string[]>([]),
rows = ref<any[]>([]),
total = ref(0),
@@ -403,6 +431,7 @@ const drawer = ref(false),
confirmed = ref(false),
drawerError = ref(''),
result = ref<any>(null)
const submittedPayload = ref<Record<string, unknown> | null>(null)
const operation = reactive<IdentityOperation>({ kind: 'bind', user_id: 0, reason: '' }),
newEmployee = reactive({ username: '', display_name: '', email: '' })
let operationKey = crypto.randomUUID(),
@@ -443,6 +472,7 @@ function reload() {
void load()
}
function open(row: any, kind: IdentityOperation['kind']) {
if (kind === 'bind' && row.iam.state === 'revoked') kind = 'rebind'
selected.value = row
Object.assign(operation, {
kind,
@@ -457,6 +487,7 @@ function open(row: any, kind: IdentityOperation['kind']) {
confirmed.value = false
drawerError.value = ''
result.value = null
submittedPayload.value = null
chosenIdentity.value = null
identities.value = []
operationKey = crypto.randomUUID()
@@ -489,16 +520,17 @@ function choose(row: any) {
async function submit() {
busy.value = true
try {
result.value = await iamPost(
'/operations',
{
...operation,
...(operation.kind === 'create_and_bind'
? { new_employee: { ...newEmployee } }
: {})
},
operationKey
)
if (!submittedPayload.value) {
submittedPayload.value = JSON.parse(
JSON.stringify({
...operation,
...(operation.kind === 'create_and_bind'
? { new_employee: { ...newEmployee } }
: {})
})
)
}
result.value = await iamPost('/operations', submittedPayload.value!, operationKey)
drawerError.value = ''
await load()
} catch (e) {
@@ -585,6 +617,7 @@ onMounted(async () => {
const s = await iamGet('/status')
enabled.value = s.enabled
caps.value = s.management_capabilities || []
reviewAllowed.value = s.protected_review_operator === true
if (enabled.value && can('read')) await load()
} catch (e) {
error.value = identityError(e)