netbirdio/netbird · error

request device code returned status

Error message

request device code returned status %d error: %s

What it means

Fires in RequestAuthInfo when the device-authorization endpoint (providerConfig.DeviceAuthEndpoint) responds with a non-200 status during the device code request. The IdP rejected the device authorization initiation — typically a misconfigured ClientID, wrong endpoint URL, or IdP-side outage. The response body is included in the message since IdPs return OAuth error payloads describing the rejection.

Solutions

  1. Verify ClientID and the DeviceAuthEndpoint URL in the provider configuration against the IdP's discovery document
  2. Inspect the error body in the message for the OAuth error code (e.g. invalid_client, unauthorized_client) and correct the cause
  3. Check network connectivity and whether an intercepting proxy or captive portal is altering responses
  4. Retry later if the IdP is temporarily unavailable; device flow setup is user-initiated so a surfaced error with guidance is acceptable
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at client/internal/auth/device_flow.go:165 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/29e0a0e2f4f2d92a. Report an issue: GitHub.

Appendix: source

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

		strings.NewReader(form.Encode()))
	if err != nil {
		return AuthFlowInfo{}, fmt.Errorf("creating request failed with error: %v", err)
	}
	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

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

	defer res.Body.Close()
	body, err := io.ReadAll(res.Body)
	if err != nil {
		return AuthFlowInfo{}, fmt.Errorf("reading body failed with error: %v", err)
	}

	if res.StatusCode != 200 {
		return AuthFlowInfo{}, fmt.Errorf("request device code returned status %d error: %s", res.StatusCode, string(body))
	}

	deviceCode := AuthFlowInfo{}
	err = json.Unmarshal(body, &deviceCode)
	if err != nil {
		return AuthFlowInfo{}, fmt.Errorf("unmarshaling response failed with error: %v", err)
	}

	// Fallback to the verification_uri if the IdP doesn't support verification_uri_complete
	if deviceCode.VerificationURIComplete == "" {
		deviceCode.VerificationURIComplete = deviceCode.VerificationURI
	}

	if d.providerConfig.LoginHint != "" {
		deviceCode.VerificationURIComplete = appendLoginHint(deviceCode.VerificationURIComplete, d.providerConfig.LoginHint)
		if deviceCode.VerificationURI != "" {
			deviceCode.VerificationURI = appendLoginHint(deviceCode.VerificationURI, d.providerConfig.LoginHint)
		}

View on GitHub (pinned to 93e97f4bf1)