netbirdio/netbird · error

Failed to validate token

Error message

Failed to validate token

What it means

Fires in handleCallback when extractUserIDFromToken returns an empty userID — i.e. the token obtained from the code exchange could not be validated or yielded no user identity (missing/invalid ID token, unexpected claims, or an IdP verification failure). The handler responds with an error page; the message flags that authentication succeeded at the IdP but identity extraction failed.

Solutions

  1. Check extractUserIDFromToken internals: ID token verification, issuer/audience checks, and which claim is used for the user ID
  2. Confirm the IdP actually issues an ID token with the expected claims (e.g. email or sub) for this client
  3. Verify the provider's JWKS is reachable and keys have not rotated
  4. Restart the login flow; the extracted token may be from a misconfigured client
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at management/server/http/handlers/proxy/auth.go:99 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/07c07519633628c6. Report an issue: GitHub.

Appendix: source

Thrown at management/server/http/handlers/proxy/auth.go:99

		http.Error(w, "Failed to create OIDC provider", http.StatusInternalServerError)
		return
	}

	token, err := (&oauth2.Config{
		ClientID:    oidcConfig.ClientID,
		Endpoint:    provider.Endpoint(),
		RedirectURL: oidcConfig.CallbackURL,
	}).Exchange(r.Context(), r.URL.Query().Get("code"), oauth2.VerifierOption(codeVerifier))
	if err != nil {
		log.WithError(err).Error("Failed to exchange code for token")
		http.Error(w, "Failed to exchange code for token", http.StatusInternalServerError)
		return
	}

	userID := extractUserIDFromToken(r.Context(), provider, oidcConfig, token)
	if userID == "" {
		log.Error("Failed to extract user ID from OIDC token")
		http.Error(w, "Failed to validate token", http.StatusUnauthorized)
		return
	}

	// Group validation is performed by the proxy via ValidateSession gRPC call.
	// This allows the proxy to show 403 pages directly without redirect dance.

	sessionToken, err := h.proxyService.GenerateSessionToken(r.Context(), redirectURL.Hostname(), userID, auth.MethodOIDC)
	if err != nil {
		log.WithError(err).Error("Failed to create session token")
		redirectURL.Scheme = "https"
		query := redirectURL.Query()
		query.Set("error", "access_denied")
		query.Set("error_description", sessionTokenErrorDescription(err))
		redirectURL.RawQuery = query.Encode()
		http.Redirect(w, r, redirectURL.String(), http.StatusFound)
		return
	}

View on GitHub (pinned to 93e97f4bf1)