Files
hanko/backend/flow_api/flow/capabilities/action_send_capabilities.go
2025-09-25 19:15:20 +02:00

60 lines
1.9 KiB
Go

package capabilities
import (
"github.com/teamhanko/hanko/backend/v2/flow_api/flow/shared"
"github.com/teamhanko/hanko/backend/v2/flowpilot"
)
type RegisterClientCapabilities struct {
shared.Action
}
func (a RegisterClientCapabilities) GetName() flowpilot.ActionName {
return shared.ActionRegisterClientCapabilities
}
func (a RegisterClientCapabilities) GetDescription() string {
return "Send the computers capabilities."
}
func (a RegisterClientCapabilities) Initialize(c flowpilot.InitializationContext) {
c.AddInputs(flowpilot.BooleanInput("webauthn_conditional_mediation_available").Hidden(true))
c.AddInputs(flowpilot.BooleanInput("webauthn_platform_authenticator_available").Hidden(true))
c.AddInputs(flowpilot.BooleanInput("webauthn_available").Required(true).Hidden(true))
}
func (a RegisterClientCapabilities) Execute(c flowpilot.ExecutionContext) error {
deps := a.GetDeps(c)
if valid := c.ValidateInputData(); !valid {
return c.Error(flowpilot.ErrorFormDataInvalid)
}
webauthnAvailable := c.Input().Get("webauthn_available").Bool()
err := c.Stash().Set(shared.StashPathWebauthnAvailable, webauthnAvailable)
if err != nil {
return err
}
conditionalMediationAvailable := c.Input().Get("webauthn_conditional_mediation_available").Bool()
err = c.Stash().Set(shared.StashPathWebauthnConditionalMediationAvailable, conditionalMediationAvailable)
if err != nil {
return err
}
platformAuthenticatorAvailable := c.Input().Get("webauthn_platform_authenticator_available").Bool()
err = c.Stash().Set(shared.StashPathWebauthnPlatformAuthenticatorAvailable, platformAuthenticatorAvailable)
if err != nil {
return err
}
attachmentSupported := platformAuthenticatorAvailable ||
deps.Cfg.MFA.SecurityKeys.AuthenticatorAttachment != "platform"
err = c.Stash().Set(shared.StashPathSecurityKeyAttachmentSupported, attachmentSupported)
if err != nil {
return err
}
return c.Continue()
}