Skip to content

Commit 5013c48

Browse files
feat: enhance authentication flow with dynamic UUID resolution
- Added lookup of enrollment and recovery flow UUIDs before rendering authentication flow template - Updated authentication flow template to use resolved UUIDs instead of slugs for Authentik API compatibility - Added retry mechanism when looking up dependent flows to handle race conditions - Extended flowTemplateData struct with EnrollmentUUID and RecoveryUUID fields - Added debug logging for UUID resolution and warning if dependent flows are not foun
1 parent 206891f commit 5013c48

1 file changed

Lines changed: 39 additions & 6 deletions

File tree

pkg/hecate/default_flows.go

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,33 @@ func EnableDefaultFlows(rc *eos_io.RuntimeContext, cfg *DefaultFlowsConfig) erro
143143
continue
144144
}
145145

146+
// CRITICAL: Authentication flow requires enrollment and recovery flow UUIDs
147+
// RATIONALE: Authentik API requires flow references by UUID, not slug
148+
// TIMING: Must look up after enrollment/recovery are imported, before authentication is rendered
149+
if flow.Name == "Authentication" {
150+
// Look up enrollment and recovery flows that were just imported
151+
enrollmentFlow := getFlowWithRetry(rc, client, logger, fmt.Sprintf("%s-enrollment", appSlug), 5, 1*time.Second)
152+
recoveryFlow := getFlowWithRetry(rc, client, logger, fmt.Sprintf("%s-recovery", appSlug), 5, 1*time.Second)
153+
154+
if enrollmentFlow != nil {
155+
templateData.EnrollmentUUID = enrollmentFlow.PK
156+
logger.Debug("Resolved enrollment flow UUID for authentication flow",
157+
zap.String("enrollment_uuid", enrollmentFlow.PK))
158+
}
159+
if recoveryFlow != nil {
160+
templateData.RecoveryUUID = recoveryFlow.PK
161+
logger.Debug("Resolved recovery flow UUID for authentication flow",
162+
zap.String("recovery_uuid", recoveryFlow.PK))
163+
}
164+
165+
if enrollmentFlow == nil || recoveryFlow == nil {
166+
logger.Warn("Authentication flow requires enrollment and recovery flows to be imported first",
167+
zap.Bool("enrollment_found", enrollmentFlow != nil),
168+
zap.Bool("recovery_found", recoveryFlow != nil))
169+
// Continue anyway - template will render with empty UUIDs which will fail Authentik validation
170+
}
171+
}
172+
146173
rendered, err := renderFlowTemplate(flow.Template, templateData)
147174
if err != nil {
148175
return fmt.Errorf("failed to render flow template %q: %w", flow.Name, err)
@@ -316,10 +343,12 @@ func EnableDefaultFlows(rc *eos_io.RuntimeContext, cfg *DefaultFlowsConfig) erro
316343
}
317344

318345
type flowTemplateData struct {
319-
AppSlug string
320-
AppTitle string
321-
GroupUUID string
322-
GroupName string
346+
AppSlug string
347+
AppTitle string
348+
GroupUUID string
349+
GroupName string
350+
EnrollmentUUID string // UUID of enrollment flow (for authentication flow template)
351+
RecoveryUUID string // UUID of recovery flow (for authentication flow template)
323352
}
324353

325354
type flowDefinition struct {
@@ -883,8 +912,12 @@ entries:
883912
- email
884913
- username
885914
template: stages/identification/login.html
886-
enrollment_flow: "{{ .AppSlug }}-enrollment"
887-
recovery_flow: "{{ .AppSlug }}-recovery"
915+
{{- if .EnrollmentUUID }}
916+
enrollment_flow: {{ .EnrollmentUUID }}
917+
{{- end }}
918+
{{- if .RecoveryUUID }}
919+
recovery_flow: {{ .RecoveryUUID }}
920+
{{- end }}
888921
show_source_labels: true
889922
890923
- identifiers:

0 commit comments

Comments
 (0)