@@ -3,7 +3,6 @@ package main
33import (
44 "fmt"
55 "net/http"
6- "os"
76 "strings"
87
98 "github.com/golang-jwt/jwt"
@@ -66,14 +65,16 @@ func (opts *ServerAuthOptions) createAuthMiddleware(
6665
6766 switch {
6867 case opts .RSAPublicKeyFilePath != "" :
68+ keyReader := readFileWithStatCache (opts .RSAPublicKeyFilePath )
69+
6970 jwtParser .ValidMethods = append (
7071 jwtParser .ValidMethods ,
7172 jwt .SigningMethodRS256 .Name ,
7273 jwt .SigningMethodRS384 .Name ,
7374 jwt .SigningMethodRS512 .Name ,
7475 )
7576 jwtKeyFunc = func (t * jwt.Token ) (interface {}, error ) {
76- b , err := os . ReadFile ( opts . RSAPublicKeyFilePath )
77+ b , err := keyReader ( )
7778 if err != nil {
7879 return nil , err
7980 }
@@ -85,14 +86,16 @@ func (opts *ServerAuthOptions) createAuthMiddleware(
8586 return v , nil
8687 }
8788 case opts .TokenFilePath != "" :
89+ tokenReader := readFileWithStatCache (opts .TokenFilePath )
90+
8891 jwtParser .ValidMethods = append (
8992 jwtParser .ValidMethods ,
9093 jwt .SigningMethodHS256 .Name ,
9194 jwt .SigningMethodHS384 .Name ,
9295 jwt .SigningMethodHS512 .Name ,
9396 )
9497 jwtKeyFunc = func (t * jwt.Token ) (interface {}, error ) {
95- b , err := os . ReadFile ( opts . TokenFilePath )
98+ b , err := tokenReader ( )
9699 if err != nil {
97100 return nil , err
98101 }
0 commit comments