refactor v1, start support for more protocols and implement nak

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens Langhammer
2025-05-20 22:39:14 +02:00
parent 8cf8f1e199
commit b6686cff14
12 changed files with 252 additions and 106 deletions

View File

@ -1,13 +1,17 @@
package eap
import (
"errors"
"slices"
"goauthentik.io/internal/outpost/radius/eap/protocol"
)
type ProtocolConstructor func() protocol.Payload
type Settings struct {
ProtocolsToOffer []protocol.Type
Protocols []ProtocolConstructor
ProtocolPriority []protocol.Type
ProtocolSettings map[protocol.Type]interface{}
}
@ -18,13 +22,23 @@ type StateManager interface {
}
type State struct {
ChallengesToOffer []protocol.Type
TypeState map[protocol.Type]any
Protocols []ProtocolConstructor
ProtocolIndex int
ProtocolPriority []protocol.Type
TypeState map[protocol.Type]any
}
func (st *State) GetNextProtocol() (protocol.Type, error) {
if st.ProtocolIndex >= len(st.ProtocolPriority) {
return protocol.Type(0), errors.New("no more protocols to offer")
}
return st.ProtocolPriority[st.ProtocolIndex], nil
}
func BlankState(settings Settings) *State {
return &State{
ChallengesToOffer: slices.Clone(settings.ProtocolsToOffer),
TypeState: map[protocol.Type]any{},
Protocols: slices.Clone(settings.Protocols),
ProtocolPriority: slices.Clone(settings.ProtocolPriority),
TypeState: map[protocol.Type]any{},
}
}