Skip to content

Commit 5b6c26c

Browse files
committed
use go-redis version from commit
1 parent aab864a commit 5b6c26c

File tree

6 files changed

+38
-35
lines changed

6 files changed

+38
-35
lines changed

.githooks/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env bash
2+
3+
goimports -l -w . # includes go fmt
4+
golangci-lint run # includes golint, go vet

go.mod

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ module github.com/redis-developer/go-redis-entraid
22

33
go 1.18
44

5-
replace github.com/redis/go-redis/v9 => /Users/nedyalko.dyakov/go-redis/
6-
75
require (
8-
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.2
9-
github.com/redis/go-redis/v9 v9.7.1
6+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0-beta.1
7+
github.com/redis/go-redis/v9 v9.5.3-0.20250331212737-c248425ade4a
108
github.com/stretchr/testify v1.10.0
119
)
1210

go.sum

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.0 h1:g0EZJwz7xkXQiZAI5xi9f3WWFYBlX1CPTrR+NDToRkQ=
22
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.0/go.mod h1:XCW7KnZet0Opnr7HccfUw1PLc4CjHqpcaxW8DHklNkQ=
3-
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.2 h1:F0gBpfdPLGsw+nsgk6aqqkZS1jiixa5WwFe3fk/T3Ys=
4-
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.2/go.mod h1:SqINnQ9lVVdRlyC8cd1lCI0SdX4n2paeABd2K8ggfnE=
5-
github.com/Azure/azure-sdk-for-go/sdk/azidentity/cache v0.3.2 h1:yz1bePFlP5Vws5+8ez6T3HWXPmwOK7Yvq8QxDBD3SKY=
3+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0-beta.1 h1:iw4+KCeCoieuKodp1d5YhAa1TU/GgogCbw8RbGvsfLA=
4+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.8.0-beta.1/go.mod h1:AP8cDnDTGIVvayqKAhwzpcAyTJosXpvLYNmVFJb98x8=
5+
github.com/Azure/azure-sdk-for-go/sdk/azidentity/cache v0.2.3 h1:BAUsn6/icUFtvUalVwCO0+hSF7qgU9DwwcEfCvtILtw=
66
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 h1:ywEEhmNahHBihViHepv3xPBn1663uRv2t2q/ESv9seY=
77
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0/go.mod h1:iZDifYGJTIgIIkYRNWPENUnqx6bJ2xnSDFI2tjwZNuY=
88
github.com/AzureAD/microsoft-authentication-extensions-for-go/cache v0.1.1 h1:WJTmL004Abzc5wDB5VtZG2PJk5ndYDgVacGqfirKxjM=
99
github.com/AzureAD/microsoft-authentication-library-for-go v1.4.1 h1:8BKxhZZLX/WosEeoCvWysmKUscfa9v8LIPEEU0JjE2o=
1010
github.com/AzureAD/microsoft-authentication-library-for-go v1.4.1/go.mod h1:wP83P5OoQ5p6ip3ScPr0BAq0BvuPAvacpEuSzyouqAI=
11-
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
1211
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1312
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
14-
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
1513
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
1614
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
1715
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
@@ -25,6 +23,8 @@ github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmd
2523
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
2624
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2725
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
26+
github.com/redis/go-redis/v9 v9.5.3-0.20250331212737-c248425ade4a h1:R5xgk8m+CF7lVE0EGr+tLkT1eM3Zfd39BJfnANQqpKA=
27+
github.com/redis/go-redis/v9 v9.5.3-0.20250331212737-c248425ade4a/go.mod h1:huWgSWd8mW6+m0VPhJjSSQ+d6Nh1VICQ6Q5lHuCH/Iw=
2828
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
2929
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
3030
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=

