Skip to content

Commit

Permalink
chore: convert between local and remote password
Browse files Browse the repository at this point in the history
  • Loading branch information
sweatybridge committed Nov 28, 2024
1 parent 8036aef commit a2efba4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
9 changes: 1 addition & 8 deletions internal/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,13 +462,6 @@ EOF
formatMapForEnvConfig(utils.Config.Auth.Sms.TestOTP, &testOTP)
}

var password_requirements = map[config.PasswordRequirements]string{
"": "",
"letters_digits": "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:0123456789",
"lower_upper_letters_digits": "abcdefghijklmnopqrstuvwxyz:ABCDEFGHIJKLMNOPQRSTUVWXYZ:0123456789",
"lower_upper_letters_digits_symbols": "abcdefghijklmnopqrstuvwxyz:ABCDEFGHIJKLMNOPQRSTUVWXYZ:0123456789:!@#$%^&*()_+-=[]{};'\\\\:\"|<>?,./`~",
}

env := []string{
"API_EXTERNAL_URL=" + utils.Config.Api.ExternalUrl,

Expand Down Expand Up @@ -514,7 +507,7 @@ EOF
"GOTRUE_SMS_TEST_OTP=" + testOTP.String(),

fmt.Sprintf("GOTRUE_PASSWORD_MIN_LENGTH=%v", utils.Config.Auth.MinimumPasswordLength),
fmt.Sprintf("GOTRUE_PASSWORD_REQUIRED_CHARACTERS=%v", password_requirements[utils.Config.Auth.PasswordRequirements]),
fmt.Sprintf("GOTRUE_PASSWORD_REQUIRED_CHARACTERS=%v", utils.Config.Auth.PasswordRequirements.ToChar()),
fmt.Sprintf("GOTRUE_SECURITY_REFRESH_TOKEN_ROTATION_ENABLED=%v", utils.Config.Auth.EnableRefreshTokenRotation),
fmt.Sprintf("GOTRUE_SECURITY_REFRESH_TOKEN_REUSE_INTERVAL=%v", utils.Config.Auth.RefreshTokenReuseInterval),
fmt.Sprintf("GOTRUE_SECURITY_MANUAL_LINKING_ENABLED=%v", utils.Config.Auth.EnableManualLinking),
Expand Down
29 changes: 28 additions & 1 deletion pkg/config/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,30 @@ const (
LowerUpperLettersDigitsSymbols PasswordRequirements = "lower_upper_letters_digits_symbols"
)

func (r PasswordRequirements) ToChar() v1API.UpdateAuthConfigBodyPasswordRequiredCharacters {
switch r {
case LettersDigits:
return v1API.AbcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
case LowerUpperLettersDigits:
return v1API.AbcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567891
case LowerUpperLettersDigitsSymbols:
return v1API.AbcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567892
}
return v1API.Empty
}

func NewPasswordRequirement(c v1API.UpdateAuthConfigBodyPasswordRequiredCharacters) PasswordRequirements {
switch c {
case v1API.AbcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:
return LettersDigits
case v1API.AbcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567891:
return LowerUpperLettersDigits
case v1API.AbcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567892:
return LowerUpperLettersDigitsSymbols
}
return NoRequirements
}

type (
auth struct {
Enabled bool `toml:"enabled"`
Expand Down Expand Up @@ -204,7 +228,7 @@ func (a *auth) ToUpdateAuthConfigBody() v1API.UpdateAuthConfigBody {
DisableSignup: cast.Ptr(!a.EnableSignup),
ExternalAnonymousUsersEnabled: &a.EnableAnonymousSignIns,
PasswordMinLength: cast.UintToIntPtr(&a.MinimumPasswordLength),
PasswordRequiredCharacters: (*v1API.UpdateAuthConfigBodyPasswordRequiredCharacters)(&a.PasswordRequirements),
PasswordRequiredCharacters: cast.Ptr(a.PasswordRequirements.ToChar()),
}
a.Hook.toAuthConfigBody(&body)
a.MFA.toAuthConfigBody(&body)
Expand All @@ -224,6 +248,9 @@ func (a *auth) FromRemoteAuthConfig(remoteConfig v1API.AuthConfigResponse) {
a.EnableManualLinking = cast.Val(remoteConfig.SecurityManualLinkingEnabled, false)
a.EnableSignup = !cast.Val(remoteConfig.DisableSignup, false)
a.EnableAnonymousSignIns = cast.Val(remoteConfig.ExternalAnonymousUsersEnabled, false)
a.MinimumPasswordLength = cast.IntToUint(cast.Val(remoteConfig.PasswordMinLength, 0))
prc := cast.Val(remoteConfig.PasswordRequiredCharacters, "")
a.PasswordRequirements = NewPasswordRequirement(v1API.UpdateAuthConfigBodyPasswordRequiredCharacters(prc))
a.Hook.fromAuthConfig(remoteConfig)
a.MFA.fromAuthConfig(remoteConfig)
a.Sessions.fromAuthConfig(remoteConfig)
Expand Down

0 comments on commit a2efba4

Please sign in to comment.