stages/authenticator_webauthn: migrate to web
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
995f3a13d1
commit
0b057ccb34
|
@ -2,7 +2,6 @@
|
|||
from typing import Optional, Type
|
||||
|
||||
from django.db import models
|
||||
from django.forms import ModelForm
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views import View
|
||||
from rest_framework.serializers import BaseSerializer
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
from typing import Optional, Type
|
||||
|
||||
from django.db import models
|
||||
from django.forms import ModelForm
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views import View
|
||||
from rest_framework.serializers import BaseSerializer
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
"""Webauthn stage forms"""
|
||||
from django import forms
|
||||
|
||||
from authentik.stages.authenticator_webauthn.models import (
|
||||
AuthenticateWebAuthnStage,
|
||||
WebAuthnDevice,
|
||||
)
|
||||
|
||||
|
||||
class AuthenticateWebAuthnStageForm(forms.ModelForm):
|
||||
"""OTP Time-based Stage setup form"""
|
||||
|
||||
class Meta:
|
||||
|
||||
model = AuthenticateWebAuthnStage
|
||||
fields = ["name"]
|
||||
|
||||
widgets = {
|
||||
"name": forms.TextInput(),
|
||||
}
|
||||
|
||||
|
||||
class DeviceEditForm(forms.ModelForm):
|
||||
"""Form to edit webauthn device"""
|
||||
|
||||
class Meta:
|
||||
|
||||
model = WebAuthnDevice
|
||||
fields = ["name"]
|
||||
|
||||
widgets = {
|
||||
"name": forms.TextInput(),
|
||||
}
|
|
@ -3,7 +3,6 @@ from typing import Optional, Type
|
|||
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db import models
|
||||
from django.forms import ModelForm
|
||||
from django.utils.timezone import now
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views import View
|
||||
|
@ -34,12 +33,8 @@ class AuthenticateWebAuthnStage(ConfigurableStage, Stage):
|
|||
return AuthenticatorWebAuthnStageView
|
||||
|
||||
@property
|
||||
def form(self) -> Type[ModelForm]:
|
||||
from authentik.stages.authenticator_webauthn.forms import (
|
||||
AuthenticateWebAuthnStageForm,
|
||||
)
|
||||
|
||||
return AuthenticateWebAuthnStageForm
|
||||
def component(self) -> str:
|
||||
return "ak-stage-authenticator-webauthn-form"
|
||||
|
||||
@property
|
||||
def ui_user_settings(self) -> Optional[UserSettingSerializer]:
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""deny stage models"""
|
||||
from typing import Type
|
||||
|
||||
from django.forms import ModelForm
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views import View
|
||||
from rest_framework.serializers import BaseSerializer
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""dummy stage models"""
|
||||
from typing import Type
|
||||
|
||||
from django.forms import ModelForm
|
||||
from django.utils.translation import gettext as _
|
||||
from django.views import View
|
||||
from rest_framework.serializers import BaseSerializer
|
||||
|
|
|
@ -3,7 +3,6 @@ from typing import Optional, Type
|
|||
|
||||
from django.contrib.postgres.fields import ArrayField
|
||||
from django.db import models
|
||||
from django.forms import ModelForm
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.views import View
|
||||
from rest_framework.serializers import BaseSerializer
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
import { AuthenticateWebAuthnStage, StagesApi } from "authentik-api";
|
||||
import { gettext } from "django";
|
||||
import { customElement, property } from "lit-element";
|
||||
import { html, TemplateResult } from "lit-html";
|
||||
import { DEFAULT_CONFIG } from "../../../api/Config";
|
||||
import { Form } from "../../../elements/forms/Form";
|
||||
import { ifDefined } from "lit-html/directives/if-defined";
|
||||
import "../../../elements/forms/HorizontalFormElement";
|
||||
|
||||
@customElement("ak-stage-authenticator-webauthn-form")
|
||||
export class AuthenticateWebAuthnStageForm extends Form<AuthenticateWebAuthnStage> {
|
||||
|
||||
set stageUUID(value: string) {
|
||||
new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorWebauthnRead({
|
||||
stageUuid: value,
|
||||
}).then(stage => {
|
||||
this.stage = stage;
|
||||
});
|
||||
}
|
||||
|
||||
@property({attribute: false})
|
||||
stage?: AuthenticateWebAuthnStage;
|
||||
|
||||
getSuccessMessage(): string {
|
||||
if (this.stage) {
|
||||
return gettext("Successfully updated stage.");
|
||||
} else {
|
||||
return gettext("Successfully created stage.");
|
||||
}
|
||||
}
|
||||
|
||||
send = (data: AuthenticateWebAuthnStage): Promise<AuthenticateWebAuthnStage> => {
|
||||
if (this.stage) {
|
||||
return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorWebauthnUpdate({
|
||||
stageUuid: this.stage.pk || "",
|
||||
data: data
|
||||
});
|
||||
} else {
|
||||
return new StagesApi(DEFAULT_CONFIG).stagesAuthenticatorWebauthnCreate({
|
||||
data: data
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
renderForm(): TemplateResult {
|
||||
return html`<form class="pf-c-form pf-m-horizontal">
|
||||
<ak-form-element-horizontal
|
||||
label=${gettext("Name")}
|
||||
?required=${true}
|
||||
name="name">
|
||||
<input type="text" value="${ifDefined(this.stage?.name || "")}" class="pf-c-form-control" required>
|
||||
</ak-form-element-horizontal>
|
||||
</form>`;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue