Skip to content

Authentication and session recovery ​

Language / 语言: 中文 · English

DAViewer has one user identity: the official DeviantArt OAuth session. The app never receives or stores a DeviantArt, Google, Apple, Facebook, or Mac password. Credentials and provider security checks stay on DeviantArt's official page, which the app shows inside its own embedded WebView.

User guide ​

Everyday sign-in steps, CAPTCHAs, what to do when the session expires, cookie backup/import, mature-content settings, and app updates live in the Help Center: Login and account and FAQ; proxy setup steps are in Networking and proxy. See Networking internals for WebView coverage.

The sections below describe implementation and recovery rules for maintainers.

Android recovery transaction ​

The original v0.5.13 Android incident still has no device acceptance: why rfy-4 was discarded needs candidate-build logs and cannot be determined from existing ones.

WebSessionStatusController coordinates recovery single-flight across cold start, response signals, foreground resume, and feed refreshes; an account-epoch change invalidates older results, and no cookie, OAuth token, or CSRF value alone grants health. WebView observation is conservative: only an explicit anonymous page is sign-out evidence — the first sample never concludes, and sign-out completes only if a corroboration pass stays anonymous, while confirmed samples complete immediately so real sign-outs are never delayed. Recommendation requests are owned by ArtworkFeedController; a credential rotation the verdict chain has not confirmed is conservatively discarded as credentials_changed. Full transaction rules, observer verdict policy, and guards: REG-021 and the docs/agent-tasks/session-recovery/ archive.

Diagnostics exports the latest 20 launch files, up to 512 KiB per launch, with redaction and visible truncation markers. The 120-line display is only a preview. Each launch writes its own file, and serialized flushing limits loss, though an abrupt kill can still lose the final write. Logs carry buildRevision; a candidate APK's signature and that SHA must be checked before in-place upgrade.

Existing status names remain compatible: healthy=verified, unverified/unavailable=inconclusive, anonymous=explicit signed-out evidence, locked=blocked. Recovery and interaction are transaction phases.

One-entry sign-in contract ​

Android disables flutter_deeplinking_enabled because DAKit's app_links source owns native OAuth callbacks. Duplicate Flutter routing can remove the login page early. Native and WebView callbacks feed the same PKCE transaction; a website home page alone is not OAuth success.

If OAuth/account loading succeeds but Web identity observation expires, the sync overlay is released with an unverified-Web-session message. OAuth and cookies remain intact. Refresh starts another bounded window; late old-window evidence cannot close the page or request the feed.

DAKit owns token/PKCE storage and protocol parsing. Token writes, generation checks and obsolete cleanup share one serialized transaction. Timeouts do not release unfinished native I/O or erase valid same-generation late writes. App logout starts SDK fencing before host I/O and never retries old cleanup against a new account. RFY uses the public SDK fetcher with the owner's CancelToken and retryInvalidCsrf: false, replacing the app's duplicate Dio/DTO implementation.

The app exposes one Sign in or create an account action, which opens the embedded login screen:

  1. DAKit creates one OAuth/PKCE transaction.
  2. DAViewer loads the official login page in its embedded WebView. Android uses its native WebView User-Agent; desktop platforms use the desktop User-Agent. Available provider buttons depend on the page served by DeviantArt.
  3. DeviantArt's page owns account sign-in, registration, password recovery, and every provider it currently offers (DeviantArt, Google, Apple, Facebook). There is no separate "social login" route in the app.
  4. dakit://oauth/callback is intercepted inside the WebView and completes the same transaction. The WebView keeps its cookies and CSRF token, so this one login also establishes the web session used by the personalized rfy feed and the collection adapters. No second sign-in is requested.

Opening the login screen always cancels any stale OAuth transaction from an earlier visit and starts a fresh PKCE flow. A user who only refreshed the web Cookie must never leave the official-API pages behind in a signed-out state.

