diff --git a/src/features/authorization/api/identityAPI.ts b/src/features/authorization/api/identityAPI.ts index 0d20e01..efa3610 100644 --- a/src/features/authorization/api/identityAPI.ts +++ b/src/features/authorization/api/identityAPI.ts @@ -1,7 +1,6 @@ import apiClient from '@/lib/apiClient'; -import axios from 'axios'; -export interface GenerateToken { +export interface GenerateTokenWithPassword { username: string; password: string; } @@ -14,11 +13,9 @@ export interface GenerateTokenResponse { scope: string; } -const ACCESS_TOKEN_KEY: 'access_token' = 'access_token' as const; -const REFRESH_TOKEN_KEY: 'refresh_token' = 'refresh_token' as const; -const EXPIRES_IN_KEY: 'expires_in' = 'expires_in' as const; - -export const generateTokenWithPassword = (request: GenerateToken) => { +export const generateTokenWithPassword = ( + request: GenerateTokenWithPassword, +) => { const body = new URLSearchParams(); body.set('grant_type', 'password'); body.set('client_id', import.meta.env.VITE_IDENTITY_CLIENT_ID); @@ -36,3 +33,27 @@ export const generateTokenWithPassword = (request: GenerateToken) => { }, ); }; + +export interface GenerateTokenWithOTP { + username: string; + otp: string; +} + +export const generateTokenWithOtp = (request: GenerateTokenWithOTP) => { + const body = new URLSearchParams(); + body.set('grant_type', 'otp'); + body.set('client_id', import.meta.env.VITE_IDENTITY_CLIENT_ID); + body.set('scope', import.meta.env.VITE_IDENTITY_SCOPE); + body.set('username', request.username); + body.set('otp', request.otp); + + return apiClient.post( + import.meta.env.VITE_IDENTITY_URL, + body.toString(), + { + headers: { + 'Content-Type': 'application/x-www-form-urlencoded', + }, + }, + ); +};