Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add auth test OTP configuration support #1446

Merged
merged 3 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions internal/start/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
_ "embed"
"encoding/json"
"errors"
"fmt"
"os"
Expand Down Expand Up @@ -345,6 +346,13 @@ EOF

// Start GoTrue.
if utils.Config.Auth.Enabled && !isContainerExcluded(utils.GotrueImage, excluded) {
var testOTP bytes.Buffer
if len(utils.Config.Auth.Sms.TestOTP) > 0 {
encoder := json.NewEncoder(&testOTP)
if err := encoder.Encode(utils.Config.Auth.Sms.TestOTP); err != nil {
return err
}
}
env := []string{
fmt.Sprintf("API_EXTERNAL_URL=http://localhost:%v", utils.Config.Api.Port),

Expand Down Expand Up @@ -387,6 +395,7 @@ EOF
"GOTRUE_SMS_OTP_EXP=6000",
"GOTRUE_SMS_OTP_LENGTH=6",
"GOTRUE_SMS_TEMPLATE=Your code is {{ .Code }}",
"GOTRUE_SMS_TEST_OTP=" + testOTP.String(),

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),
Expand Down Expand Up @@ -789,6 +798,7 @@ EOF
started = append(started, utils.PoolerId)
}

p.Send(utils.StatusMsg("Waiting for health checks..."))
return reset.WaitForServiceReady(ctx, started)
}

Expand Down
1 change: 1 addition & 0 deletions internal/utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ type (
Messagebird messagebirdConfig `toml:"messagebird" mapstructure:"messagebird"`
Textlocal textlocalConfig `toml:"textlocal" mapstructure:"textlocal"`
Vonage vonageConfig `toml:"vonage" mapstructure:"vonage"`
TestOTP map[string]string `toml:"test_otp"`
}

twilioConfig struct {
Expand Down
4 changes: 4 additions & 0 deletions internal/utils/templates/init_config.test.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ enable_signup = true
# If enabled, users need to confirm their phone number before signing in.
enable_confirmations = false

# Use pre-defined map of phone number to OTP for testing.
[auth.sms.test_otp]
4152127777 = "123456"

# Configure one of the supported SMS providers: `twilio`, `twilio_verify`, `messagebird`, `textlocal`, `vonage`.
[auth.sms.twilio]
enabled = true
Expand Down
4 changes: 4 additions & 0 deletions internal/utils/templates/init_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ enable_signup = true
# If enabled, users need to confirm their phone number before signing in.
enable_confirmations = false

# Use pre-defined map of phone number to OTP for testing.
[auth.sms.test_otp]
# 4152127777 = "123456"

# Configure one of the supported SMS providers: `twilio`, `twilio_verify`, `messagebird`, `textlocal`, `vonage`.
[auth.sms.twilio]
enabled = false
Expand Down