import { getEnvs } from "../environment/env"; /* eslint-disable @typescript-eslint/return-await */ export const getToken = async (url: string) => { const envs = getEnvs(url); const body = { grant_type: "client_credentials", client_id: envs.clientId, client_secret: envs.clientSecret, scope: envs.clientScope, }; const credentials = `grant_type=client_credentials&client_id=${body.client_id}&client_secret=${body.client_secret}&scope=client_scope`; try { const tokenResponse = await fetch(`${envs.wlAuthUrl}/connect/token`, { method: "POST", body: credentials, headers: { "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8", "Cache-Control": "no-cache", Accept: "*/*", Referer: url, } as any, }); if (tokenResponse.status !== 200) { return null; } const tokenResult = await tokenResponse.json(); return tokenResult; } catch (error) { return null; } };