AlexxIT/go2rtc · error

failed to decode auth response

Error message

failed to decode auth response: %w

What it means

After a successful (200) auth response, JSON decoding of the body into AuthTokenResponse failed, meaning Ring returned a 200 whose body is not a valid token payload. Wraps the decoder error; login cannot complete.

Solutions

  1. Retry the auth request
  2. Capture the raw response body to identify API changes and update the struct
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at pkg/ring/api.go:311 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07). Data as JSON: /api/errors/8a7cab6f8c78a01f. Report an issue: GitHub.

Appendix: source

Thrown at pkg/ring/api.go:311

				prompt = fmt.Sprintf("sent to %s via %s", tfaResp.Phone, tfaResp.TSVState)
			}
			c.PromptFor2FA = fmt.Sprintf("Please enter the code %s", prompt)
		} else {
			c.PromptFor2FA = "Please enter the code sent to your text/email"
		}

		return nil, fmt.Errorf("2FA required")
	}

	// Handle errors
	if resp.StatusCode != http.StatusOK {
		body, _ := io.ReadAll(resp.Body)
		return nil, fmt.Errorf("auth request failed with status %d: %s", resp.StatusCode, string(body))
	}

	var authResp AuthTokenResponse
	if err := json.NewDecoder(resp.Body).Decode(&authResp); err != nil {
		return nil, fmt.Errorf("failed to decode auth response: %w", err)
	}

	// Refresh token and expiry
	c.authToken = &authResp
	c.authConfig = &AuthConfig{
		RT:  authResp.RefreshToken,
		HID: c.hardwareID,
	}
	// Set token expiry (1 minute before actual expiry)
	expiresIn := time.Duration(authResp.ExpiresIn-60) * time.Second
	c.tokenExpiry = time.Now().Add(expiresIn)

	c.RefreshToken = encodeAuthConfig(c.authConfig)
	if c.onTokenRefresh != nil {
		c.onTokenRefresh(c.RefreshToken)
	}

	// Refresh the cached client

View on GitHub (pinned to c245815e75)