@@ -51,12 +51,17 @@ func (c *HMACStrategy) Generate(ctx context.Context) (string, string, error) {
51
51
c .Lock ()
52
52
defer c .Unlock ()
53
53
54
- if len (c .Config .GetGlobalSecret (ctx )) < minimumSecretLength {
55
- return "" , "" , errors .Errorf ("secret for signing HMAC-SHA512/256 is expected to be 32 byte long, got %d byte" , len (c .Config .GetGlobalSecret (ctx )))
54
+ secrets , err := c .Config .GetGlobalSecret (ctx )
55
+ if err != nil {
56
+ return "" , "" , err
57
+ }
58
+
59
+ if len (secrets ) < minimumSecretLength {
60
+ return "" , "" , errors .Errorf ("secret for signing HMAC-SHA512/256 is expected to be 32 byte long, got %d byte" , len (secrets ))
56
61
}
57
62
58
63
var signingKey [32 ]byte
59
- copy (signingKey [:], c . Config . GetGlobalSecret ( ctx ) )
64
+ copy (signingKey [:], secrets )
60
65
61
66
entropy := c .Config .GetTokenEntropy (ctx )
62
67
if entropy < minimumEntropy {
@@ -86,11 +91,21 @@ func (c *HMACStrategy) Generate(ctx context.Context) (string, string, error) {
86
91
func (c * HMACStrategy ) Validate (ctx context.Context , token string ) (err error ) {
87
92
var keys [][]byte
88
93
89
- if len (c .Config .GetGlobalSecret (ctx )) > 0 {
90
- keys = append (keys , c .Config .GetGlobalSecret (ctx ))
94
+ secrets , err := c .Config .GetGlobalSecret (ctx )
95
+ if err != nil {
96
+ return err
97
+ }
98
+
99
+ rotatedSecrets , err := c .Config .GetRotatedGlobalSecrets (ctx )
100
+ if err != nil {
101
+ return err
102
+ }
103
+
104
+ if len (secrets ) > 0 {
105
+ keys = append (keys , secrets )
91
106
}
92
107
93
- keys = append (keys , c . Config . GetRotatedGlobalSecrets ( ctx ) ... )
108
+ keys = append (keys , rotatedSecrets ... )
94
109
for _ , key := range keys {
95
110
if err = c .validate (ctx , key , token ); err == nil {
96
111
return nil
0 commit comments