erp-platform/ui/src/services/auth.service.ts

64 lines
1.7 KiB
TypeScript
Raw Normal View History

import {
2025-05-06 06:45:49 +00:00
FailedRefreshResponse,
FailedSignInResponse,
SignInCredential,
SignInResponse,
} from '../@types/auth'
import { AUTH_API_NAME } from '../constants/app.constant'
import apiService, { Config } from './api.service'
2025-05-06 06:45:49 +00:00
const authConfig: Config = {
apiName: AUTH_API_NAME,
}
export const signIn = (data: SignInCredential) =>
apiService.fetchData<SignInResponse | FailedSignInResponse>(
{
method: 'POST',
url: '/connect/token',
headers: { 'content-type': 'application/x-www-form-urlencoded' },
data: {
username: data.userName,
password: data.password,
twoFactorCode: data.twoFactorCode,
captchaResponse: data.captchaResponse,
grant_type: 'password',
scope: 'offline_access Platform',
client_id: 'Platform_App',
},
},
authConfig,
)
export const refreshToken = (refresh_token: string) =>
apiService.fetchData<SignInResponse | FailedRefreshResponse>(
{
method: 'POST',
url: '/connect/token',
headers: { 'content-type': 'application/x-www-form-urlencoded' },
data: {
refresh_token,
grant_type: 'refresh_token',
scope: 'offline_access Platform',
client_id: 'Platform_App',
},
validateStatus: () => true,
},
authConfig,
)
export const signOut = (data: any) =>
apiService.fetchData(
{
method: 'POST',
url: '/connect/revocat',
headers: { 'content-type': 'application/x-www-form-urlencoded' },
data: new URLSearchParams({
token: data.token,
client_id: 'Platform_App',
token_type_hint: 'access_token',
}).toString(),
},
authConfig,
)