feat: add api to connect user completion form to backend
This commit is contained in:
34
src/lib/authToken.ts
Normal file
34
src/lib/authToken.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
// src/lib/authService.ts
|
||||
import axios from 'axios';
|
||||
|
||||
export interface TokenResponse {
|
||||
access_token: string;
|
||||
expires_in: number;
|
||||
refresh_token: string;
|
||||
}
|
||||
|
||||
const authClient = axios.create({
|
||||
baseURL: 'https://account.business-harmony.com',
|
||||
timeout: 10000,
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
});
|
||||
|
||||
export async function loginWithPassword(
|
||||
username: string,
|
||||
password: string,
|
||||
): Promise<TokenResponse> {
|
||||
const body = new URLSearchParams();
|
||||
body.set('grant_type', 'password');
|
||||
body.set('username', username);
|
||||
body.set('password', password);
|
||||
body.set('client_id', 'harmony_identity');
|
||||
body.set('scope', 'openid harmony_identity profile offline_access');
|
||||
|
||||
const { data } = await authClient.post<TokenResponse>(
|
||||
'/connect/token',
|
||||
body.toString(),
|
||||
);
|
||||
|
||||
localStorage.setItem('authToken', data.access_token);
|
||||
return data;
|
||||
}
|
||||
Reference in New Issue
Block a user