install-git-hook.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
chmod ug+x ./.githooks/*
2+
git config core.hooksPath ./.githooks

token.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ import (
1313
// The token is valid for a limited time and must be refreshed periodically.
1414
type Token struct {
1515
// username is the username of the user.
16-
username string `json:"username"`
16+
username string
1717
// password is the password of the user.
18-
password string `json:"password"`
18+
password string
1919
// expiresOn is the expiration time of the token.
20-
expiresOn time.Time `json:"expires_on"`
20+
expiresOn time.Time
2121
// ttl is the time to live of the token.
22-
ttl int64 `json:"ttl"`
22+
ttl int64
2323
// rawToken is the authentication token.
24-
rawToken string `json:"raw_token"`
24+
rawToken string
2525
// receivedAt is the time when the token was received.
26-
receivedAt time.Time `json:"received_at"`
26+
receivedAt time.Time
2727
}
2828

2929
// BasicAuth returns the username and password for basic authentication.

token_manager.go

+19-20
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ var defaultIdentityProviderResponseParser = func(response IdentityProviderRespon
142142
if expiresOn.Before(time.Now()) {
143143
return nil, fmt.Errorf("expires on is in the past")
144144
}
145-
if expiresOn.Sub(time.Now()) < MinTokenTTL {
145+
if time.Until(expiresOn) < MinTokenTTL {
146146
return nil, fmt.Errorf("expires on is less than minimum token TTL")
147147
}
148148
// parse token as jwt token and get claims
@@ -153,7 +153,7 @@ var defaultIdentityProviderResponseParser = func(response IdentityProviderRespon
153153
rawToken,
154154
expiresOn,
155155
time.Now().UTC(),
156-
int64(expiresOn.Sub(time.Now()).Seconds()),
156+
int64(time.Until(expiresOn).Seconds()),
157157
), nil
158158
}
159159

@@ -309,6 +309,7 @@ func (e *entraidTokenManager) Start(listener TokenListener) (cancelFunc, error)
309309
return
310310
case <-time.After(e.durationToRenewal()):
311311
// Token is about to expire, refresh it
312+
delay := time.Duration(e.retryOptions.InitialDelayMs) * time.Millisecond
312313
for i := 0; i < e.retryOptions.MaxAttempts; i++ {
313314
select {
314315
case <-e.closed:
@@ -325,30 +326,28 @@ func (e *entraidTokenManager) Start(listener TokenListener) (cancelFunc, error)
325326
// check if err is retryable
326327
if e.retryOptions.IsRetryable(err) {
327328
// retryable error, continue to next attempt
329+
// Exponential backoff
330+
if i == e.retryOptions.MaxAttempts-1 {
331+
// last attempt, call OnTokenError
332+
listener.OnTokenError(err)
333+
return
334+
}
335+
336+
if delay < time.Duration(e.retryOptions.MaxDelayMs)*time.Millisecond {
337+
delay = time.Duration(float64(delay) * e.retryOptions.BackoffMultiplier)
338+
}
339+
340+
time.Sleep(delay)
341+
342+
if delay > time.Duration(e.retryOptions.MaxDelayMs)*time.Millisecond {
343+
delay = time.Duration(e.retryOptions.MaxDelayMs) * time.Millisecond
344+
}
328345
continue
329346
} else {
330347
// not retryable
331348
listener.OnTokenError(err)
332349
return
333350
}
334-
335-
// check if max attempts reached
336-
if i == e.retryOptions.MaxAttempts-1 {
337-
listener.OnTokenError(err)
338-
return
339-
}
340-
341-
// Exponential backoff
342-
delay := time.Duration(e.retryOptions.InitialDelayMs) * time.Millisecond
343-
if delay < time.Duration(e.retryOptions.MaxDelayMs)*time.Millisecond {
344-
delay = time.Duration(float64(delay) * e.retryOptions.BackoffMultiplier)
345-
}
346-
347-
time.Sleep(delay)
348-
349-
if delay > time.Duration(e.retryOptions.MaxDelayMs)*time.Millisecond {
350-
delay = time.Duration(e.retryOptions.MaxDelayMs) * time.Millisecond
351-
}
352351
}
353352
}
354353
}

0 commit comments

Comments
 (0)