@@ -10,6 +10,8 @@ import (
10
10
11
11
// ExtensionKey represents a key for the password in info extensions.
12
12
// Typically used when basic strategy cache the authentication decisions.
13
+ //
14
+ // Deprecated: No longer used.
13
15
const ExtensionKey = "x-go-guardian-basic-password"
14
16
15
17
// NewCached return new auth.Strategy.
@@ -26,6 +28,11 @@ func NewCached(f AuthenticateFunc, cache auth.Cache, opts ...auth.Option) auth.S
26
28
return New (cb .authenticate , opts ... )
27
29
}
28
30
31
+ type entry struct {
32
+ password string
33
+ info auth.Info
34
+ }
35
+
29
36
type cachedBasic struct {
30
37
fn AuthenticateFunc
31
38
comparator Comparator
@@ -42,18 +49,12 @@ func (c *cachedBasic) authenticate(ctx context.Context, r *http.Request, userNam
42
49
return c .authenticatAndHash (ctx , r , hash , userName , pass )
43
50
}
44
51
45
- if _ , ok := v .(auth.Info ); ! ok {
46
- return nil , auth .NewTypeError ("strategies/basic:" , (* auth .Info )(nil ), v )
47
- }
48
-
49
- info := v .(auth.Info )
50
- ext := info .GetExtensions ()
51
-
52
- if ! ext .Has (ExtensionKey ) {
53
- return c .authenticatAndHash (ctx , r , hash , userName , pass )
52
+ ent , ok := v .(entry )
53
+ if ! ok {
54
+ return nil , auth .NewTypeError ("strategies/basic:" , entry {}, v )
54
55
}
55
56
56
- return info , c .comparator .Compare (ext . Get ( ExtensionKey ) , pass )
57
+ return ent . info , c .comparator .Compare (ent . password , pass )
57
58
}
58
59
59
60
func (c * cachedBasic ) authenticatAndHash (ctx context.Context , r * http.Request , hash string , userName , pass string ) (auth.Info , error ) { //nolint:lll
@@ -63,8 +64,11 @@ func (c *cachedBasic) authenticatAndHash(ctx context.Context, r *http.Request, h
63
64
}
64
65
65
66
hashedPass , _ := c .comparator .Hash (pass )
66
- info .GetExtensions ().Set (ExtensionKey , hashedPass )
67
- c .cache .Store (hash , info )
67
+ ent := entry {
68
+ password : hashedPass ,
69
+ info : info ,
70
+ }
71
+ c .cache .Store (hash , ent )
68
72
69
73
return info , nil
70
74
}
0 commit comments