Skip to content
This repository was archived by the owner on May 24, 2024. It is now read-only.

Commit fa424bc

Browse files
Ajinkya Naharajinkyan83
authored andcommitted
DA-4596: remove custom expiry logic added to avoid frequent oauth0 calls
Signed-off-by: Ajinkya Nahar <[email protected]>
1 parent 8167d90 commit fa424bc

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

auth0/jwks.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ func (a *ClientProvider) createAuthJwks(cert string) error {
4444

4545
func (a *ClientProvider) getPemCert(token *jwt.Token, refreshJwks bool) (string, error) {
4646
cert := ""
47-
cert, expired, err := a.getCachedJwks()
47+
cert, err := a.getCachedJwks()
4848
if err != nil {
4949
return cert, err
5050
}
5151

52-
// check if the cache expired as well is not invoked via refresh token cron
53-
if refreshJwks || expired {
52+
// check if the refresh jwks cache flag coming from the refresh cron is set to true
53+
if refreshJwks {
5454
_, resp, err := a.httpClient.Request(fmt.Sprintf("%s/oauth/.well-known/jwks.json", a.AuthURL), "GET", nil, nil, nil)
5555
if err != nil {
5656
return cert, err
@@ -82,8 +82,7 @@ func (a *ClientProvider) getPemCert(token *jwt.Token, refreshJwks bool) (string,
8282
return cert, nil
8383
}
8484

85-
func (a *ClientProvider) getCachedJwks() (string, bool, error) {
86-
expired := true
85+
func (a *ClientProvider) getCachedJwks() (string, error) {
8786
res, err := a.esClient.Search(strings.TrimSpace(auth0JwksCache+a.Environment), searchJwksQuery)
8887
if err != nil {
8988
go func() {
@@ -92,27 +91,23 @@ func (a *ClientProvider) getCachedJwks() (string, bool, error) {
9291
fmt.Println("Err: send to slack: ", err)
9392
}()
9493

95-
return "", expired, err
94+
return "", err
9695
}
9796

9897
var e ESJwksSchema
9998
err = json.Unmarshal(res, &e)
10099
if err != nil {
101100
log.Println("repository: GetOauthJwks: could not unmarshal the data", err)
102-
return "", expired, err
101+
return "", err
103102
}
104103

105104
if len(e.Hits.Hits) > 0 {
106105
data := e.Hits.Hits[0]
107-
// compare current time v/s existing cached time + 30 mins
108-
if data.Source.CreatedAt.Add(30*time.Minute).Unix() > time.Now().UTC().Unix() {
109-
expired = false
110-
}
111106

112-
return data.Source.Jwks, expired, nil
107+
return data.Source.Jwks, nil
113108
}
114109

115-
return "", expired, errors.New("GetJwks: could not find the associated jwks")
110+
return "", errors.New("GetJwks: could not find the associated jwks")
116111
}
117112

118113
var searchJwksQuery = map[string]interface{}{

0 commit comments

Comments
 (0)