From 5766e268000da0248edd61ba51f0dca60998b85f Mon Sep 17 00:00:00 2001 From: guisithos Date: Wed, 30 Oct 2024 16:22:47 -0300 Subject: [PATCH] Working on feature #31, revoke method ldap --- auth/strategies/ldap/ldap.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/auth/strategies/ldap/ldap.go b/auth/strategies/ldap/ldap.go index 63a89f1..b63821e 100644 --- a/auth/strategies/ldap/ldap.go +++ b/auth/strategies/ldap/ldap.go @@ -150,10 +150,24 @@ func New(cfg *Config, opts ...auth.Option) auth.Strategy { return basic.New(fn, opts...) } -// NewCached return strategy authenticate request using LDAP. -// The returned strategy, caches the authentication decision. -// New is similar to Basic.NewCached(). +// Add new type +type CachedLDAP struct { + auth.Strategy + cache auth.Cache +} + +// Implement token.Revokable interface +func (c *CachedLDAP) Revoke(hash string) error { + c.cache.Delete(hash) + return nil +} + +// Update NewCached to return our new type func NewCached(cfg *Config, c auth.Cache, opts ...auth.Option) auth.Strategy { fn := GetAuthenticateFunc(cfg, opts...) - return basic.NewCached(fn, c, opts...) + strategy := basic.NewCached(fn, c, opts...) + return &CachedLDAP{ + Strategy: strategy, + cache: c, + } }