Skip to content

Commit

Permalink
fix: token endpoint rate limiting
Browse files Browse the repository at this point in the history
  • Loading branch information
nsklikas committed Mar 28, 2024
1 parent a42695b commit f5008d6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions handler/rfc8628/strategy_hmacsha.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@ func (h *DefaultDeviceStrategy) ShouldRateLimit(context context.Context, code st
timer.NotUntil = h.getExpirationTime(context, 1)
exp, err := h.serializeExpiration(timer)
if err != nil {
return false, err
return false, errorsx.WithStack(fosite.ErrServerError.WithHintf("Failed to serialize expiration struct %s", err))
}
// Set the expiration time as value, and use the lifespan of the device code as TTL.
h.RateLimiterCache.Set(keyBytes, exp, int(h.Config.GetDeviceAndUserCodeLifespan(context)))
h.RateLimiterCache.Set(keyBytes, exp, int(h.Config.GetDeviceAndUserCodeLifespan(context).Seconds()))
return false, nil
}

Expand All @@ -199,9 +199,9 @@ func (h *DefaultDeviceStrategy) ShouldRateLimit(context context.Context, code st
expiration.NotUntil = h.getExpirationTime(context, expiration.Counter)
exp, err := h.serializeExpiration(expiration)
if err != nil {
return false, err
return false, errorsx.WithStack(fosite.ErrServerError.WithHintf("Failed to serialize expiration struct %s", err))
}
h.RateLimiterCache.Set(keyBytes, exp, int(h.Config.GetDeviceAndUserCodeLifespan(context)))
h.RateLimiterCache.Set(keyBytes, exp, int(h.Config.GetDeviceAndUserCodeLifespan(context).Seconds()))
return false, nil
}

Expand All @@ -210,9 +210,9 @@ func (h *DefaultDeviceStrategy) ShouldRateLimit(context context.Context, code st
expiration.Counter += 1
exp, err := h.serializeExpiration(expiration)
if err != nil {
return false, err
return false, errorsx.WithStack(fosite.ErrServerError.WithHintf("Failed to serialize expiration struct %s", err))
}
h.RateLimiterCache.Set(keyBytes, exp, int(h.Config.GetDeviceAndUserCodeLifespan(context)))
h.RateLimiterCache.Set(keyBytes, exp, int(h.Config.GetDeviceAndUserCodeLifespan(context).Seconds()))

return true, nil
}
Expand Down

0 comments on commit f5008d6

Please sign in to comment.