gofr-dev/gofr · warning

errMessage (dynamic credential validation error)

Error message

errMessage (dynamic credential validation error)

What it means

In the mock OAuth server (mock_oauth_server.go:57), validateCredentials returns an error message and HTTP status; when credentials are invalid the handler responds with http.Error(w, errMessage, statusCode). The exact body text is dynamic — it comes from the server's credential validator (e.g. "invalid client credentials"), so this entry represents whatever message your validateCredentials implementation produced.

Source

Thrown at pkg/gofr/service/mock_oauth_server.go:57

		testURL:       "/test",
		audienceClaim: config.EndpointParams.Get("aud"),
	}

	server.clientID = config.ClientID
	server.clientSecret = config.ClientSecret

	privateKey, err := rsa.GenerateKey(rand.Reader, privateKeyBits)
	require.NoError(t, err, "failed to generate private key, aborting")

	server.privateKey = privateKey

	mux := http.NewServeMux()

	mux.HandleFunc(server.tokenURL, func(w http.ResponseWriter, r *http.Request) {
		errMessage, statusCode := server.validateCredentials(r)

		if statusCode != http.StatusOK {
			http.Error(w, errMessage, statusCode)
			return
		}

		accessToken, err := server.generateToken(getClaims(r))
		if err != nil {
			http.Error(w, "Unable to generate token", http.StatusInternalServerError)
			return
		}

		// Prepare the JSON response
		w.Header().Set("Content-Type", "application/json")
		w.Header().Set("Cache-Control", "no-store")
		w.Header().Set("Pragma", "no-cache")

		tokenResponse := map[string]any{
			"access_token": accessToken,
			"token_type":   "Bearer",
			"expires_in":   3600,         // Expires in 1 hour

View on GitHub (pinned to 187eb24962)

Solutions

  1. Use the client credentials returned by the mock server's setup (oAuthConfigForTests) in the client under test.
  2. Inspect validateCredentials in your mock server setup to see which credential fields it compares and align the test request.
  3. Regenerate test credentials if generateRandomString output was persisted/staled across runs.
  4. Log the request's credentials in the mock to diff expected vs actual.
Defensive patterns

Strategy: validation

Validate before calling

// client side, before requesting a token
if clientID == "" || clientSecret == "" {
	return errors.New("missing client credentials for mock OAuth server")
}

Try / catch

resp, err := client.Token(ctx, creds)
if err != nil {
	log.Printf("mock token endpoint said: %s", readBody(resp)) // dynamic validator message
	return fmt.Errorf("credential rejected by mock server: %w", err)
}

Prevention

When it happens

Trigger: A test client POSTs to the mock server's token URL with a client ID/secret (or other credentials) that fail the server's validateCredentials check; the response carries that validator's message with a non-200 status.

Common situations: Using oAuthConfigForTests-generated credentials against a differently configured mock server; stale credentials cached in test fixtures; pointing a real client at the mock token endpoint with production credentials.

Related errors


AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01). Data as JSON: /api/errors/d8d92e7261338ccb. Report an issue: GitHub.