Skip to content

Commit afb7d1f

Browse files
login: use JSS org's own solid-oidc client (sso#2)
Replaces the @inrupt/solid-client-authn-browser import (which a file-write tool was inadvertently corrupting via email-pattern text replacement — `n@2.5.0` → `[email protected]` — yielding 404s on load) with the JavaScriptSolidServer org's own solid-oidc package: zero-build, single ~600-line file, zero-dependency, designed exactly for this use case. API translation: @inrupt/solid-client-authn-browser JSS solid-oidc ───────────────────────────────── ────────────────── login({oidcIssuer, redirectUrl}) session.login(idp, redirectUri) handleIncomingRedirect() session.init() + session.handleRedirectFromLogin() getDefaultSession().info.isLoggedIn session.isActive getDefaultSession().info.webId session.webId Behavior unchanged: button click → redirect to IdP → user proves identity (Schnorr/passkey/password) → redirect back → hydrate session → jump to pod root.
1 parent f22e47f commit afb7d1f

1 file changed

Lines changed: 27 additions & 31 deletions

File tree

login.js

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
// JSS SSO — one-click Solid sign-in.
22
//
3+
// Uses the JSS org's own `solid-oidc` package — a zero-build,
4+
// single-file (~600 lines), zero-dependency Solid-OIDC client.
5+
// Source: https://github.com/JavaScriptSolidServer/solid-oidc
6+
//
37
// Flow:
4-
// 1. Page loads. If a Solid-OIDC session was already restored
5-
// (handleIncomingRedirect), redirect straight to the user's
6-
// pod root. Skip the button.
7-
// 2. Otherwise: button click → `login()` triggers a redirect to
8-
// the configured IdP's /auth endpoint. The IdP handles the
9-
// actual identity proof (Schnorr / passkey / password) and
10-
// redirects back here with auth state.
11-
// 3. On return: step 1 fires, the session is hydrated, and we
12-
// redirect to the resolved WebID's pod root.
8+
// 1. Page loads. If a previous session is in localStorage, hydrate
9+
// it (session.init()). If the URL is a redirect-back, finalize
10+
// it (session.handleRedirectFromLogin()). Either way, if we
11+
// end up active, jump to the user's pod and skip the button.
12+
// 2. Otherwise: button click → session.login(idp, redirectUri)
13+
// triggers a redirect to the configured IdP's /auth endpoint.
14+
// The IdP handles the actual identity proof (Schnorr / passkey /
15+
// password) and redirects back here.
16+
// 3. On return: step 1 finalizes the session and we redirect to
17+
// the resolved WebID's pod root.
1318
//
14-
// Configurable via URL params or localStorage:
19+
// Configurable via URL params (also persisted to localStorage so a
20+
// freshly-redirected-back page knows where to send the user even if
21+
// the params got stripped on the IdP round-trip):
1522
// ?idp=<oidc-issuer> — defaults to https://solid.social
1623
// ?next=<destination-url> — defaults to the WebID's pod root
17-
//
18-
// Both are persisted so a freshly-redirected-back page knows
19-
// where to send the user even if the params got stripped on the
20-
// IdP round-trip.
2124

22-
import {
23-
login,
24-
handleIncomingRedirect,
25-
getDefaultSession,
26-
} from 'https://esm.sh/@inrupt/[email protected]';
25+
import Session from 'https://esm.sh/solid-oidc';
2726

2827
const DEFAULT_IDP = 'https://solid.social';
2928

@@ -61,20 +60,21 @@ function podRootFromWebId(webId) {
6160

6261
async function init() {
6362
const { idp, next } = readConfig();
63+
const session = new Session();
6464

65-
// If we're coming back from the IdP, hydrate the session.
65+
// Hydrate any prior session OR finalize a redirect-back from the IdP.
6666
try {
67-
await handleIncomingRedirect({
68-
restorePreviousSession: true,
69-
});
67+
await session.init();
68+
if (location.search.includes('code=')) {
69+
await session.handleRedirectFromLogin();
70+
}
7071
} catch (err) {
7172
setStatus(`Sign-in failed: ${err.message}`, true);
7273
return;
7374
}
7475

75-
const session = getDefaultSession();
76-
if (session.info.isLoggedIn && session.info.webId) {
77-
const webId = session.info.webId;
76+
if (session.isActive && session.webId) {
77+
const webId = session.webId;
7878
const dest = next || podRootFromWebId(webId);
7979
setStatus(`Signed in as ${webId}. Taking you to your pod…`);
8080
// Clear the saved `next` so a subsequent visit doesn't re-use it.
@@ -93,11 +93,7 @@ async function init() {
9393
localStorage.setItem('jss-sso:idp', idp);
9494
if (next) localStorage.setItem('jss-sso:next', next);
9595
try {
96-
await login({
97-
oidcIssuer: idp,
98-
redirectUrl: location.origin + location.pathname,
99-
clientName: 'JSS SSO',
100-
});
96+
await session.login(idp, location.origin + location.pathname);
10197
} catch (err) {
10298
setStatus(`Could not start sign-in: ${err.message}`, true);
10399
button.disabled = false;

0 commit comments

Comments
 (0)