@ofidj/generator-fidj 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -409,6 +409,32 @@ function render() {
409
409
  config.ownCredentials ? credentialFields() : "",
410
410
  isFidjItself,
411
411
  );
412
+ // On Fidj itself there is nobody to hand the person to, so the credential
413
+ // screen is fetched straight away: what they see is the form, or their name.
414
+ // Once per document, and never once the provider has already answered — a
415
+ // refusal or a cancellation must not bounce them round again.
416
+ if (
417
+ oidc &&
418
+ isFidjItself &&
419
+ // Only from the sign-in screen. Without this it fired on every render where
420
+ // nobody was signed in — including the recovery screens, so a person opening
421
+ // a password-reset link was handed a sign-in form instead of the reset they
422
+ // had asked for, and could never finish.
423
+ element("signin") &&
424
+ !askedProvider &&
425
+ !interactionId &&
426
+ !signedIn &&
427
+ // Nor when the shell has something to say. A password reset ends on this
428
+ // screen with "your password has been changed"; leaving for the provider
429
+ // would swallow the one confirmation the person was waiting for.
430
+ !message
431
+ ) {
432
+ askedProvider = true;
433
+ void (async () => {
434
+ if (!(await providerRendersHere())) return;
435
+ window.location.assign(await oidc.beginLogin());
436
+ })();
437
+ }
412
438
 
413
439
  element("forget-hint")?.addEventListener("click", () => {
414
440
  forgetSignIn(config.appId);
@@ -594,6 +620,25 @@ const refusals: Record<string, string> = {
594
620
  // dashboard it points people to is itself. "Sign in with Fidj" is the right
595
621
  // label on an app that is not Fidj; here it names a provider the person is
596
622
  // standing in, and hides the form behind a click that only fetches it.
623
+ let askedProvider = false;
624
+ // Whether the provider renders its sign-in on this front end. A deployment
625
+ // decides that, so the shell asks rather than assumes: hopping to a provider
626
+ // that answers with its own page would land the person on the API's origin,
627
+ // which is the thing this is meant to avoid.
628
+ let signinOnThisUi: boolean | null = null;
629
+ async function providerRendersHere() {
630
+ if (signinOnThisUi !== null) return signinOnThisUi;
631
+ try {
632
+ const response = await fetch(
633
+ new URL("status", config.apiEndpoint.replace(/\/?$/, "/")).href,
634
+ {signal: AbortSignal.timeout(5000)},
635
+ );
636
+ signinOnThisUi = response.ok && (await response.json()).signin === "fidj-ui";
637
+ } catch {
638
+ signinOnThisUi = false;
639
+ }
640
+ return signinOnThisUi;
641
+ }
597
642
  const isFidjItself = (() => {
598
643
  try {
599
644
  return new URL(config.dashboardUrl).origin === window.location.origin;
@@ -649,10 +694,14 @@ function interactionScreen() {
649
694
  try {
650
695
  typed = sessionStorage.getItem("fidj.interaction.email") || "";
651
696
  } catch {}
697
+ // Fidj signing into Fidj: saying "the account behind fidj" and "fidj never
698
+ // sees your password" about itself is nonsense in the same family as offering
699
+ // to sign in with Fidj on Fidj.
700
+ const itself = details.app.id === config.appId;
652
701
  const body =
653
702
  details.prompt === "login"
654
- ? `<h2>Sign in to continue to ${asking}</h2>
655
- <p class="signin-lead">This is Fidj, the account behind ${asking}. One account, and separate choices for every app that uses it — ${asking} never sees your password.</p>
703
+ ? `<h2>${itself ? "Sign in to Fidj" : "Sign in to continue to " + asking}</h2>
704
+ <p class="signin-lead">${itself ? "One account across every app that uses Fidj, and a separate set of choices for each one." : `This is Fidj, the account behind ${asking}. One account, and separate choices for every app that uses it — ${asking} never sees your password.`}</p>
656
705
  ${notice}
657
706
  <form method="post" action="${escape(action)}" id="interaction">
658
707
  <input type="hidden" name="csrf" value="${escape(details.csrf)}">
@@ -663,8 +712,8 @@ function interactionScreen() {
663
712
  <button class="secondary" type="submit" name="action" value="signup">Create a Fidj account</button>
664
713
  <button class="quiet" type="submit" name="action" value="cancel" formnovalidate>Cancel and go back</button>
665
714
  </form>`
666
- : `<h2>Continue to ${asking}</h2>
667
- <p class="signin-lead">${asking} is asking for the information below. Optional privacy choices stay separate, and you can change them in Fidj at any time.</p>
715
+ : `<h2>${itself ? "Continue to Fidj" : "Continue to " + asking}</h2>
716
+ <p class="signin-lead">${itself ? "Fidj is asking for the information below. Optional privacy choices stay separate for every app, including this one." : `${asking} is asking for the information below. Optional privacy choices stay separate, and you can change them in Fidj at any time.`}</p>
668
717
  ${notice}
669
718
  <ul class="scope-list">${details.scopes
670
719
  .filter((scope) => scopeMeaning[scope])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ofidj/generator-fidj",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "Generate a TypeScript app with Fidj sign-in, live server-side roles and per-app privacy.",
5
5
  "homepage": "https://fidj.ovh",
6
6
  "bugs": {