@@ -767,8 +767,15 @@ func LoadDirectory(configDir string) error {
767
767
// If at least one path was found we load the configuration files in the
768
768
// directory. We don't call override without config files because it will
769
769
// override the env vars previously set with a ".env", if one exists.
770
- if len (paths ) > 0 {
771
- if err := godotenv .Overload (paths ... ); err != nil {
770
+ return loadDirectoryPaths (paths ... )
771
+ }
772
+
773
+ func loadDirectoryPaths (p ... string ) error {
774
+ // If at least one path was found we load the configuration files in the
775
+ // directory. We don't call override without config files because it will
776
+ // override the env vars previously set with a ".env", if one exists.
777
+ if len (p ) > 0 {
778
+ if err := godotenv .Overload (p ... ); err != nil {
772
779
return err
773
780
}
774
781
}
@@ -811,7 +818,10 @@ func loadGlobal(config *GlobalConfiguration) error {
811
818
if err := config .Validate (); err != nil {
812
819
return err
813
820
}
821
+ return populateGlobal (config )
822
+ }
814
823
824
+ func populateGlobal (config * GlobalConfiguration ) error {
815
825
if config .Hook .PasswordVerificationAttempt .Enabled {
816
826
if err := config .Hook .PasswordVerificationAttempt .PopulateExtensibilityPoint (); err != nil {
817
827
return err
@@ -892,37 +902,9 @@ func (config *GlobalConfiguration) ApplyDefaults() error {
892
902
893
903
if len (config .JWT .Keys ) == 0 {
894
904
// transform the secret into a JWK for consistency
895
- privKey , err := jwk .FromRaw ([]byte (config .JWT .Secret ))
896
- if err != nil {
905
+ if err := config .applyDefaultsJWT ([]byte (config .JWT .Secret )); err != nil {
897
906
return err
898
907
}
899
- if config .JWT .KeyID != "" {
900
- if err := privKey .Set (jwk .KeyIDKey , config .JWT .KeyID ); err != nil {
901
- return err
902
- }
903
- }
904
- if privKey .Algorithm ().String () == "" {
905
- if err := privKey .Set (jwk .AlgorithmKey , jwt .SigningMethodHS256 .Name ); err != nil {
906
- return err
907
- }
908
- }
909
- if err := privKey .Set (jwk .KeyUsageKey , "sig" ); err != nil {
910
- return err
911
- }
912
- if len (privKey .KeyOps ()) == 0 {
913
- if err := privKey .Set (jwk .KeyOpsKey , jwk.KeyOperationList {jwk .KeyOpSign , jwk .KeyOpVerify }); err != nil {
914
- return err
915
- }
916
- }
917
- pubKey , err := privKey .PublicKey ()
918
- if err != nil {
919
- return err
920
- }
921
- config .JWT .Keys = make (JwtKeysDecoder )
922
- config .JWT .Keys [config .JWT .KeyID ] = JwkInfo {
923
- PublicKey : pubKey ,
924
- PrivateKey : privKey ,
925
- }
926
908
}
927
909
928
910
if config .JWT .ValidMethods == nil {
@@ -1036,6 +1018,45 @@ func (config *GlobalConfiguration) ApplyDefaults() error {
1036
1018
1037
1019
return nil
1038
1020
}
1021
+ func (config * GlobalConfiguration ) applyDefaultsJWT (secret []byte ) error {
1022
+ // transform the secret into a JWK for consistency
1023
+ privKey , err := jwk .FromRaw (secret )
1024
+ if err != nil {
1025
+ return err
1026
+ }
1027
+ return config .applyDefaultsJWTPrivateKey (privKey )
1028
+ }
1029
+
1030
+ func (config * GlobalConfiguration ) applyDefaultsJWTPrivateKey (privKey jwk.Key ) error {
1031
+ if config .JWT .KeyID != "" {
1032
+ if err := privKey .Set (jwk .KeyIDKey , config .JWT .KeyID ); err != nil {
1033
+ return err
1034
+ }
1035
+ }
1036
+ if privKey .Algorithm ().String () == "" {
1037
+ if err := privKey .Set (jwk .AlgorithmKey , jwt .SigningMethodHS256 .Name ); err != nil {
1038
+ return err
1039
+ }
1040
+ }
1041
+ if err := privKey .Set (jwk .KeyUsageKey , "sig" ); err != nil {
1042
+ return err
1043
+ }
1044
+ if len (privKey .KeyOps ()) == 0 {
1045
+ if err := privKey .Set (jwk .KeyOpsKey , jwk.KeyOperationList {jwk .KeyOpSign , jwk .KeyOpVerify }); err != nil {
1046
+ return err
1047
+ }
1048
+ }
1049
+ pubKey , err := privKey .PublicKey ()
1050
+ if err != nil {
1051
+ return err
1052
+ }
1053
+ config .JWT .Keys = make (JwtKeysDecoder )
1054
+ config .JWT .Keys [config .JWT .KeyID ] = JwkInfo {
1055
+ PublicKey : pubKey ,
1056
+ PrivateKey : privKey ,
1057
+ }
1058
+ return nil
1059
+ }
1039
1060
1040
1061
// Validate validates all of configuration.
1041
1062
func (c * GlobalConfiguration ) Validate () error {
0 commit comments