netbirdio/netbird · error

failed to create request access token

Error message

failed to create request access token: %v

What it means

Fires in requestToken (called by WaitToken) when http.NewRequest cannot construct the POST to the token endpoint. Since the method, URL, and body are all locally derived, this practically means the configured TokenEndpoint URL failed to parse (e.g. malformed or empty providerConfig.TokenEndpoint), not a network problem.

Solutions

  1. Validate the TokenEndpoint URL in the provider configuration — it must be an absolute, parseable https:// URL
  2. Check the wrapped error: url.Parse failures name the offending URL
  3. Fix the configuration source (defaults, flags, or config file) supplying the endpoint rather than retrying, since a parse error is deterministic
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at client/internal/auth/device_flow.go:215 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/97893172fce1faff. Report an issue: GitHub.

Appendix: source

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

		return uri
	}

	query := parsedURL.Query()
	query.Set("login_hint", loginHint)
	parsedURL.RawQuery = query.Encode()

	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)

View on GitHub (pinned to 93e97f4bf1)