Ensure JWT not empty

This commit is contained in:
Daniel Ponte 2022-12-17 15:17:05 -05:00
parent 86abb0b618
commit 3038750206
3 changed files with 22 additions and 2 deletions

View file

@ -34,6 +34,10 @@ type RefreshToken struct {
Version *string `json:"version"`
}
func (rt *RefreshToken) IsValid() bool {
return rt.JWTKey != ""
}
type AccessSessionStore struct {
s map[AccessTokenID]*AccessToken
lastCull time.Time

View file

@ -69,6 +69,22 @@ func (a *Authenticator) newAuthStore(s storage.Store) (as *authStore, err error)
}
}
// remove invalid RefreshTokens
i := 0
for _, rt := range as.Refresh {
if rt.IsValid() {
as.Refresh[i] = rt
i++
}
}
// don't leak memory
for j := i; j < len(as.Refresh); j++ {
as.Refresh[j] = RefreshToken{}
}
as.Refresh = as.Refresh[:i]
return
}

View file

@ -60,7 +60,7 @@ type (
}
Handler interface {
Base() FlowHandler
BaseHandler() FlowHandler
FlowID() FlowID
flowCtime() time.Time
@ -105,7 +105,7 @@ type FlowHandler struct {
func (f *FlowHandler) Step() Step { return f.curStep }
func (f *FlowHandler) Base() FlowHandler { return *f }
func (f *FlowHandler) BaseHandler() FlowHandler { return *f }
func (f *FlowHandler) FlowID() FlowID {
return f.ID