Skip to content

Commit

Permalink
fix missing gob register
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianccm committed Nov 26, 2021
1 parent d7b30a0 commit 0c48898
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions core/auth/oauth/oidc.go
Expand Up @@ -286,15 +286,16 @@ func (i *openIDIdentifier) config(request *web.Request) *oauth2.Config {
return &oauth2Config
}

type state struct {
type StateEntry struct {
State string
TS time.Time
}

const stateTimeout = time.Minute * 30

func init() {
gob.Register(state{})
gob.Register([]StateEntry(nil))
gob.Register(StateEntry{})
}

const sessionStatesKey = "states"
Expand All @@ -306,11 +307,11 @@ func (i *openIDIdentifier) validateSessionCode(request *web.Request, code string
if !ok {
return false
}
states, ok := sessionStates.([]state)
states, ok := sessionStates.([]StateEntry)
if !ok {
return false
}
newstates := make([]state, 0, len(states))
newstates := make([]StateEntry, 0, len(states))
validated := false
for _, state := range states {
if state.TS.Add(stateTimeout).Before(now()) {
Expand All @@ -329,10 +330,10 @@ func (i *openIDIdentifier) validateSessionCode(request *web.Request, code string
func (i *openIDIdentifier) createSessionCode(request *web.Request, code string) {
sessionStates, ok := request.Session().Load(i.sessionCode(sessionStatesKey))
if !ok {
sessionStates = []state{}
sessionStates = []StateEntry{}
}
states := sessionStates.([]state)
states = append(states, state{
states := sessionStates.([]StateEntry)
states = append(states, StateEntry{
State: code,
TS: now(),
})
Expand Down

0 comments on commit 0c48898

Please sign in to comment.