{"record":{"id":"4f3aabc4f767e20a","repo":"wtfutil/wtf","slug":"authentication-failed-please-log-in-to-spotify-by","errorCode":null,"errorMessage":"authentication failed! Please log in to Spotify by visiting the following page in your browser: ","messagePattern":"authentication failed! Please log in to Spotify by visiting the following page in your browser: ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/spotifyweb/widget.go","lineNumber":135,"sourceCode":"\t// This mostly likely has to do with the fact that the URL includes some very special characters that no terminal likes.\n\t// The only solution would be to include quotes in the command, which is why I do here, but it doesn't work.\n\t//\n\t// If inconvenient, I'll remove this option and save the URL in a file or some other method.\n\tutils.OpenFile(`\"` + authURL + `\"`)\n\n\twidget.settings.RefreshInterval = 5 * time.Second\n\n\twidget.initializeKeyboardControls()\n\n\twidget.View.SetWrap(true)\n\twidget.View.SetWordWrap(true)\n\n\treturn &widget\n}\n\nfunc (w *Widget) refreshSpotifyInfos() error {\n\tif w.client == nil || w.playerState == nil {\n\t\treturn errors.New(\"authentication failed! Please log in to Spotify by visiting the following page in your browser: \" + authURL)\n\t}\n\tvar err error\n\tw.playerState, err = w.client.PlayerState()\n\tif err != nil {\n\t\treturn errors.New(\"extracting player state failed! Please refresh or restart WTF\")\n\t}\n\tw.Album = fmt.Sprint(w.playerState.Item.Album.Name)\n\tartists := \"\"\n\tfor _, artist := range w.playerState.Item.Artists {\n\t\tartists += artist.Name + \", \"\n\t}\n\tartists = artists[:len(artists)-2]\n\tw.Artists = artists\n\tw.Title = fmt.Sprint(w.playerState.Item.Name)\n\tw.TrackNumber = w.playerState.Item.TrackNumber\n\tif w.playerState.Playing {\n\t\tw.Status = \"Playing\"\n\t} else {","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/wtfutil/wtf/blob/bb838c1ccb0f0f3223690df44afdec663d622881/modules/spotifyweb/widget.go#L117-L153","documentation":"The spotifyweb widget requires an authenticated Spotify client and a player state before it can poll the API. If either the OAuth client (w.client) or the cached player state (w.playerState) is nil, the widget cannot talk to Spotify and returns this error, whose message includes the authURL so the user can complete the browser-based OAuth flow.","triggerScenarios":"Widget.Refresh -> refreshSpotifyInfos() is called while w.client == nil or w.playerState == nil. This is the state before the user has ever completed the Spotify OAuth login, or after the token/session data was not loaded.","commonSituations":"First run of the spotifyweb module without logging in; deleted or missing OAuth token cache; Spotify app credentials (client ID/secret) misconfigured so authentication never completes; running WTFUtil headless where the browser login flow cannot be finished.","solutions":["Open the URL printed in the error message in a browser and complete the Spotify OAuth login, then restart/refresh WTFUtil.","Verify the spotifyweb module settings: valid clientID and clientSecret (or secretKey) in the WTFUtil config.","Check that the token cache file for the module exists and is writable so the session persists across restarts.","Ensure the Spotify redirect URI configured in the Spotify developer dashboard matches the one WTFUtil uses."],"exampleFix":"// before: widget shows error with auth URL, user never logs in\n// after: complete the OAuth flow once so w.client is set\n// 1. click/visit the authURL printed by the error\n// 2. approve scopes in the browser\n// 3. restart wtfutil; w.client != nil and refresh succeeds","handlingStrategy":"validation","validationCode":"if widget.client == nil {\n    // complete the OAuth login at authURL before enabling refresh\n    return\n}","typeGuard":null,"tryCatchPattern":"if err := widget.refreshSpotifyInfos(); err != nil {\n    if strings.Contains(err.Error(), \"authentication failed\") {\n        // prompt the user to visit the embedded authURL\n    }\n}","preventionTips":["Complete the browser OAuth flow before running WTFUtil headless.","Verify clientID/clientSecret and redirect URI in the Spotify developer dashboard.","Keep the token cache file writable so sessions persist across restarts."],"tags":["spotify","oauth","authentication"],"backgroundTag":"oauth-login-required","analyzedSha":"bb838c1ccb0f0f3223690df44afdec663d622881","analyzedAt":"2026-09-03T17:02:45.030Z","contentChangedAt":"2026-09-03T17:02:45.030Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}