AGENT SKILL

solid-auth-core

Use when maintaining legacy @jeswr/solid-auth-core integrations. Deprecated; use @jeswr/pod-auth and its package skill for new suite authentication.

License 许可
MIT
所属仓库
jeswr/solid-sdk
最近更新
2026-11-15
Stars
★ 2
Forks
0

01 前言 Front Matter

name
solid-auth-core
description
Use when maintaining legacy @jeswr/solid-auth-core integrations. Deprecated; use @jeswr/pod-auth and its package skill for new suite authentication.

02 资源文件 32

03 SKILL.md 正文

<!-- AUTHORED-BY Codex GPT-5 --> <!-- AUTHORED-BY Codex GPT-6.1-Sol --> <!-- AUTHORED-BY Codex GPT-6 -->

Work with @jeswr/solid-auth-core

<!-- AUTHORED-BY Codex GPT-6.1-Sol -->

Deprecated — use @jeswr/pod-auth. Read the pod-auth skill for migration, the current API and security policy. The guidance below maintains existing consumers; it does not describe pod-auth or authorize deleting legacy exports.

Use createSolidAuth() instead of copying token-provider, login UX, restore, or React session code into an app.

import { createSolidAuth } from "@jeswr/solid-auth-core";

const auth = createSolidAuth({
  callbackUri,
  clientId,
  authFlow: { getCode },
  patchGlobalFetch: true,
});

await auth.restore();
await auth.login(webId);
await auth.authenticatedFetch(resourceUrl);
await auth.publicFetch(foreignUrl);

React consumers use SessionProvider and useSolidSession() from @jeswr/solid-auth-core/react.

Preserve the credential boundary

  • Keep pristine fetch capture first and pin every OIDC discovery, registration, token, and refresh request to it. Never route auth bootstrap traffic through a token-attaching global wrapper.
  • Use authenticatedFetch only for allowed Solid resource origins and publicFetch for foreign/public origins.
  • Keep the allowed-origin set fail-closed: HTTPS resource origins only, with explicit loopback HTTP opt-in for development. Do not add the issuer merely because it issued the token.
  • Send every SDK-credentialed request with redirect: "manual", overriding caller policy. The controller and proactive fetch wrapper check each visible redirect with the same live credential gate and mint a fresh URL/method/token-bound DPoP proof per hop; never use native redirect following for credentials.
  • Use the shared Request-derivation helper for initial copies, buffering, manual passthrough/fallback, credential attachment, and followed hops. Preserve all caller-controlled Request settings (including referrer, referrerPolicy, mode, credentials, cache, integrity, keepalive, signal, and priority where supported) except the designed URL, redirect, credential-header, and method/body/content-header changes. Map inherited mode: "navigate" to "same-origin" when deriving with a non-empty init, per Fetch's constructor rule.
  • Never attach or refresh SDK tokens for mode: "no-cors" requests, including direct upgrade() calls. Decide whether to force manual redirects from credential headers that survive Request construction, reading the constructed Request's headers. If browser header filtering removes all credentials, keep the caller's redirect policy.
  • Force manual mode on every passthrough or fallback carrying caller-owned Authorization, DPoP, or Proxy-Authorization, from either init headers or a Request. Return every such redirect unfollowed, even on the same origin; the SDK cannot re-mint caller proofs. Credential-free passthrough and fallbacks keep the caller's original follow, error, or manual policy, including superseded upgrades and retries. Keep that policy on source requests and clones; derive manual requests only when attaching credentials. Let the transport handle credential-free redirects under the caller's policy.
  • On SDK-authenticated hops that change origin, strip Cookie, Cookie2, Proxy-Authorization, Authorization, and caller DPoP before re-adding fresh SDK credentials. Same-origin hops preserve them before the SDK replaces its authorization and proof.
  • Return foreign redirects and browser opaqueredirect responses unchanged. Browsers hide Location in manual mode, so credentialed redirects surface to their callers. Direct upgrade() users also receive manual Requests when credentials attach and must handle redirects themselves.
  • Follow at most 20 hops. Apply Fetch's POST-to-GET 301/302 and non-GET/HEAD-to-GET 303 rewrites, dropping body/content headers including Content-Length. Buffer only non-stream init.body values before sending; check the abort signal before buffering, race reads against abort, cancel the reader on abort, and reject with the signal's reason (AbortError by default) without waiting for source cancellation. Treat Request bodies as streams and return redirects that require replaying a stream unfollowed.
  • Cache resource-server nonces only under the checked hop's origin; a nonce retry must sign that hop's URL. Refuse a response nonce when its reported URL belongs to a different origin.
  • deriveProactiveAllowedOrigins excludes the issuer origin by default; only includeIssuerOrigin: true opts in. A pod hosted on the issuer origin remains allowed through podRoot. Use includeWebIdOrigin: false if the WebID document is not served by the pod. The separate computeAllowedOrigins default still includes the issuer.
  • When storage origins become known after restore, call reArmAllowedOrigins(origins, { expectedWebId }) with the identity captured before the asynchronous profile read. A missing session, WebID mismatch, or any inadmissible origin returns false without changing the boundary; success admits the entire list. Omitting expectedWebId targets the session live at call time. HTTPS is required, except HTTP loopback under the explicit development opt-in.
  • Keep generation fences and per-session ownership checks around login, restore, refresh, logout, and persistence. Re-check after every awaited boundary before mutating live state.
  • In request upgrades, re-check live session object identity and the allowed origin after both refresh and DPoP proof signing, before attaching credentials. Snapshot the access token and DPoP key once before signing and use that pair for both the proof and Authorization header; re-check both values after signing. A superseded session, revoked origin, or concurrent refresh that changes either value returns the original request without adding SDK credentials, preserving its redirect policy. Do not re-sign or force another refresh in that upgrade; later requests use the refreshed pair normally.
  • The final credential check runs before upgrade() resolves for dispatch. A logout in the microtask gap after it resolves cannot recall the already-built request, which may still be sent.
  • On any failure after arming a session, clear both the provider session and the authenticated-fetch boundary.
  • Keep same-WebID login single-flight; reject concurrent login for a different WebID.

Lifecycle rules

  • Call restore() before showing the unauthenticated screen.
  • Use dropLiveSession() for transient failures that should preserve the durable refresh credential.
  • Use logout() for intentional sign-out or a definitive invalid grant; await durable cleanup before publishing logged-out state.
  • Persist/rotate credentials before publishing authenticated state.
  • Use rememberAccount() for display metadata instead of an app-local overlay.
  • rememberAccount() is a no-op for WebIDs outside HTTPS (HTTP loopback requires allowInsecureLoopback). Newly stored labels, including WebID fallbacks, are truncated to the exported MAX_DISPLAY_NAME_LENGTH (256 Unicode code points); the full account WebID is preserved. Admit only absolute HTTP(S) avatars. Omitted metadata and rejected avatars preserve existing safe values.
  • Prefer a stable Client Identifier Document and WebID-first login. If a profile advertises multiple issuers or storage roots, require an explicit choice.

This package is security-critical. Keep tests adversarial and non-vacuous, including cross-account switching, delayed stale operations, login-stall regression, pristine-fetch routing, foreign-origin refusal, DPoP nonce handling, and restore/logout races. Run the full gate.

04 同仓库更多 Skills