MathewSachin/Captura · error · Exception
Not logged in to Imgur
Error message
Not logged in to Imgur
What it means
Thrown by ImgurUploader.GetAuthorizationHeader (src/Captura.Imgur/ImgurUploader.cs:73) when not anonymous and _settings.AccessToken is null/whitespace. The code only falls back to Client-ID when _settings.Anonymous is true; an authenticated profile without a stored access token cannot produce a Bearer header.
Source
Thrown at src/Captura.Imgur/ImgurUploader.cs:73
}
return new UploadResult
{
Url = uploadResponse.Data.Link,
DeleteLink = $"https://api.imgur.com/3/image/{uploadResponse.Data.DeleteHash}"
};
}
async Task<string> GetAuthorizationHeader()
{
if (_settings.Anonymous)
{
return $"Client-ID {_apiKeys.ImgurClientId}";
}
if (string.IsNullOrWhiteSpace(_settings.AccessToken))
{
throw new Exception("Not logged in to Imgur");
}
if (_settings.IsExpired())
{
if (!await RefreshToken())
{
throw new Exception("Failed to Refresh Imgur token");
}
}
return $"Bearer {_settings.AccessToken}";
}
async Task<bool> RefreshToken()
{
var args = new NameValueCollection
{
{ "refresh_token", _settings.RefreshToken },View on GitHub (pinned to 3fdf41529b)
Solutions
- Run the Imgur OAuth login flow to populate AccessToken before allowing non-anonymous uploads.
- Expose a UI guard: disable authenticated upload when AccessToken is empty and prompt to sign in.
- Fall back to anonymous mode (set _settings.Anonymous = true) if Client-ID keys are available.
- Persist AccessToken/RefreshToken/ExpiresAt immediately after login.
Example fix
// before
if (string.IsNullOrWhiteSpace(_settings.AccessToken))
throw new Exception("Not logged in to Imgur");
// after
if (string.IsNullOrWhiteSpace(_settings.AccessToken))
throw new ImgurAuthRequiredException(); // caller starts OAuth flow Defensive patterns
Strategy: validation
Validate before calling
if (!_settings.Anonymous && string.IsNullOrWhiteSpace(_settings.AccessToken))
throw new ImgurAuthRequiredException(); // caller runs OAuth Type guard
static bool CanUploadAuthenticated(ImgurSettings s)
=> s.Anonymous || !string.IsNullOrWhiteSpace(s.AccessToken); Try / catch
try { await uploader.Upload(img, fmt, progress); }
catch (Exception e) when (e.Message.Contains("Not logged in")) { await StartOAuthFlow(); } Prevention
- Disable authenticated upload when AccessToken is empty; prompt sign-in.
- Persist AccessToken/RefreshToken/ExpiresAt immediately after OAuth.
- Offer anonymous mode as a fallback when Client-ID keys are configured.
When it happens
Trigger: Calling Upload (or DeleteUploadedFile) in non-anonymous mode when ImgurSettings.AccessToken was never set, was cleared, or was never persisted after a prior OAuth flow.
Common situations: User toggled Imgur to authenticated mode but never completed the OAuth login; settings were reset/migrated and AccessToken came back empty; profile JSON partially corrupted.
Related errors
- Failed to Refresh Imgur token
- FFmpeg could not be found. Please download using the in-buil
- FFmpeg could not be found. Please download using the in-buil
- FFmpeg could not be found. Please download using the in-buil
- FFmpeg could not be found. Please download using the in-buil
AI-assisted analysis of MathewSachin/Captura@3fdf41529b (2026-08-13).
Data as JSON: /api/errors/41f2c4bb94f8275f.
Report an issue: GitHub.