mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
23 lines
572 B
TypeScript
23 lines
572 B
TypeScript
|
|
||
|
import { Speakeasy } from "../types/Dependencies";
|
||
|
import BluebirdPromise = require("bluebird");
|
||
|
|
||
|
const TOTP_ENCODING = "base32";
|
||
|
|
||
|
export default class TOTPValidator {
|
||
|
private speakeasy: Speakeasy;
|
||
|
|
||
|
constructor(speakeasy: Speakeasy) {
|
||
|
this.speakeasy = speakeasy;
|
||
|
}
|
||
|
|
||
|
validate(token: string, secret: string): BluebirdPromise<void> {
|
||
|
const real_token = this.speakeasy.totp({
|
||
|
secret: secret,
|
||
|
encoding: TOTP_ENCODING
|
||
|
});
|
||
|
|
||
|
if (token == real_token) return BluebirdPromise.resolve();
|
||
|
return BluebirdPromise.reject("Wrong challenge");
|
||
|
}
|
||
|
}
|