You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
812 B

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;
}
}