stages/authenticator_duo: revamp duo enroll status API

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>

#3288
This commit is contained in:
Jens Langhammer
2022-08-08 20:38:06 +02:00
parent 2858682866
commit 54c16129ea
4 changed files with 61 additions and 25 deletions

View File

@ -21,6 +21,7 @@ import PFBase from "@patternfly/patternfly/patternfly-base.css";
import {
AuthenticatorDuoChallenge,
AuthenticatorDuoChallengeResponseRequest,
DuoResponseEnum,
StagesApi,
} from "@goauthentik/api";
@ -35,23 +36,29 @@ export class AuthenticatorDuoStage extends BaseStage<
firstUpdated(): void {
const i = setInterval(() => {
this.checkEnrollStatus().then(() => {
clearInterval(i);
this.checkEnrollStatus().then((shouldStop) => {
if (shouldStop) {
clearInterval(i);
}
});
}, 3000);
}
checkEnrollStatus(): Promise<void> {
return new StagesApi(DEFAULT_CONFIG)
.stagesAuthenticatorDuoEnrollmentStatusCreate({
stageUuid: this.challenge?.stageUuid || "",
})
.then(() => {
async checkEnrollStatus(): Promise<boolean> {
const status = await new StagesApi(
DEFAULT_CONFIG,
).stagesAuthenticatorDuoEnrollmentStatusCreate({
stageUuid: this.challenge?.stageUuid || "",
});
console.debug(`authentik/flows/duo: Enrollment status: ${status.duoResponse}`);
switch (status.duoResponse) {
case DuoResponseEnum.Success:
this.host?.submit({});
})
.catch(() => {
console.debug("authentik/flows/duo: Waiting for auth status");
});
return true;
case DuoResponseEnum.Waiting:
break;
}
return false;
}
render(): TemplateResult {