{"record":{"id":"d36559e11c3b2b8b","repo":"ory/hydra","slug":"no-hydra-endpoint-is-configured","errorCode":null,"errorMessage":"No Hydra endpoint is configured","messagePattern":"No Hydra endpoint is configured","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"cmd/cmd_perform_device_flow.go","lineNumber":194,"sourceCode":"\t\treturn\n\t}\n\tuserCode, challenge := r.FormValue(\"user_code\"), r.FormValue(\"device_challenge\")\n\tif userCode == \"\" {\n\t\thttp.Error(w, \"user_code is required\", http.StatusBadRequest)\n\t\treturn\n\t}\n\tif challenge == \"\" {\n\t\thttp.Error(w, \"device_challenge is required\", http.StatusBadRequest)\n\t\treturn\n\t}\n\n\t// Accept the user code with a hand-rolled request instead of the generated\n\t// client: other modules in this repository compile this package against the\n\t// released hydra-client-go/v2 module, which predates the device\n\t// authorization API.\n\tcfg := s.cl.GetConfig()\n\tif len(cfg.Servers) == 0 {\n\t\thttp.Error(w, \"No Hydra endpoint is configured\", http.StatusInternalServerError)\n\t\treturn\n\t}\n\tacceptURL := strings.TrimSuffix(cfg.Servers[0].URL, \"/\") +\n\t\t\"/admin/oauth2/auth/requests/device/accept?device_challenge=\" + url.QueryEscape(challenge)\n\tbody, err := json.Marshal(map[string]string{\"user_code\": userCode})\n\tif err != nil {\n\t\thttp.Error(w, fmt.Sprintf(\"Failed to encode request body: %s\", err), http.StatusInternalServerError)\n\t\treturn\n\t}\n\treq, err := http.NewRequestWithContext(r.Context(), http.MethodPut, acceptURL, bytes.NewReader(body))\n\tif err != nil {\n\t\thttp.Error(w, fmt.Sprintf(\"Failed to create request: %s\", err), http.StatusInternalServerError)\n\t\treturn\n\t}\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\treq.Header.Set(\"Accept\", \"application/json\")\n\n\thc := cfg.HTTPClient","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/cmd/cmd_perform_device_flow.go#L176-L212","documentation":"POSTdevice accepts the user code with a hand-rolled HTTP request to Hydra's admin device-accept endpoint. It builds the URL from cfg.Servers[0]; when the generated client's config has no servers configured, it responds 500 'No Hydra endpoint is configured' rather than making a request to an invalid URL.","triggerScenarios":"The hydra client configuration was created without setting any server URL (cfg.Servers empty) before POSTdevice runs.","commonSituations":"HYDRA_ADMIN_URL (or equivalent config) not set; client constructed with the default configuration and SetServerURL/SetServers never called; environment variable misspelled or empty in the CLI invocation; config loading silently skipped in tests.","solutions":["Set the Hydra admin URL on the client config before starting the device flow (e.g. cfg.SetServerURL(...)) or set the corresponding environment variable","Verify the environment variable used to configure the client is exported and non-empty in the shell running the command","Check how the client is constructed in the CLI entrypoint and ensure the config is passed through to deviceSrv","Run with debug logging to confirm the resolved configuration"],"exampleFix":"// before\ncl := hydra.NewAPIClient(hydra.NewConfiguration())\n// after\ncfg := hydra.NewConfiguration()\ncfg.Servers = hydra.ServerConfigurations{{URL: \"http://127.0.0.1:4445\"}}\ncl := hydra.NewAPIClient(cfg)","handlingStrategy":"validation","validationCode":"cfg := s.cl.GetConfig()\nif len(cfg.Servers) == 0 || cfg.Servers[0].URL == \"\" {\n\treturn errors.New(\"hydra admin URL not configured\")\n}","typeGuard":"func hasServerURL(cfg *hydra.Configuration) bool {\n\treturn cfg != nil && len(cfg.Servers) > 0 && cfg.Servers[0].URL != \"\"\n}","tryCatchPattern":"if err != nil {\n\tlog.Printf(\"device accept request failed: %v\", err)\n\thttp.Error(w, \"failed to accept user code\", http.StatusBadGateway)\n\treturn\n}","preventionTips":["Always configure the Hydra admin server URL before constructing API handlers","Verify the HYDRA_ADMIN_URL-style env var at CLI startup, not at request time","Add a startup connectivity check against the configured admin endpoint","Fail fast with a clear message if cfg.Servers is empty instead of serving pages"],"tags":["configuration","device-flow","hydra"],"backgroundTag":"missing-server-url","analyzedSha":"4174065ffb052799890f7480f5360a877a67ffc1","analyzedAt":"2026-09-03T14:52:41.581Z","contentChangedAt":"2026-09-03T14:52:41.581Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}