AlexxIT/go2rtc · error

failed to create auth request

Error message

failed to create auth request: %w

What it means

Returned when http.NewRequest fails while building the POST to Ring's OAuth token endpoint. In practice this happens only if the OAuth URL is malformed (unparseable URL), since the body is a valid bytes.Reader.

Solutions

  1. Check the wrapped error (url.Parse error) for the malformed URL detail
  2. Verify the OAuth endpoint URL configuration (no empty or garbled value)
  3. Ensure any base-URL override is a valid absolute http(s) URL

Example fix

// before
cfg.OAuthURL = "" // yields unparsable request URL
// after
cfg.OAuthURL = "https://oauth.ring.com/oauth/token"
Defensive patterns

Strategy: validation

Validate before calling

if u, err := url.Parse(oauthURL); err != nil || u.Scheme == "" || u.Host == "" {
    return fmt.Errorf("invalid oauth url %q", oauthURL)
}

Prevention

When it happens

Trigger: oauthURL is empty, malformed, or contains invalid characters so http.NewRequest cannot parse it.

Common situations: Misconfigured base URL / OAuth endpoint override; empty config value substituted for the OAuth URL; environment-specific URL rewrites with bad characters.

Understand the failure class

Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.

Related errors


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

Appendix: source

Thrown at pkg/ring/api.go:606

	var grantData = map[string]string{
		"grant_type":    "refresh_token",
		"refresh_token": c.authConfig.RT,
	}

	// Add common fields
	grantData["client_id"] = "ring_official_android"
	grantData["scope"] = "client"

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

	req, err := http.NewRequest("POST", oauthURL, bytes.NewReader(body))
	if err != nil {
		return fmt.Errorf("failed to create auth request: %w", 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")

	resp, err := c.httpClient.Do(req)
	if err != nil {
		return fmt.Errorf("auth request failed: %w", err)
	}
	defer resp.Body.Close()

	if resp.StatusCode == http.StatusPreconditionFailed {
		return fmt.Errorf("2FA required. Please see documentation for handling 2FA")
	}

View on GitHub (pinned to c245815e75)