53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import BaseApiService from "@Front/Api/BaseApiService";
|
|
import { FrontendVariables } from "@Front/Config/VariablesFront";
|
|
//import User from "le-coffre-resources/dist/SuperAdmin";
|
|
|
|
export default class Auth extends BaseApiService {
|
|
private static instance: Auth;
|
|
|
|
private constructor() {
|
|
super();
|
|
}
|
|
|
|
public static getInstance(): Auth {
|
|
return (this.instance = this.instance ?? new this());
|
|
}
|
|
|
|
public async logOutWithIdNot() {
|
|
const variables = FrontendVariables.getInstance();
|
|
const url = new URL(`${variables.IDNOT_BASE_URL}/user/auth/logout?post_logout_redirect_uri=${variables.FRONT_APP_HOST}`);
|
|
console.log(url.toString())
|
|
try {
|
|
return await fetch(url);
|
|
} catch (err) {
|
|
console.log(err);
|
|
this.onError(err);
|
|
return Promise.reject(err);
|
|
}
|
|
}
|
|
|
|
public async loginWithIdNot() {
|
|
const variables = FrontendVariables.getInstance();
|
|
const url = new URL(`${variables.IDNOT_BASE_URL + variables.IDNOT_AUTHORIZE_ENDPOINT}?client_id=${variables.IDNOT_CLIENT_ID}&redirect_uri=${variables.FRONT_APP_HOST}/authorized-client&scope=openid,profile&response_type=code`);
|
|
try {
|
|
return await this.getRequest(url);
|
|
} catch (err) {
|
|
this.onError(err);
|
|
return Promise.reject(err);
|
|
}
|
|
}
|
|
|
|
public async getIdnotJwt(autorizationCode: string | string[]): Promise<{accessToken: string, refreshToken: string}> {
|
|
const variables = FrontendVariables.getInstance();
|
|
const baseBackUrl = variables.BACK_API_PROTOCOL + variables.BACK_API_HOST;
|
|
const url = new URL(`${baseBackUrl}/api/v1/idnot/user/${autorizationCode}`);
|
|
try {
|
|
return await this.postRequest<{accessToken: string, refreshToken: string}>(url);
|
|
} catch (err) {
|
|
this.onError(err);
|
|
return Promise.reject(err);
|
|
}
|
|
}
|
|
|
|
}
|