-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathviews.js
More file actions
1180 lines (1088 loc) · 38 KB
/
Copy pathviews.js
File metadata and controls
1180 lines (1088 loc) · 38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* HTML templates for IdP login/consent pages
* Minimal, functional design
*/
const styles = `
* { box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: #f5f5f5;
margin: 0;
padding: 40px 20px;
min-height: 100vh;
}
.container {
max-width: 400px;
margin: 0 auto;
background: white;
border-radius: 12px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
padding: 40px;
}
h1 {
margin: 0 0 8px 0;
font-size: 24px;
color: #333;
}
.subtitle {
color: #666;
margin: 0 0 30px 0;
font-size: 14px;
}
.client-info {
background: #f8f9fa;
border-radius: 8px;
padding: 16px;
margin-bottom: 24px;
}
.client-name {
font-weight: 600;
color: #333;
}
.client-uri {
font-size: 12px;
color: #666;
word-break: break-all;
}
label {
display: block;
font-size: 14px;
font-weight: 500;
color: #333;
margin-bottom: 6px;
}
input[type="text"],
input[type="email"],
input[type="password"] {
width: 100%;
padding: 12px;
border: 1px solid #ddd;
border-radius: 8px;
font-size: 16px;
margin-bottom: 16px;
transition: border-color 0.2s;
}
input:focus {
outline: none;
border-color: #0066cc;
}
.error {
background: #fee;
border: 1px solid #fcc;
color: #c00;
padding: 12px;
border-radius: 8px;
margin-bottom: 20px;
font-size: 14px;
}
.btn {
display: inline-block;
padding: 12px 24px;
border-radius: 8px;
font-size: 16px;
font-weight: 500;
cursor: pointer;
border: none;
text-decoration: none;
text-align: center;
transition: background-color 0.2s;
}
.btn-primary {
background: #0066cc;
color: white;
width: 100%;
}
.btn-primary:hover {
background: #0052a3;
}
.btn-secondary {
background: #f0f0f0;
color: #333;
margin-top: 12px;
width: 100%;
}
.btn-secondary:hover {
background: #e0e0e0;
}
.btn-passkey {
background: #1a73e8;
color: white;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
}
.btn-passkey:hover {
background: #1557b0;
}
.btn-passkey svg {
width: 20px;
height: 20px;
}
.btn-schnorr {
background: #7b1fa2;
color: white;
width: 100%;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
margin-top: 12px;
}
.btn-schnorr:hover {
background: #6a1b9a;
}
.btn-schnorr svg {
width: 20px;
height: 20px;
}
.divider {
display: flex;
align-items: center;
margin: 20px 0;
color: #666;
font-size: 14px;
}
.divider::before,
.divider::after {
content: '';
flex: 1;
border-bottom: 1px solid #ddd;
}
.divider span {
padding: 0 12px;
}
.scopes {
margin: 20px 0;
}
.scope {
display: flex;
align-items: center;
padding: 12px;
background: #f8f9fa;
border-radius: 8px;
margin-bottom: 8px;
}
.scope-icon {
width: 24px;
height: 24px;
margin-right: 12px;
opacity: 0.6;
}
.scope-name {
font-weight: 500;
}
.scope-desc {
font-size: 12px;
color: #666;
}
.actions {
margin-top: 24px;
}
.logo {
text-align: center;
margin-bottom: 24px;
}
.logo svg {
width: 48px;
height: 48px;
}
`;
const solidLogo = `
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg">
<circle cx="50" cy="50" r="45" fill="#7C4DFF" />
<path d="M30 50 L45 65 L70 40" stroke="white" stroke-width="8" fill="none" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
`;
const passkeyIcon = `
<svg viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path d="M12.65 10C11.83 7.67 9.61 6 7 6c-3.31 0-6 2.69-6 6s2.69 6 6 6c2.61 0 4.83-1.67 5.65-4H17v4h4v-4h2v-4H12.65zM7 14c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2z"/>
</svg>
`;
const schnorrIcon = `
<svg viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path d="M18 8h-1V6c0-2.76-2.24-5-5-5S7 3.24 7 6v2H6c-1.1 0-2 .9-2 2v10c0 1.1.9 2 2 2h12c1.1 0 2-.9 2-2V10c0-1.1-.9-2-2-2zm-6 9c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2zm3.1-9H8.9V6c0-1.71 1.39-3.1 3.1-3.1 1.71 0 3.1 1.39 3.1 3.1v2z"/>
</svg>
`;
const scopeDescriptions = {
openid: 'Access your identity',
webid: 'Access your WebID',
profile: 'Access your name',
email: 'Access your email address',
offline_access: 'Stay logged in',
};
/**
* Escape string for safe use in JavaScript
*/
function escapeJs(text) {
if (!text) return '';
return String(text)
.replace(/\\/g, '\\\\')
.replace(/'/g, "\\'")
.replace(/"/g, '\\"')
.replace(/</g, '\\x3c')
.replace(/>/g, '\\x3e')
.replace(/\n/g, '\\n')
.replace(/\r/g, '\\r');
}
/**
* Login page HTML
*/
export function loginPage(uid, clientId, error = null, passkeyEnabled = true, schnorrEnabled = true) {
const appName = clientId || 'An application';
const safeUid = escapeJs(uid);
const passkeySection = passkeyEnabled ? `
<button type="button" class="btn btn-passkey" onclick="loginWithPasskey()">
${passkeyIcon}
Sign in with Passkey
</button>
` : '';
const schnorrSection = schnorrEnabled ? `
<button type="button" class="btn btn-schnorr" onclick="loginWithSchnorr()" id="schnorrBtn">
${schnorrIcon}
Sign in with Schnorr
</button>
` : '';
const ssoSection = (passkeyEnabled || schnorrEnabled) ? `
${passkeySection}
${schnorrSection}
<div class="divider"><span>or</span></div>
` : '';
const passkeyScript = passkeyEnabled ? `
<script>
var INTERACTION_UID = '${safeUid}';
async function loginWithPasskey() {
// Passkeys require WebAuthn + a secure context. Stale Android
// System WebViews (common on de-Googled phones, #556) and plain
// http origins lack it. Detect up front and steer the user to the
// password form right below instead of failing deep in the
// ceremony with a cryptic error.
if (!window.isSecureContext || !window.PublicKeyCredential ||
!(navigator.credentials && navigator.credentials.get)) {
alert('Passkeys aren\\'t available in this browser. Please sign in with your username and password below.');
return;
}
try {
// Get authentication options. No client-side correlation id is
// sent — the server mints the challengeKey (always-available
// Node crypto) and returns it; we echo options.challengeKey on
// verify. This deliberately avoids a browser crypto.randomUUID
// call that old WebViews lack (#556).
const optionsRes = await fetch('/idp/passkey/login/options', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({})
});
const options = await optionsRes.json();
if (options.error) {
alert('Error: ' + options.error);
return;
}
// Convert base64url to ArrayBuffer
options.challenge = base64urlToBuffer(options.challenge);
if (options.allowCredentials) {
options.allowCredentials = options.allowCredentials.map(c => ({
...c,
id: base64urlToBuffer(c.id)
}));
}
// Prompt user for passkey
const credential = await navigator.credentials.get({ publicKey: options });
// Send response to server
const verifyRes = await fetch('/idp/passkey/login/verify', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
challengeKey: options.challengeKey,
credential: {
id: credential.id,
rawId: bufferToBase64url(credential.rawId),
type: credential.type,
response: {
clientDataJSON: bufferToBase64url(credential.response.clientDataJSON),
authenticatorData: bufferToBase64url(credential.response.authenticatorData),
signature: bufferToBase64url(credential.response.signature),
userHandle: credential.response.userHandle
? bufferToBase64url(credential.response.userHandle)
: null
}
}
})
});
const result = await verifyRes.json();
if (result.success) {
// Complete the OIDC interaction - build URL safely
const redirectUrl = '/idp/interaction/' + encodeURIComponent(INTERACTION_UID) + '/passkey-complete?accountId=' + encodeURIComponent(result.accountId);
window.location.href = redirectUrl;
} else {
alert('Passkey authentication failed: ' + (result.error || 'Unknown error'));
}
} catch (err) {
if (err.name === 'NotAllowedError') {
// User cancelled - do nothing
} else {
console.error('Passkey error:', err);
alert('Passkey authentication failed: ' + err.message);
}
}
}
function base64urlToBuffer(base64url) {
const base64 = base64url.replace(/-/g, '+').replace(/_/g, '/');
const padLen = (4 - base64.length % 4) % 4;
const padded = base64 + '='.repeat(padLen);
const binary = atob(padded);
const bytes = new Uint8Array(binary.length);
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
return bytes.buffer;
}
function bufferToBase64url(buffer) {
const bytes = new Uint8Array(buffer);
let binary = '';
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
return btoa(binary).replace(/[+]/g, '-').replace(/[/]/g, '_').replace(/=/g, '');
}
</script>
` : '';
const schnorrScript = schnorrEnabled ? `
<script>
async function loginWithSchnorr() {
const btn = document.getElementById('schnorrBtn');
// Check for NIP-07 extension (window.nostr)
if (typeof window.nostr === 'undefined') {
alert('No Schnorr signer found. Please install a NIP-07 compatible extension like Podkey, nos2x, or Alby.');
return;
}
btn.disabled = true;
btn.textContent = 'Signing...';
try {
// Get the current URL for the auth event
const authUrl = window.location.origin + '/idp/interaction/${safeUid}/schnorr-login';
// Create NIP-98 event (kind 27235)
const event = {
kind: 27235,
created_at: Math.floor(Date.now() / 1000),
tags: [
['u', authUrl],
['method', 'POST']
],
content: ''
};
// Sign with NIP-07 extension
const signedEvent = await window.nostr.signEvent(event);
// Read the typed username so the server can resolve which
// account this Nostr key belongs to, in case the existing
// did:nostr DID-doc resolver doesn't have a binding yet.
// The signature is verified BEFORE the username is consulted —
// typing someone else's username doesn't grant access.
const typedUsername = (document.getElementById('username')?.value || '').trim();
// Send to server
const response = await fetch(authUrl, {
method: 'POST',
headers: {
'Authorization': 'Nostr ' + btoa(JSON.stringify(signedEvent)),
'Content-Type': 'application/x-www-form-urlencoded'
},
body: typedUsername ? 'username=' + encodeURIComponent(typedUsername) : ''
});
const result = await response.json();
if (result.success && result.redirectUrl) {
window.location.href = result.redirectUrl;
} else if (result.error) {
alert('Schnorr login failed: ' + result.error);
btn.disabled = false;
btn.textContent = 'Sign in with Schnorr';
} else {
alert('Schnorr login failed: Unknown error');
btn.disabled = false;
btn.textContent = 'Sign in with Schnorr';
}
} catch (err) {
console.error('Schnorr login error:', err);
if (err.message && err.message.includes('User rejected')) {
// User cancelled signing - do nothing
} else {
alert('Schnorr login failed: ' + err.message);
}
btn.disabled = false;
btn.textContent = 'Sign in with Schnorr';
}
}
</script>
` : '';
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sign In - Solid IdP</title>
<style>${styles}</style>
</head>
<body>
<div class="container">
<div class="logo">${solidLogo}</div>
<h1>Sign In</h1>
<p class="subtitle">Sign in to your Solid Pod</p>
<div class="client-info">
<div class="client-name">${escapeHtml(appName)}</div>
<div class="client-uri">is requesting access to your pod</div>
</div>
${error ? `<div class="error">${escapeHtml(error)}</div>` : ''}
${ssoSection}
<form method="POST" action="/idp/interaction/${uid}/login">
<label for="username">Username</label>
<input type="text" id="username" name="username" required autofocus placeholder="Your username">
<label for="password">Password</label>
<input type="password" id="password" name="password" required placeholder="Your password">
<button type="submit" class="btn btn-primary">Sign In</button>
</form>
<form method="POST" action="/idp/interaction/${uid}/abort">
<button type="submit" class="btn btn-secondary">Cancel</button>
</form>
<p style="text-align: center; margin-top: 24px; color: #666; font-size: 14px;">
Don't have an account? <a href="/idp/register?uid=${uid}" style="color: #0066cc;">Register</a>
</p>
</div>
${passkeyScript}
${schnorrScript}
</body>
</html>
`;
}
/**
* Consent page HTML
*/
export function consentPage(uid, client, params, account) {
const scopes = (params.scope || 'openid').split(' ').filter(Boolean);
const clientName = client?.clientName || client?.client_id || 'Unknown App';
const clientUri = client?.clientUri || client?.redirect_uris?.[0] || '';
const scopeItems = scopes.map(scope => `
<div class="scope">
<div class="scope-icon">✓</div>
<div>
<div class="scope-name">${escapeHtml(scope)}</div>
<div class="scope-desc">${escapeHtml(scopeDescriptions[scope] || 'Access requested')}</div>
</div>
</div>
`).join('');
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Authorize - Solid IdP</title>
<style>${styles}</style>
</head>
<body>
<div class="container">
<div class="logo">${solidLogo}</div>
<h1>Authorize Access</h1>
<p class="subtitle">Allow this app to access your data?</p>
<div class="client-info">
<div class="client-name">${escapeHtml(clientName)}</div>
${clientUri ? `<div class="client-uri">${escapeHtml(clientUri)}</div>` : ''}
</div>
${account ? `
<div style="display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; margin: 12px 0;">
<span>Signed in as <strong>${escapeHtml(account.email)}</strong></span>
<span style="color: #94a3b8;">·</span>
<form method="POST" action="/idp/interaction/${uid}/switch" style="display: inline; margin: 0;">
<button type="submit" style="background: none; border: 0; padding: 0; color: #2563eb; font: inherit; cursor: pointer; text-decoration: underline;">Sign in as a different user</button>
</form>
</div>
` : ''}
<div class="scopes">
<label>This app is requesting access to:</label>
${scopeItems}
</div>
<div class="actions">
<form method="POST" action="/idp/interaction/${uid}/confirm">
<button type="submit" class="btn btn-primary">Allow Access</button>
</form>
<form method="POST" action="/idp/interaction/${uid}/abort">
<button type="submit" class="btn btn-secondary">Deny</button>
</form>
</div>
</div>
</body>
</html>
`;
}
/**
* Account-deletion form HTML (#392).
*
* Public unauthenticated page (matches the existing /idp landing and
* /idp/register pattern). Auth happens at submission time: the user
* supplies username + password, which the server validates and uses as
* proof-of-possession for the delete. The "type your username again to
* confirm" field is the destructive-action UX guard.
*
* On any failure (wrong password, mismatched confirmation, etc.) the
* handler re-renders this same form in place at status 200 with an
* error message and the identifier field pre-filled — no redirect.
*
* @param {object} opts
* @param {string|null} opts.error - Error message (e.g. wrong password) to display
* @param {string} opts.username - Pre-fill the identifier field on re-render after error
* @param {boolean} opts.singleUser - When true, render a disabled message
* instead of the form. Deletion via HTTP is blocked in single-user mode
* (would brick the IdP until re-seed); operator path stays the CLI.
* @param {boolean} opts.success - When true, render the post-delete confirmation
* @param {boolean} opts.purgeFailed - When true (only on success), include a
* notice that the user requested a pod-data purge but it didn't complete.
* Account deletion still succeeded.
*/
export function accountDeletePage({ error = null, username = '', singleUser = false, success = false, purgeFailed = false } = {}) {
if (singleUser) {
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Account deletion disabled - Solid IdP</title>
<style>${styles}</style>
</head>
<body>
<div class="container">
<div class="logo">${solidLogo}</div>
<h1>Account deletion disabled</h1>
<p>This server runs in <strong>single-user mode</strong>. Deleting the single account
via HTTP would leave the server with no IdP account until re-seed,
so this endpoint is disabled.</p>
<p>The operator can still delete the account at the shell with:</p>
<pre style="background: #f1f5f9; padding: 12px; border-radius: 6px; font-size: 13px;">jss account delete <username></pre>
<a href="/idp" class="btn btn-secondary" style="text-decoration: none;">Back</a>
</div>
</body>
</html>
`;
}
if (success) {
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Account deleted - Solid IdP</title>
<style>${styles}</style>
</head>
<body>
<div class="container">
<div class="logo">${solidLogo}</div>
<h1>Account deleted</h1>
<p>Your account record has been removed from this server. Future sign-ins
with this username will fail.</p>
<p style="font-size: 13px; color: #64748b; margin-top: 8px;">
Note: any access tokens already issued may remain usable until they
expire — the server does not currently revoke them on account deletion.
</p>
${purgeFailed ? `
<div class="error" style="margin-top: 16px;">
Your account was deleted, but the pod-data purge did not complete on
this server. Some files may still exist. Contact the operator to
finish the cleanup if needed.
</div>
` : ''}
<a href="/idp" class="btn btn-primary" style="text-decoration: none; margin-top: 16px;">Return to sign-in</a>
</div>
</body>
</html>
`;
}
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Delete account - Solid IdP</title>
<style>${styles}
.danger {
background: #fef2f2;
border: 1px solid #fecaca;
color: #991b1b;
padding: 14px 16px;
border-radius: 8px;
margin: 16px 0 24px;
font-size: 13px;
line-height: 1.55;
}
.danger strong { color: #7f1d1d; }
.btn-danger {
background: #dc2626;
color: #fff;
}
.btn-danger:hover { background: #b91c1c; }
.checkbox-row {
display: flex;
align-items: flex-start;
gap: 10px;
margin: 16px 0 8px;
padding: 10px 12px;
background: #f8fafc;
border: 1px solid #e2e8f0;
border-radius: 6px;
}
.checkbox-row input[type="checkbox"] { margin-top: 3px; flex-shrink: 0; }
.checkbox-row label {
margin: 0;
font-size: 13px;
line-height: 1.5;
color: #334155;
cursor: pointer;
}
.checkbox-row label strong { color: #0f172a; }
</style>
</head>
<body>
<div class="container">
<div class="logo">${solidLogo}</div>
<h1>Delete your account</h1>
<div class="danger">
<strong>This is permanent.</strong> Your account record and credentials will be
removed; future sign-ins with this username will fail. By default, your pod
data (every file you've stored, including your WebID profile document) is
also wiped — check the box below if you want to keep it. Federated references
(ActivityPub follows, Nostr relays, type indexes) cannot be retracted from
this server.
<br><br>
<span style="font-size: 12px; color: #7f1d1d;">
Note: access tokens already issued may remain usable until they
expire — the server does not currently revoke them on deletion.
</span>
</div>
${error ? `<div class="error">${escapeHtml(error)}</div>` : ''}
<form method="POST" action="/idp/account/delete">
<label for="username">Username</label>
<input type="text" id="username" name="username" required autofocus
value="${escapeHtml(username || '')}"
placeholder="alice">
<label for="currentPassword">Current password</label>
<input type="password" id="currentPassword" name="currentPassword" required
placeholder="Re-enter your password">
<label for="confirmUsername">Type your username again to confirm</label>
<input type="text" id="confirmUsername" name="confirmUsername" required
placeholder="Must match the username above">
<div class="checkbox-row">
<input type="checkbox" id="keepData" name="keepData" value="on">
<label for="keepData">
<strong>Keep my pod data on this server.</strong> Check only if you want
to delete just your account record and leave your files in place. Default
(unchecked) wipes the pod folder along with the account.
</label>
</div>
<button type="submit" class="btn btn-danger" style="width: 100%; margin-top: 16px;">
Delete my account permanently
</button>
</form>
<p style="text-align: center; margin-top: 16px; font-size: 13px;">
<a href="/idp">Cancel and go back</a>
</p>
</div>
</body>
</html>
`;
}
/**
* Error page HTML
*/
export function errorPage(title, message) {
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Error - Solid IdP</title>
<style>${styles}</style>
</head>
<body>
<div class="container">
<div class="logo">${solidLogo}</div>
<h1 style="color: #c00;">${escapeHtml(title)}</h1>
<p>${escapeHtml(message)}</p>
<a href="/" class="btn btn-secondary">Go Home</a>
</div>
</body>
</html>
`;
}
/**
* Friendly landing page for the IdP root.
*
* The OIDC authorization endpoint (/idp/auth) requires a client_id; opening
* /idp manually used to drop the user into a raw OIDC error. This page is
* the human-navigable entry point.
*
* In single-user mode (`ctx.singleUser`) the Create Account button is
* suppressed — pod creation is disabled and the button would lead to a
* 403. The sign-in note still names pilot as the example client.
*/
export function landingPage(ctx = {}) {
const issuer = ctx.baseUri || '';
const singleUser = !!ctx.singleUser;
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Solid Pod Server</title>
<style>${styles}
/* landingPage local polish (#286) */
.container.landing { padding-top: 32px; }
.landing-header {
margin: -40px -40px 24px;
padding: 32px 40px 26px;
background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
color: #fff;
border-radius: 12px 12px 0 0;
text-align: center;
}
.landing-header h1 { color: #fff; margin: 0 0 6px; font-size: 24px; }
.landing-header .subtitle { color: rgba(255,255,255,.85); margin: 0; font-size: 14px; }
.landing .signin-note {
margin-top: 18px;
padding: 14px 16px;
background: #f8fafc;
border: 1px solid #e2e8f0;
border-radius: 8px;
color: #475569;
font-size: 13px;
line-height: 1.55;
}
.landing .signin-note strong { color: #1e293b; }
.landing .signin-note a { color: #4f46e5; text-decoration: none; font-weight: 500; }
.landing .signin-note a:hover { text-decoration: underline; }
.landing .issuer {
margin-top: 18px;
text-align: center;
color: #94a3b8;
font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
word-break: break-all;
}
</style>
</head>
<body>
<div class="container landing">
<div class="landing-header">
<h1>Solid Pod Server</h1>
<p class="subtitle">${singleUser
? 'Single-user pod — sign in from any Solid app.'
: 'Create an account, then sign in from any Solid app.'}</p>
</div>
${singleUser
? '' /* Registration is disabled in single-user mode; suppress the dead-end button. */
: '<a href="/idp/register" class="btn btn-primary" style="text-decoration: none;">Create Account</a>'}
<div class="signin-note">
<strong>${singleUser ? 'Sign in' : 'Already have an account?'}</strong> ${singleUser ? 'from' : 'Sign in from'} a Solid app — for example, <a href="https://solid-apps.github.io/pilot/" target="_blank" rel="noopener">pilot</a> is a minimal console you can open right now. Point it at this server and click Sign In. Or <a href="https://solidproject.org/apps" target="_blank" rel="noopener">browse other Solid apps</a>.
</div>
${issuer ? `<div class="issuer">Issuer: ${escapeHtml(issuer.replace(/\/$/, ''))}</div>` : ''}
</div>
</body>
</html>
`;
}
/**
* Registration page HTML
*/
export function registerPage(uid = null, error = null, success = null, inviteOnly = false, ctx = {}) {
const inviteField = inviteOnly ? `
<label for="invite">Invite Code</label>
<input type="text" id="invite" name="invite" required
placeholder="Enter your invite code" style="text-transform: uppercase;">
` : '';
// Embed the values the live preview needs. Escape characters that are
// unsafe in inline <script> contexts so values like "</script>" or
// U+2028 / U+2029 line separators can't terminate the script tag or
// confuse the parser when template-substituted.
const previewConfig = JSON.stringify({
baseUri: ctx.baseUri || '',
subdomainsEnabled: !!ctx.subdomainsEnabled,
baseDomain: ctx.baseDomain || '',
})
.replace(/</g, '\\u003c')
.replace(/\u2028/g, '\\u2028')
.replace(/\u2029/g, '\\u2029');
// Server validates more strictly than the HTML pattern can express; mirror
// as much as possible client-side so the browser catches obvious mistakes
// before submit. Subdomain mode drops dot/underscore (DNS hostname rules).
const usernamePattern = (ctx.subdomainsEnabled && ctx.baseDomain)
? '[a-z0-9](?:[a-z0-9-]{1,30}[a-z0-9])?'
: '(?!.*\\.\\.)[a-z0-9](?:[a-z0-9._-]{1,30}[a-z0-9])?';
const usernameTitle = (ctx.subdomainsEnabled && ctx.baseDomain)
? 'Lowercase letters, numbers, or - (start and end alphanumeric, 3–32 chars). Subdomain mode disallows . and _.'
: 'Lowercase letters, numbers, or . _ - (start and end alphanumeric, 3–32 chars, no consecutive dots)';
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Register - Solid IdP</title>
<style>${styles}
/* registerPage local polish (#284) */
.container.register { padding-top: 32px; }
.register-header {
margin: -40px -40px 24px;
padding: 28px 40px 22px;
background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
color: #fff;
border-radius: 12px 12px 0 0;
}
.register-header h1 { color: #fff; margin: 0 0 4px; font-size: 22px; }
.register-header .subtitle { color: rgba(255,255,255,.85); margin: 0; font-size: 13px; }
.preview {
margin: 4px 0 18px;
padding: 12px 14px;
background: #f8fafc;
border: 1px solid #e2e8f0;
border-radius: 8px;
font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
color: #475569;
word-break: break-all;
}
.preview .label { color: #64748b; font-weight: 600; margin-right: 6px; }
.preview .placeholder { color: #94a3b8; font-style: italic; }
</style>
</head>
<body>
<div class="container register">
<div class="register-header">
<h1>Create Account</h1>
<p class="subtitle">Register for a new Solid Pod${inviteOnly ? ' (invite required)' : ''}</p>
</div>
${error ? `<div class="error">${escapeHtml(error)}</div>` : ''}
${success ? `<div class="error" style="background: #efe; border-color: #cfc; color: #060;">${escapeHtml(success)}</div>` : ''}
<form method="POST" action="/idp/register${uid ? `?uid=${uid}` : ''}">
${inviteField}
<label for="username">Username</label>
<input type="text" id="username" name="username" required ${!inviteOnly ? 'autofocus' : ''}
placeholder="Choose a username" minlength="3" maxlength="32"
pattern="${usernamePattern}"
title="${usernameTitle}">
<div class="preview" id="preview" aria-live="polite">
<div><span class="label">WebID</span><span id="preview-webid" class="placeholder">choose a username to preview</span></div>
<div style="margin-top: 4px;"><span class="label">Storage</span><span id="preview-storage" class="placeholder">—</span></div>
</div>
<label for="password">Password</label>
<input type="password" id="password" name="password" required
placeholder="Choose a password">
<label for="confirmPassword">Confirm Password</label>
<input type="password" id="confirmPassword" name="confirmPassword" required
placeholder="Confirm your password">
<button type="submit" class="btn btn-primary">Create Account</button>
</form>
<p style="text-align: center; margin-top: 24px; color: #666; font-size: 14px;">
${uid
? `Already have an account? <a href="/idp/interaction/${uid}" style="color: #0066cc;">Sign In</a>`
: `<a href="/idp" style="color: #0066cc;">Back to home</a>`}
</p>
</div>
<script>
(function () {
var cfg = ${previewConfig};
var input = document.getElementById('username');
var webEl = document.getElementById('preview-webid');
var storEl = document.getElementById('preview-storage');
if (!input || !webEl || !storEl) return;
function render() {
// Server rejects uppercase outright, so normalise the field as the
// user types — keeps the preview honest and avoids a confusing
// post-submit error.
var normalised = (input.value || '').toLowerCase();
if (input.value !== normalised) input.value = normalised;
var u = normalised.trim();
if (!u) {
webEl.textContent = 'choose a username to preview';
webEl.className = 'placeholder';
storEl.textContent = '—';
storEl.className = 'placeholder';
return;
}
var pod, webid;
if (cfg.subdomainsEnabled && cfg.baseDomain) {
var origin = cfg.baseUri.split('://')[0] + '://';
pod = origin + u + '.' + cfg.baseDomain + '/';
} else {
pod = (cfg.baseUri || (location.protocol + '//' + location.host)) + '/' + u + '/';
}
webid = pod + 'profile/card.jsonld#me';
webEl.textContent = webid;
webEl.className = '';
storEl.textContent = pod;
storEl.className = '';
}
input.addEventListener('input', render);
render();
})();
</script>
</body>
</html>