netbirdio/netbird · error

failed to request access token with error

Error message

failed to request access token with error: %v

What it means

Fires in requestToken (called by WaitToken) when the HTTP POST to the token endpoint fails at the transport level. WaitToken polls repeatedly, so this commonly fires transiently on each poll tick during device flow — network drops, DNS failures, or an unreachable IdP — and the caller treats it as a poll iteration error rather than a fatal condition.

Solutions

  1. WaitToken already retries on the next poll interval; ensure transient errors are logged, not fatal
  2. Check DNS resolution and connectivity to the token endpoint host
  3. Verify the token endpoint is reachable from restricted networks (corporate proxies may block it)
  4. If the IdP endpoint moved, update the provider configuration
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at client/internal/auth/device_flow.go:221 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of netbirdio/netbird@93e97f4bf1 (2026-08-16). Data as JSON: /api/errors/9f630a0f4d69adaf. Report an issue: GitHub.

Appendix: source

Thrown at client/internal/auth/device_flow.go:221

	return parsedURL.String()
}

func (d *DeviceAuthorizationFlow) requestToken(info AuthFlowInfo) (TokenRequestResponse, error) {
	form := url.Values{}
	form.Add("client_id", d.providerConfig.ClientID)
	form.Add("grant_type", HostedGrantType)
	form.Add("device_code", info.DeviceCode)

	req, err := http.NewRequest("POST", d.providerConfig.TokenEndpoint, strings.NewReader(form.Encode()))
	if err != nil {
		return TokenRequestResponse{}, fmt.Errorf("failed to create request access token: %v", err)
	}
	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

	res, err := d.HTTPClient.Do(req)
	if err != nil {
		return TokenRequestResponse{}, fmt.Errorf("failed to request access token with error: %v", err)
	}

	defer func() {
		err := res.Body.Close()
		if err != nil {
			return
		}
	}()

	body, err := io.ReadAll(res.Body)
	if err != nil {
		return TokenRequestResponse{}, fmt.Errorf("failed reading access token response body with error: %v", err)
	}

	if res.StatusCode > 499 {
		return TokenRequestResponse{}, fmt.Errorf("access token response returned code: %s", string(body))
	}

View on GitHub (pinned to 93e97f4bf1)