1- /** 提供单应用对话与门户的认证前置配置、匿名认证、登录和登出接口 。 */
1+ /** 提供单应用对话与门户的认证前置配置、匿名认证、账号/第三方/扫码登录和登出接口 。 */
22
33import { get , post , promise , request } from './core/request'
44import type { ApiResponse } from './core/types'
5- import type { ApplicationAuthProfile , ChatLoginRequest , ChatLoginResponse , PortalAuthProfile } from '@/api/types'
5+ import type { ApplicationAuthProfile , ChatLoginRequest , ChatLoginResponse , ExternalAuthSetting , PortalAuthProfile , QrCodeSource } from '@/api/types'
66
77interface ChatCaptchaResponse {
88 captcha : string
@@ -43,6 +43,30 @@ const postLogin = (loginRequest: ChatLoginRequest, accessToken?: string, savedTo
4343 )
4444}
4545
46+ /** 使用 LDAP 账号登录;传入 accessToken 时登录到对应应用,否则登录门户。携带本地保存的 token。 */
47+ const postLdapLogin = ( loginRequest : ChatLoginRequest , accessToken ?: string , savedToken ?: string ) => {
48+ return promise < ChatLoginResponse > (
49+ request . post < ApiResponse < ChatLoginResponse > > ( accessToken ? `/auth/ldap/login/${ accessToken } ` : '/auth/ldap/login' , loginRequest , {
50+ headers : getSavedTokenHeaders ( savedToken ) ,
51+ } ) ,
52+ )
53+ }
54+
55+ /** 获取 CAS、OIDC、OAuth2 等对话用户第三方认证的跳转配置。 */
56+ const getExternalAuthSetting = ( authType : string ) => {
57+ return get < ExternalAuthSetting > ( `/chat_user/${ authType } /detail` )
58+ }
59+
60+ /** 获取对话用户扫码登录提供商配置。 */
61+ const getQrCodeSources = ( ) => {
62+ return get < QrCodeSource [ ] > ( '/auth/qr_type/source' )
63+ }
64+
65+ /** 使用钉钉扫码授权码登录;传入 accessToken 时登录到对应应用。 */
66+ const getDingTalkCallback = ( code : string , accessToken ?: string ) => {
67+ return get < ChatLoginResponse > ( '/auth/dingtalk' , accessToken ? { code, accessToken } : { code } )
68+ }
69+
4670/**
4771 * 获取应用登录验证码;无需验证码时返回空字符串。
4872 * 后端当前以 `application_id` 查询参数接收 accessToken,且仅支持应用场景。
@@ -56,4 +80,15 @@ const postLogout = () => {
5680 return post < undefined , boolean > ( '/v3/auth/logout' )
5781}
5882
59- export default { getApplicationAuthProfile, getPortalAuthProfile, postAnonymousAuth, postLogin, getCaptcha, postLogout }
83+ export default {
84+ getApplicationAuthProfile,
85+ getPortalAuthProfile,
86+ postAnonymousAuth,
87+ postLogin,
88+ postLdapLogin,
89+ getExternalAuthSetting,
90+ getQrCodeSources,
91+ getDingTalkCallback,
92+ getCaptcha,
93+ postLogout,
94+ }
0 commit comments