You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

167 lines
3.6 KiB

import type { GrantType } from '@vben/common-ui';
import { useAppConfig } from '@vben/hooks';
import { requestClient } from '#/api/request';
const { clientId } = useAppConfig(import.meta.env, import.meta.env.PROD);
export namespace AuthApi {
/**
* @description:
* @param clientId ID loginApi
* @param grantType /
* @param tenantId id
*/
export interface BaseLoginParams {
clientId?: string;
grantType: GrantType;
tenantId: string;
}
/**
* @description: oauth
* @param socialCode
* @param socialState
* @param source justauth.type.xxxsource
*/
export interface OAuthLoginParams extends BaseLoginParams {
socialCode: string;
socialState: string;
source: string;
}
/**
* @description:
* @param code ()
* @param uuid ID ()
* @param username
* @param password
*/
export interface SimpleLoginParams extends BaseLoginParams {
code?: string;
uuid?: string;
username: string;
password: string;
}
export type LoginParams = OAuthLoginParams | SimpleLoginParams;
// /** 登录接口参数 */
// export interface LoginParams {
// code?: string;
// grantType: string;
// password: string;
// tenantId: string;
// username: string;
// uuid?: string;
// }
/** 登录接口返回值 */
export interface LoginResult {
access_token: string;
client_id: string;
expire_in: number;
}
export interface RefreshTokenResult {
data: string;
status: number;
}
}
/**
*
*/
export async function loginApi(data: AuthApi.LoginParams) {
return requestClient.post<AuthApi.LoginResult>(
'/auth/login',
{ ...data, clientId },
{
encrypt: true,
},
);
}
/**
*
* @returns void
*/
export function doLogout() {
return requestClient.post<void>('/auth/logout');
}
/**
* sse
* @returns void
*/
export function seeConnectionClose() {
return requestClient.get<void>('/resource/sse/close');
}
/**
* @param companyName /
* @param domain (http(s)://) 可选
* @param tenantId id
*/
export interface TenantOption {
companyName: string;
domain?: string;
tenantId: string;
}
/**
* @param tenantEnabled
* @param voList
*/
export interface TenantResp {
tenantEnabled: boolean;
voList: TenantOption[];
}
/**
* 使
*/
export function tenantList() {
return requestClient.get<TenantResp>('/auth/tenant/list');
}
/**
* vben
* @returns string[]
*/
export async function getAccessCodesApi() {
return requestClient.get<string[]>('/auth/codes');
}
/**
*
* @param source
* @returns url
*/
export function authBinding(source: string, tenantId: string) {
return requestClient.get<string>(`/auth/binding/${source}`, {
params: {
domain: window.location.host,
tenantId,
},
});
}
/**
*
* @param id id
*/
export function authUnbinding(id: string) {
return requestClient.deleteWithMsg<void>(`/auth/unlock/${id}`);
}
/**
* oauth
* @param data oauth
* @returns void
*/
export function authCallback(data: AuthApi.OAuthLoginParams) {
return requestClient.post<void>('/auth/social/callback', data);
}