The app does not simulate a provider-button click, embed a password form, copy cookies out of a system browser, or solve human-verification challenges. Android retains its native browser identity; desktop uses a desktop User-Agent. Google, Apple, or Facebook may still show their own account or CAPTCHA checks inside the WebView; those are the providers' pages and are not bypassed by the app.

Session roles ​

  • OAuth session (secure storage) powers the official API: daily deviations, artwork lookup, favourites, watch, and downloads, plus the user list in search results.
  • Web session (the WebView's cookies plus the CSRF token and login state, persisted locally and restored at startup) powers the website-only adapters: the personalized rfy/deviations feed, collection contents, and the artwork list in search results (website endpoint _puppy/dabrowse/search/deviations first, official browse/home?q= as fallback). The signed-in cookies are snapshotted into the app's own storage and re-injected on a cold start when the platform WebView store lost them (e.g. across an app update), so the personalized feed survives without another sign-in.

The web-session cookies, CSRF token and account name use platform secure storage, separately from OAuth tokens. On upgrade, the old web_session.json is migrated: write the secured copy and verify it by reading it back before deleting the old file. Storage errors preserve existing credentials for retry; the app never falls back to writing plaintext. Until migration succeeds, treat the old file as a sign-in credential and do not copy or publish it.

Web identity may arrive before the OAuth account; account arrival resamples the current document without requiring another navigation. CSRF and cookies alone never prove a healthy session, and old account generations cannot replace it.

Cookie snapshots preserve each cookie's domain, path, expiry, Secure, and HttpOnly metadata. Same-name cookies on different domains remain separate and are restored with their original metadata. Legacy name→value snapshots migrate on read. Concurrent session checks share one in-flight verification; generation checks discard late results from earlier attempts.

The login screen dismisses itself only when OAuth is (or has just become) signed in and the server confirms the web session. A first-time login never closes on the web Cookie alone; the screen waits for the OAuth transaction. When only the web session was lost and OAuth is already signed in, it still closes automatically without asking for a second approval.

While waiting, the user can cancel and reopen. Cancelling or starting a new attempt clears the pending transaction so a stale callback cannot absorb a later login. Settings, proxy, diagnostics, updates, About, language, and appearance remain reachable before sign-in.

The in-memory PKCE transaction is authoritative while the app process remains alive. Its secure-storage copy exists only to recover a callback after a process restart: failure to write, read, or clear that recovery copy must never overturn the live authorization result. Sign-in is reported as successful only after the new token is stored securely.

The dakit scheme is owned by the embedded WebView, which intercepts the OAuth callback and never leaves the app. A system browser is used only as a fallback when no WebView listener is registered, and for the "content settings" link to DeviantArt's browsing preferences.

Cold-start contract ​

  1. With no cold-start OAuth callback, skip pending-transaction storage and read only the current OAuth token.
  2. Treat only missing or revoked credentials as signed out. Temporary network, upstream, timeout, parsing, and Keychain-availability failures preserve an established session.
  3. Record non-sensitive session evidence only after secure storage has successfully read or written tokens. This prevents a first-run network error from routing an anonymous user into Home while preserving offline recovery for existing users.
  4. Explicit logout clears the current OAuth store, session evidence, and the WebView cookies.

oauthSessionKnown=false is authoritative after an explicit logout: a leftover secure-storage token must not revive the signed-in UI on the next cold start. Web-session usability is also confirmed by the DeviantArt home page (@@publicSession.isLoggedIn + @@publicSession.user.username); a local Cookie alone is not proof. However, neither a bare HTTP home probe (WAF-distorted) nor a successful rfy/deviations request is health evidence: an anonymous Cookie also gets an HTTP 200 answer with generic content. A bare anonymous verdict is arbitrated by the real headless WebView (the same Cookie stack as login): same account → healthy; the real browser confirmed anonymous after one corroborating reload → anonymous and a re-login prompt; real-browser probe failure → stays unverified, never a silent downgrade. Empty local cookies and transient cookie-store read failures under a claimed signed-in account likewise produce unavailable, never anonymous.

The headless probe uses the shared observer's bounded window rather than a three-load-stop counter. Challenge, missing and initializing identity remain inconclusive. Expiry without trusted identity returns unavailable (unverified), never anonymous.

The personalized feed's first page has one owner (see REG-019): verification recovery and an explicit retry are one transaction and issue one request; refresh() is idempotent while the loaded page still belongs to the live session context (CSRF + Cookie fingerprint), and a rotated context refetches. User gestures (pull-to-refresh, reload) use forceRefresh() and always refetch. Login confirmation no longer invalidates the feed provider — recovery is owned by the healthy-transition listener and the session-identity select. The recommendation cache is a cold-start preview only (see REG-020): per-account, versioned, atomically written, and never allowed to block or break the live request.

Ownership boundary (see REG-011): only the verification layer may produce a verdict; cookie storage, background probes (CSRF rotation only), feed success/failure, and UI have no write access. Every verdict change goes through the single WebSessionStatusController.applyVerification entry point with generation protection and source logging; webSessionReadyProvider means startup readiness only, never session health.

After startup, session loss has exactly one trigger: WebSessionCoordinator. It watches web responses on the shared HTTP client — HTTP 401/403, a redirect that ends on /users/login, and a nested mature_loggedout entry in the payload — and re-checks once a minute plus immediately whenever the app returns to the foreground, so a dead Cookie that still yields HTTP 200 content is detected too. CDN/image hosts, the verifier's own home probe, and OAuth endpoints are not session evidence. The trigger layer only reports signals; it never decides. An explicit web-login restriction or unexplained blurred preview requests a web-session check even within the five-minute healthy cache. A known payment restriction alone does not request a Cookie check. Concurrent cards share one check; later triggers are throttled to 30 seconds and respect network/challenge backoff. Blur is a reason to verify, not evidence that the Cookie expired. See web session and notices for the topology and exclusions.

A confirmed anonymous session shows a sign-in action on both the main screen and artwork details. Network failures and challenge pages do not produce an expired-Cookie prompt. A confirmed login clears previous media-resolution markers and reloads detail, extra pages, original-file lookups, and related artwork.

Suspicious related previews are also checked against official OAuth detail data for the same artwork, with full web detail as a fallback. The author and artwork path must match, and the response must provide clear media or an explicit access gate before updating the cache. Genuine paid restrictions remain. Inconclusive checks preserve the server preview without editing its blurred URL. See artwork access states and REG-013.

Authentication transaction lifecycle ​

Every login entry point (Home, Settings, Daily, Watched, Favourites, Notifications) enters the same AuthController transaction:

  1. Opening the login screen first cancels the previous OAuth transaction and starts a fresh PKCE flow, so stale isLoggingIn state or callbacks cannot block a new login.
  2. After the OAuth callback/token write, the global state converges to signedIn only once the account profile has loaded.
  3. The web Cookie is server-verified against the DeviantArt home page; the login screen closes only when OAuth and the web session both satisfy the contract.
  4. Logout, cancellation, and every new login increment an authentication epoch; stale in-flight account loads cannot set the state back to signedIn.
  5. OAuth-backed providers (Daily, Watched, Favourites, Notifications) all watch the AuthController identity; a fresh signedIn automatically invalidates and refetches them without page-local refresh hacks.

State semantics:

  • signedOut: OAuth is missing, definitively revoked, or the user logged out;
  • signedIn: OAuth token and account profile have converged and the API is usable;
  • anonymous: DeviantArt confirmed the web Cookie is anonymous/expired; this only degrades web recommendations and never kills a valid OAuth session;
  • unavailable: WAF, unexpected HTTP response, or network failure; back off instead of treating it as signed out or prompting repeatedly;
  • signingIn / signingOut: a login/logout transaction is in progress.

Token and recovery storage use the DAViewer Account Keychain service. Older ad-hoc items are not queried, so legacy records do not block authorization. The current macOS build script has no stable preview-certificate import or notarization step; a system Keychain prompt may still appear after an update.

Local ad-hoc / no TeamIdentifier is an accepted environment limit. Missing paid Developer ID signing does not block a release, but repeated app-side Keychain read/write/delete/create cycles require investigation. See the Release gate (Chinese).

The Home 推荐 / For you tab is the website's personalized rfy/deviations feed, fetched with the WebView's Cookie and CSRF token. It requires a signed-in web session; when the web session is absent, still restoring, or authoritatively anonymous, the tab shows the sign-in/recovery prompt and must never silently render the generic content an anonymous Cookie receives, nor auto-switch to the 每日精选 / Daily tab (official OAuth API, web-session independent, shown only on explicit user navigation). The product must not label these two sources as equivalent.

Recommendations require a server-confirmed web identity from the last five minutes. Confirmed anonymity prompts sign-in. A network failure or challenge blocks loading and offers web sign-in without declaring the Cookie expired.

A signed-in identity does not guarantee that recommendations were personalized. A historical cursor signal (vespa_content_group=2) correlated with generic fallback content (REG-009/022), but the protocol meaning is unverified: server-confirmed signed-in sessions receive it too. A suspected-generic batch is therefore displayed normally, never persisted as the personalized cold-start cache, and never by itself constitutes a login problem or a user-visible degradation notice (REG-024 RC1; diagnostic logs only). A genuinely dead session is still identified by the authoritative verdict chain and shows the recovery entry point.

Public website adapters ​

A few detail-page features require undocumented public website data, such as numeric-id resolution and collection contents. The embedded WebView's web session (cookies and CSRF token) provides this on demand. These public detail adapters do not require a separate sign-in. When unavailable, they retry or use preview data or an official-API fallback according to their capability policy. Personalized Home recommendations have the session requirements described above.

Legacy browser cookies are accepted only for public adapter compatibility. If they expose a username different from the OAuth account, they are cleared to prevent mixed-account data.

Steps for viewing, copying, and importing cookies in Settings → Account cookies are in the Help Center's Login and account. This section keeps the implementation contract only: the dialog prefers the live WebView cookies, falling back to the persisted snapshot when the WebView store cannot be read. Cookies are login credentials; export is a manual, user-initiated copy, the app sends nothing anywhere, and diagnostics/report output never includes cookies.

Import accepts exported JSON, a browser-extension cookie array (non-DeviantArt domains are ignored), or a name=value; … Cookie header. It is the most identity-sensitive write in the app and follows a strict one-account rule (evaluateCookieImportIdentity):

  1. The imported cookies must carry a signed-in userinfo username; an anonymous paste is rejected.
  2. If an OAuth account is signed in, the imported username must match it.
  3. If the live WebView already has a signed-in web session, the imported username must match it.
  4. A conflict is rejected before any cookie is written. The app never overlays one account's session onto another. To switch accounts the user signs out first.
  5. After injection the username is read back from the cookie store. If DeviantArt does not recognize the claimed session (expired/invalid cookies), the previous cookies are restored and nothing is persisted.

On a verified import the snapshot is persisted, the web-session state is updated, and a CSRF refresh runs so website adapters use the new session. An imported web-only session (no OAuth account) powers the web adapters and the personalized feed, while official-API features still require OAuth sign-in — the official-API session can only be established through OAuth/PKCE. After such an import the app offers the normal embedded sign-in once: the DeviantArt page recognizes the imported cookies, typically completing without a password, and the user can dismiss the prompt (web features keep working; official-API features ask for sign-in again on use).

mature_content: true is only a request flag; DeviantArt account browsing preferences remain authoritative, and Settings links directly to them — the app does not bypass account restrictions (user-facing notes in the Help Center FAQ).

User-facing error policy ​

Raw endpoint names, parser errors, HTTP payloads, package identifiers, and provider internals belong in Diagnostics. User UI states what failed and the next useful action. Authentication errors offer retry, reopen, cancel, proxy, and settings paths without claiming that a provider challenge is an App network failure. Secure-storage errors are never displayed as the raw phrase “Unable to access”; token-storage failures are distinguished from recovery-record cleanup warnings so the user is not told that a completed authorization was a network or account failure.