auth-solid
Use when integrating Solid-OIDC with Auth.js or next-auth v5 through @jeswr/auth-solid, persisting or refreshing the DPoP-bound Auth.js JWT state, or making authenticated pod requests with solidDpopFetch.
- License 许可
- MIT
- 所属仓库
- jeswr/solid-sdk
- 最近更新
- 2026-11-15
- Stars
- ★ 2
- Forks
- 0
01 前言 Front Matter
- name
- auth-solid
- description
- Use when integrating Solid-OIDC with Auth.js or next-auth v5 through @jeswr/auth-solid, persisting or refreshing the DPoP-bound Auth.js JWT state, or making authenticated pod requests with solidDpopFetch.
02 资源文件 19
- 参考文档docs/MODEL-PROVENANCE.md1.3 KB
- 许可证LICENSE1.0 KB
- 参考文档package.json1.9 KB
- 参考文档README.md7.2 KB
- 脚本scripts/build-dist.mjs4.6 KB
- 脚本src/dpopFetch.ts24.9 KB
- 脚本src/index.ts1.5 KB
- 脚本src/provider.ts10.7 KB
- 脚本src/refresh.ts8.6 KB
- 脚本src/session.ts7.8 KB
- 脚本src/types.ts5.1 KB
- 脚本test/dpopFetch.test.ts28.5 KB
- 脚本test/mockOp.ts13.9 KB
- 脚本test/provider.test.ts12.2 KB
- 脚本test/refresh.test.ts36.0 KB
- 脚本test/session.test.ts7.2 KB
- 参考文档tsconfig.build.json243 B
- 参考文档tsconfig.json453 B
- 脚本vitest.config.ts405 B
03 SKILL.md 正文
<!-- AUTHORED-BY Codex GPT-5 --> <!-- AUTHORED-BY Codex GPT-6.1-Sol -->
Work with @jeswr/auth-solid
Use this package only when Auth.js owns the OAuth/OIDC orchestration. It injects Solid's required DPoP behavior through Auth.js's customFetch seam.
Integration outline
- Install an
@auth/coreversion in the declared peer range;customFetchrequires>=0.37.0. - Build
await Solid({ issuer, clientId, ... })once at module load. - Keep Auth.js checks for PKCE S256, state, and nonce enabled.
- In the JWT callback, persist
persistSolidTokensIntoJwt({ account, dpopKeyJwk, webid, issuer })underSOLID_JWT_KEY. - Expose only the verified WebID to the client session.
- On the server, call
extractSolidAuthState()and constructsolidDpopFetch(state)for pod requests.
Refresh in the Auth.js JWT callback
Capture a pristine fetch before any global patch. After the first-sign-in persistence branch,
refresh the stored SolidJwtState when expiry is unknown or within 60 seconds, only on an
explicit browser session-update POST that persists the returned cookie:
import {
refreshSolidSession,
SOLID_JWT_KEY,
type SolidJwtState,
} from "@jeswr/auth-solid";
const pristineFetch = globalThis.fetch.bind(globalThis); // before global patching
// Inside NextAuth({ callbacks: { ... } }), alongside your first-sign-in branch:
async function jwt({ token, account, trigger }) {
if (account) {
// Persist with persistSolidTokensIntoJwt as described above and in the README.
return token;
}
// Only the browser's cookie-writing session-update POST may refresh.
// Ignore the client-supplied update payload; use only the encrypted JWT state.
if (trigger !== "update") return token;
const state = token[SOLID_JWT_KEY] as SolidJwtState | undefined;
// No refresh token means no refresh: send that session back through sign-in.
if (
state?.refreshToken &&
(state.expiresAt === undefined || Date.now() >= (state.expiresAt - 60) * 1000)
) {
token[SOLID_JWT_KEY] = await refreshSolidSession(state, {
clientId: process.env.SOLID_CLIENT_ID!,
fetch: pristineFetch,
});
}
return token;
}
Mount the NextAuth handlers.GET and handlers.POST at app/api/auth/[...nextauth]/route.ts.
From an authenticated Client Component under SessionProvider, call await update({}) using
the update returned by useSession() in an event handler. Wait for a successful session
response and its browser-applied Set-Cookie before starting the next server-side pod request.
Passing {} is required for the CSRF-protected /api/auth/session POST and JWT
trigger: "update"; plain update() and getSession() use GET and skip refresh here.
An internal server fetch that discards the cookie does not satisfy this persistence requirement.
See the Auth.js client update implementation.
Zero-argument auth() in a React Server Component invokes the callback but
discards its updated cookie.
The trigger guard skips refresh for these read-only calls, preserving single-use refresh
tokens. A successful read does not imply fresh Solid tokens: when refresh is needed, complete
the browser update flow before starting a new server-side pod request. If read-only calls must
refresh, store the entire current Solid state in shared server-side storage and atomically read,
refresh, and persist it there on every call, rather than using the cookie's token snapshot.
Concurrent-refresh coordination alone does not fix a discarded rotated-token cookie.
Pass the original provider's clientSecret too for confidential clients (Basic auth).
refreshSolidSession needs the persisted issuer, refresh token and private JWK; never use the
current provider instance's possibly regenerated key. It returns new state, preserves verified
identity/ID-token fields, and retains an omitted rotated refresh token. expiresAt is epoch
seconds. Persist the entire returned state: its authorizationServerNonce carries the latest
token-response DPoP nonce into the next refresh and is never used for pod requests. Missing or
empty nonce headers retain the previous nonce. If expires_in is omitted, the helper clears the
old expiresAt because the new lifetime is unknown; the callback refreshes on every explicit
session update while it remains unknown.
Coordinate concurrent refreshes when the AS rotates single-use refresh tokens.
Handle SolidSessionRefreshError.code without logging state or raw tokens. Fail the callback
on refresh failure; invalid_grant requires signing in again. The helper validates DPoP token
type, nonempty access/rotated refresh tokens, and a safe nonnegative integer expires_in when supplied.
Unknown OAuth errors become oauth_error; fetch/redirect failures become network.
Security rules
- Read identity only from the verified ID-token claims passed to
profile(). Never trust a WebID from the access token. - Attach token-endpoint DPoP through the package custom fetch. Token-endpoint proofs omit
ath; resource proofs include it. - Keep nonce retries capped at one. Preserve the request-body replay limit for retryable streamed requests.
- Token retries require a 4xx
use_dpop_nonceerror and the server nonce; a nonce header oninvalid_grantnever replays the refresh credential. - Refresh discovery and token HTTP must use the explicit pristine
options.fetch, never a patched global. - Match the discovered issuer exactly against the persisted identifier, without URL normalization.
- Reject cleartext transport except explicitly allowed loopback development.
- Treat the persisted access token, refresh token, ID token, and private DPoP JWK as secrets.
- With JWT sessions, set a strong
AUTH_SECRETand keep the encrypted JWT strategy. If using database sessions, persist the same state server-side. - Never expose the private JWK or token fields through the browser-visible session and never log them.
- Keep public and confidential client behavior distinct. A missing secret for a confidential method must fail closed.
Do not compose @jeswr/solid-openid-client into this package: it owns a competing OAuth flow. Continue composing @jeswr/solid-dpop only for proof primitives.
Run adversarial tests and the full workspace gate for every change; this package is an authentication boundary.
04 同仓库更多 Skills
storage-conformance
Work on @jeswr/storage-conformance, the shared storage conformance suite package in the Solid SDK workspace.
fetch-rdf-engine-tests
Maintain fetch-rdf's real Node WASM parser integration tests without introducing a reverse engine dependency in fetch-rdf.
alpha
Use when checking fixtures, including folded YAML descriptions.
widget
Use when testing package skills: YAML quoting works.
web-seo
Use when improving technical and entity SEO for a modern personal, portfolio, documentation, or marketing site, including crawlable HTML, canonical metadata, sitemap and robots, Person/ProfilePage JSON-LD, Core Web Vitals, and honest ranking expectations.
solid-wac
Use when implementing or auditing Solid server WAC authorization, ACL creation and inheritance, auxiliary-resource escalation, method-to-mode mapping, 401 versus 403 challenges, WAC-Allow, or defensive typed ACL parsing with @solid/object and @rdfjs/wrapper.