refactoring

This commit is contained in:
Bethuel
2023-04-15 03:44:42 +03:00
parent 53d78ad982
commit f7196cd9a5
5 changed files with 17 additions and 18 deletions

View File

@@ -80,8 +80,8 @@ type HttpServerConfig struct {
AuthKeysLocation string
// OIDCConfigEndpoint is the endpoint of an IDP manager to get OIDC configuration
OIDCConfigEndpoint string
// KeyRotationEnabled identifies the signing key is currently being rotated or not
KeyRotationEnabled bool
// IdpSignKeyRefreshEnabled identifies the signing key is currently being rotated or not
IdpSignKeyRefreshEnabled bool
}
// Host represents a Wiretrustee host (e.g. STUN, TURN, Signal)

View File

@@ -53,7 +53,7 @@ func NewServer(config *Config, accountManager AccountManager, peersUpdateManager
config.HttpConfig.AuthIssuer,
config.GetAuthAudiences(),
config.HttpConfig.AuthKeysLocation,
config.HttpConfig.KeyRotationEnabled,
config.HttpConfig.IdpSignKeyRefreshEnabled,
)
if err != nil {
return nil, status.Errorf(codes.Internal, "unable to create new jwt middleware, err: %v", err)

View File

@@ -68,7 +68,7 @@ type JWTValidator struct {
}
// NewJWTValidator constructor
func NewJWTValidator(issuer string, audienceList []string, keysLocation string, keyRotationEnabled bool) (*JWTValidator, error) {
func NewJWTValidator(issuer string, audienceList []string, keysLocation string, idpSignkeyRefreshEnabled bool) (*JWTValidator, error) {
keys, err := getPemKeys(keysLocation)
if err != nil {
return nil, err
@@ -94,13 +94,12 @@ func NewJWTValidator(issuer string, audienceList []string, keysLocation string,
}
// If keys are rotated, verify the keys prior to token validation
if keyRotationEnabled {
if idpSignkeyRefreshEnabled {
// If the keys are invalid, retrieve new ones
if !keys.stillValid() {
keys, err = getPemKeys(keysLocation)
if err != nil {
log.Errorf("cannot get JSONWebKey: %v", err)
log.Debugf("cannot get JSONWebKey: %v", err)
return nil, err
}
}