AlexxIT/go2rtc · error

failed to marshal auth request

Error message

failed to marshal auth request: %w

What it means

json.Marshal of the OAuth grant_data map (password or refresh-token grant for the Ring API) failed, which practically only happens with unsupported value types in the map. Wraps the marshaling error; the auth request is never sent.

Solutions

  1. Treat as an internal bug: the grant data contains only strings and cannot normally fail to marshal
  2. Report the issue with the grantData contents
Defensive patterns

Strategy: try-catch

When it happens

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

Common situations: See trigger scenarios.


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

Appendix: source

Thrown at pkg/ring/api.go:252

		}
	} else {
		authEmail, ok := c.auth.(EmailAuth)
		if !ok {
			return nil, fmt.Errorf("invalid auth type for email authentication")
		}
		grantData = map[string]string{
			"grant_type": "password",
			"username":   authEmail.Email,
			"password":   authEmail.Password,
		}
	}

	grantData["client_id"] = "ring_official_android"
	grantData["scope"] = "client"

	body, err := json.Marshal(grantData)
	if err != nil {
		return nil, fmt.Errorf("failed to marshal auth request: %w", err)
	}

	req, err := http.NewRequest("POST", oauthURL, bytes.NewReader(body))
	if err != nil {
		return nil, err
	}

	req.Header.Set("Content-Type", "application/json")
	req.Header.Set("Accept", "application/json")
	req.Header.Set("hardware_id", c.hardwareID)
	req.Header.Set("User-Agent", "android:com.ringapp")
	req.Header.Set("2fa-support", "true")
	if twoFactorAuthCode != "" {
		req.Header.Set("2fa-code", twoFactorAuthCode)
	}

	resp, err := c.httpClient.Do(req)
	if err != nil {

View on GitHub (pinned to c245815e75)