import axios from 'axios'; import { IAuthentication } from '../types/Authentication'; import PackageInterface from '../interface'; const packageInterface = PackageInterface.get(); const log = (...args) => packageInterface.log(...args); interface IHTTPAuthOptions { url: string; } export class HTTPAuth implements IAuthentication { private url: string; constructor(config: IHTTPAuthOptions) { this.url = config.url; } async authenticate(username: string, password: string) { const result = await axios.post( this.url, { username, password, }, { validateStatus(status) { return status >= 200 && status < 500; }, } ); if (result.status === 200) { return true; } log(`HTTP authentication failed, response code: ${result.status}`); return false; } }