Skip to content

Commit fcb4586

Browse files
refactor: improve error messages in M2M config loading for clarity
Jira Ticket: https://linuxfoundation.atlassian.net/browse/LFXV2-501 Assisted by [Claude Code](https://claude.ai/code) Signed-off-by: Mauricio Zanetti Salomao <mauriciozanetti86@gmail.com>
1 parent 2b37db0 commit fcb4586

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

internal/infrastructure/auth0/token.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,23 +142,23 @@ func (tm *TokenManager) GetTokenInfo() (*TokenInfo, error) {
142142
func loadM2MConfigFromEnv(ctx context.Context, config Config) (m2mConfig, error) {
143143
clientID := os.Getenv(constants.Auth0M2MClientIDEnvKey)
144144
if clientID == "" {
145-
return m2mConfig{}, errors.NewUnexpected("AUTH0_M2M_CLIENT_ID is required")
145+
return m2mConfig{}, errors.NewUnexpected(constants.Auth0M2MClientIDEnvKey + " is required")
146146
}
147147

148148
audience := os.Getenv(constants.Auth0AudienceEnvKey)
149149
if audience == "" {
150-
return m2mConfig{}, errors.NewUnexpected("AUTH0_AUDIENCE is required")
150+
return m2mConfig{}, errors.NewUnexpected(constants.Auth0AudienceEnvKey + " is required")
151151
}
152152

153153
// private key is base64 encoded
154154
privateKey := os.Getenv(constants.Auth0M2MPrivateBase64KeyEnvKey)
155155
if privateKey == "" {
156-
return m2mConfig{}, errors.NewUnexpected("AUTH0_M2M_PRIVATE_BASE64_KEY is required")
156+
return m2mConfig{}, errors.NewUnexpected(constants.Auth0M2MPrivateBase64KeyEnvKey + " is required")
157157
}
158158

159159
decoded, err := base64.StdEncoding.DecodeString(privateKey)
160160
if err != nil {
161-
return m2mConfig{}, errors.NewUnexpected("failed to base64-decode AUTH0_M2M_PRIVATE_BASE64_KEY", err)
161+
return m2mConfig{}, errors.NewUnexpected("failed to base64-decode "+constants.Auth0M2MPrivateBase64KeyEnvKey, err)
162162
}
163163
privateKey = string(decoded)
164164
//
@@ -222,12 +222,12 @@ func NewM2MTokenManager(ctx context.Context, config Config) (*TokenManager, erro
222222
func NewProfileClientAuthConfig(ctx context.Context, domain string) (*authentication.Authentication, error) {
223223
clientID := os.Getenv(constants.Auth0LFXProfileClientIDEnvKey)
224224
if clientID == "" {
225-
return nil, errors.NewUnexpected("AUTH0_LFX_PROFILE_CLIENT_ID is required for email linking flow")
225+
return nil, errors.NewUnexpected(constants.Auth0LFXProfileClientIDEnvKey + " is required for email linking flow")
226226
}
227227

228228
clientSecret := os.Getenv(constants.Auth0LFXProfileClientSecretEnvKey)
229229
if clientSecret == "" {
230-
return nil, errors.NewUnexpected("AUTH0_LFX_PROFILE_CLIENT_SECRET is required for email linking flow")
230+
return nil, errors.NewUnexpected(constants.Auth0LFXProfileClientSecretEnvKey + " is required for email linking flow")
231231
}
232232

233233
// Create Auth0 authentication client with client secret

0 commit comments

Comments
 (0)