so today i tried to implement two factor authentication.
in my non 2fa flow i send a TokenEvent in a login auth request which works fine.
what i thought to do for 2fa is add a flag to the connection token after login to indicate 2fa is required which redirects to a 2fa page,
what I’d like to do is trigger a 2nd TokenEvent with an additional flag that indicates 2fa is validated after the right code has been entered, this will allow me to have access handles which can check if 2fa was required and validated.
the problem is that the 2nd TokenEvent does not seem to update the token connection information.
I’m pretty sure the problem is the way I’m adding the flag (dereferencing issues and all) but i thought I’d check to see if there are any known issues with triggering multiple TokenEvents on the same connection in order to modify the token attributes
//TotpCode is the code used to validate the user
type TotpCode struct {
Code string `json:"code"`
}
//validates a totp
func (th *TotpHandler) validateProviderTotp(r res.AuthRequest) {
var params TotpCode
r.ParseParams(¶ms )
var token Token
r.ParseToken(&token)
totp, err := th.validateTotp(token, params .Code)
if err != nil {
log.Error(err)
r.InvalidParams(fmt.Sprintf("There was a problem: %s", err))
return
}
if totp.valid == false {
r.TokenEvent(nil)
r.InvalidParams("Invalid Token!")
return
}
token.Totp = true
r.TokenEvent(token)//<---- this is where it seems to be failing, it sets here just fine, but other services when they get the token, totp is set to false
r.OK(map[string]string{
"redirect": "/home/index.html",
})