@softistx/janus 0.74.0 → 0.76.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.
Files changed (50) hide show
  1. package/README.md +31 -6
  2. package/dist/auth/config/index.d.ts +1 -1
  3. package/dist/auth/config/index.d.ts.map +1 -1
  4. package/dist/auth/config/resolve-social.d.ts.map +1 -1
  5. package/dist/auth/config/social-config.d.ts +31 -0
  6. package/dist/auth/config/social-config.d.ts.map +1 -1
  7. package/dist/auth/index.d.ts +2 -2
  8. package/dist/auth/index.d.ts.map +1 -1
  9. package/dist/auth/passkeys/assert.d.ts +2 -0
  10. package/dist/auth/passkeys/assert.d.ts.map +1 -1
  11. package/dist/auth/passkeys/assertion-options.d.ts +1 -1
  12. package/dist/auth/passkeys/assertion-options.d.ts.map +1 -1
  13. package/dist/auth/passkeys/sign-in.d.ts +5 -2
  14. package/dist/auth/passkeys/sign-in.d.ts.map +1 -1
  15. package/dist/auth/second-factor/challenge.d.ts +2 -2
  16. package/dist/auth/second-factor/challenge.d.ts.map +1 -1
  17. package/dist/auth/second-factor/flows.d.ts +2 -2
  18. package/dist/auth/second-factor/flows.d.ts.map +1 -1
  19. package/dist/auth/second-factor/passkey-confirm.d.ts +2 -2
  20. package/dist/auth/second-factor/passkey-confirm.d.ts.map +1 -1
  21. package/dist/auth/second-factor/recovery.d.ts.map +1 -1
  22. package/dist/auth/sessions/amr.d.ts +1 -1
  23. package/dist/auth/social/complete.d.ts.map +1 -1
  24. package/dist/auth/social/federated-amr.d.ts +15 -0
  25. package/dist/auth/social/federated-amr.d.ts.map +1 -0
  26. package/dist/auth/social/find-provider.d.ts.map +1 -1
  27. package/dist/auth/social/finish.d.ts +2 -0
  28. package/dist/auth/social/finish.d.ts.map +1 -1
  29. package/dist/auth/step-up/passkey.d.ts.map +1 -1
  30. package/dist/auth/types/index.d.ts +2 -2
  31. package/dist/auth/types/index.d.ts.map +1 -1
  32. package/dist/auth/types/passkeys.d.ts +18 -3
  33. package/dist/auth/types/passkeys.d.ts.map +1 -1
  34. package/dist/auth/types/second-factor.d.ts +4 -2
  35. package/dist/auth/types/second-factor.d.ts.map +1 -1
  36. package/dist/auth/types/sign-in.d.ts +12 -0
  37. package/dist/auth/types/sign-in.d.ts.map +1 -1
  38. package/dist/auth/types/step-up.d.ts +4 -2
  39. package/dist/auth/types/step-up.d.ts.map +1 -1
  40. package/dist/index.js +127 -34
  41. package/dist/index.js.map +16 -15
  42. package/docs/guide/errors.md +1 -1
  43. package/docs/guide/passkeys.md +27 -4
  44. package/docs/guide/second-factor.md +1 -0
  45. package/docs/guide/sessions.md +1 -1
  46. package/docs/guide/social.md +41 -0
  47. package/docs/guide/step-up.md +2 -1
  48. package/docs/roadmap.md +4 -0
  49. package/docs/troubleshooting.md +19 -2
  50. package/package.json +1 -1
@@ -97,6 +97,18 @@ export interface SecondFactorRequired {
97
97
  }
98
98
  /** A way to answer a {@link SecondFactorRequired}. */
99
99
  export type SecondFactorMethod = 'totp' | 'passkey';
100
+ /**
101
+ * The proof that completed a second factor: the app's code (`'totp'`), a
102
+ * recovery code (`'recovery'`) or a passkey (`'passkey'`). Unlike
103
+ * {@link SecondFactorMethod}, which lists what a challenge offers, it names
104
+ * what was used, so an application can alert on `'recovery'`.
105
+ */
106
+ export type SecondFactorProof = 'totp' | 'recovery' | 'passkey';
107
+ /** A sign-in completed by a second factor, saying which proof completed it. */
108
+ export type SecondFactorSignedIn<U, M extends SecondFactorProof = SecondFactorProof> = SignedIn<U> & {
109
+ /** The proof used. The session's `amr` is the same for `'totp'` and `'recovery'`. */
110
+ readonly method: M;
111
+ };
100
112
  /** What `signIn` answers once a second factor is configured: switch on `status`. */
101
113
  export type SignInResult<U> = SignedIn<U> | SecondFactorRequired;
102
114
  //# sourceMappingURL=sign-in.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sign-in.d.ts","sourceRoot":"","sources":["../../../src/auth/types/sign-in.ts"],"names":[],"mappings":"AAAA;;;;;GA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MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC5D;AAED,sDAAsD;AACtD,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,SAAS,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,UAAU,GAAG,SAAS,CAAC;AAEhE,+EAA+E;AAC/E,MAAM,MAAM,oBAAoB,CAC/B,CAAC,EACD,CAAC,SAAS,iBAAiB,GAAG,iBAAiB,IAC5C,QAAQ,CAAC,CAAC,CAAC,GAAG;IACjB,qFAAqF;IACrF,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;CACnB,CAAC;AAEF,oFAAoF;AACpF,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAC,GAAG,oBAAoB,CAAC"}
@@ -63,7 +63,8 @@ export interface StepUpPasskeyApi<U> {
63
63
  * Issues a challenge the user answers with a passkey
64
64
  * (`via: 'passkey'`). Nothing is sent. **One step-up is live per
65
65
  * user**, as for the other kinds. `SECOND_FACTOR_NOT_ENROLLED` when the
66
- * user holds no passkey, `NOT_FOUND` for no such user, `USER_INACTIVE`
66
+ * user holds no passkey, or has no active TOTP while `passkeys.firstFactor`
67
+ * is off, `NOT_FOUND` for no such user, `USER_INACTIVE`
67
68
  * for an inactive one.
68
69
  */
69
70
  request(user: UserRef, options: {
@@ -75,7 +76,8 @@ export interface StepUpPasskeyApi<U> {
75
76
  * `confirm` does for a code. A challenge takes **five attempts**: an
76
77
  * assertion that does not verify is `CODE_INVALID` with `attemptsLeft`,
77
78
  * and the fifth spends it. A counter that went backwards is refused
78
- * the same way and emits `user.passkeyCloneSuspected`. The other
79
+ * the same way and emits `user.passkeyCloneSuspected`. With no active TOTP
80
+ * (`passkeys.firstFactor`), user verification is required. The other
79
81
  * refusals are `confirm`'s.
80
82
  */
81
83
  confirmPasskey(request: RequestLike, challenge: string, assertion: unknown): Promise<Session>;
@@ -1 +1 @@
1
- {"version":3,"file":"step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;;;;;;;;;WAWG;QACH,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QACxC;;;;;;;;;;;;;;;;;;;;WAoBG;QACH,OAAO,CACN,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,GACV,OAAO,CAAC,OAAO,CAAC,CAAC;KACpB,CAAC;CACF"}
package/dist/index.js CHANGED
@@ -833,6 +833,93 @@ function resolveSecondFactor(config, where) {
833
833
  };
834
834
  }
835
835
 
836
+ // src/auth/sessions/amr.ts
837
+ var AMR = {
838
+ password: ["pwd"],
839
+ oneTimeCode: ["otp"],
840
+ passkey: ["hwk", "user"],
841
+ appCode: ["otp", "mfa"],
842
+ recoveryCode: ["otp", "mfa"],
843
+ passkeySecondFactor: ["hwk", "user", "mfa"],
844
+ social: ["fed"]
845
+ };
846
+ function mergeAmr(a, b) {
847
+ return [...new Set([...a ?? [], ...b])];
848
+ }
849
+ function isMultiFactor(session) {
850
+ const { amr } = session;
851
+ return amr.includes("mfa") || amr.includes("hwk") && amr.includes("user");
852
+ }
853
+
854
+ // src/auth/social/federated-amr.ts
855
+ var GRANTABLE = new Set([
856
+ "pwd",
857
+ "otp",
858
+ "hwk",
859
+ "user",
860
+ "mfa",
861
+ "sms",
862
+ "swk",
863
+ "pin",
864
+ "fpt",
865
+ "face",
866
+ "iris",
867
+ "retina",
868
+ "mca",
869
+ "sc",
870
+ "tel",
871
+ "vbm",
872
+ "geo",
873
+ "kba",
874
+ "rba",
875
+ "wia"
876
+ ]);
877
+ var MAX_REPORTED_AMR = 16;
878
+ function checkFederatedAmr(mapping, at) {
879
+ if (mapping === undefined)
880
+ return;
881
+ const fail = (why) => new TypeError(`${at}: federatedAmr: ${why}`);
882
+ if (mapping === null || typeof mapping !== "object") {
883
+ throw fail("must be { acr?: Record, amr?: Record }");
884
+ }
885
+ for (const [name, table] of Object.entries(mapping)) {
886
+ if (name !== "acr" && name !== "amr") {
887
+ throw fail("an unknown key: acr and amr only");
888
+ }
889
+ if (table === null || typeof table !== "object" || Array.isArray(table)) {
890
+ throw fail(`${name} must map each upstream value to an array of methods`);
891
+ }
892
+ for (const methods of Object.values(table)) {
893
+ if (!Array.isArray(methods) || methods.length === 0 || methods.some((m) => typeof m !== "string" || !GRANTABLE.has(m))) {
894
+ throw fail(`${name}: every entry must be a non-empty array of RFC 8176 methods (${[...GRANTABLE].join(", ")})`);
895
+ }
896
+ }
897
+ }
898
+ }
899
+ function grantable(granted) {
900
+ return Array.isArray(granted) ? granted.filter((m) => typeof m === "string" && GRANTABLE.has(m)) : [];
901
+ }
902
+ var own = (table, key) => table !== null && typeof table === "object" && Object.hasOwn(table, key) ? table[key] : undefined;
903
+ function federatedMethods(mapping, identity) {
904
+ let methods = [...AMR.social];
905
+ if (mapping === undefined || mapping === null)
906
+ return methods;
907
+ const { acr, amr } = identity;
908
+ const byAcr = own(mapping, "acr");
909
+ const byAmr = own(mapping, "amr");
910
+ if (typeof acr === "string") {
911
+ methods = mergeAmr(methods, grantable(own(byAcr, acr)));
912
+ }
913
+ if (Array.isArray(amr)) {
914
+ for (const value of amr.slice(0, MAX_REPORTED_AMR)) {
915
+ if (typeof value === "string") {
916
+ methods = mergeAmr(methods, grantable(own(byAmr, value)));
917
+ }
918
+ }
919
+ }
920
+ return methods;
921
+ }
922
+
836
923
  // src/auth/config/resolve-social.ts
837
924
  var PROVIDER_NAME = /^[a-z][a-z0-9-]{0,31}$/;
838
925
  function resolveSocial(social, type, at) {
@@ -857,6 +944,7 @@ function resolveSocial(social, type, at) {
857
944
  if (!isSocialProvider(provider)) {
858
945
  throw new TypeError(`${at}: social.providers.${name} must be a provider — an object with authorizationUrl and exchange, such as google() from @softistx/janus-social`);
859
946
  }
947
+ checkFederatedAmr(provider.federatedAmr, `${at}: social.providers.${name}`);
860
948
  providers.set(name, provider);
861
949
  }
862
950
  const signUp = social.signUp ?? false;
@@ -2842,24 +2930,6 @@ function sharedApi(context) {
2842
2930
  types: [...config.types.keys()]
2843
2931
  };
2844
2932
  }
2845
- // src/auth/sessions/amr.ts
2846
- var AMR = {
2847
- password: ["pwd"],
2848
- oneTimeCode: ["otp"],
2849
- passkey: ["hwk", "user"],
2850
- appCode: ["otp", "mfa"],
2851
- recoveryCode: ["otp", "mfa"],
2852
- passkeySecondFactor: ["hwk", "user", "mfa"],
2853
- social: ["fed"]
2854
- };
2855
- function mergeAmr(a, b) {
2856
- return [...new Set([...a ?? [], ...b])];
2857
- }
2858
- function isMultiFactor(session) {
2859
- const { amr } = session;
2860
- return amr.includes("mfa") || amr.includes("hwk") && amr.includes("user");
2861
- }
2862
-
2863
2933
  // src/auth/sign-in-attempts.ts
2864
2934
  var PURPOSE3 = "janus/sign-in/attempts/v1";
2865
2935
  async function countLogin(context, type, login, where) {
@@ -2985,7 +3055,7 @@ async function acceptAssertion(context, user, given, where) {
2985
3055
  return checkAssertion(context, user, held, {
2986
3056
  assertion: given.assertion,
2987
3057
  expectedChallenge: assertionChallenge(sealer, given.purpose, given.secret),
2988
- requireUserVerified: false
3058
+ requireUserVerified: given.requireUserVerified ?? false
2989
3059
  }, where);
2990
3060
  }
2991
3061
  async function checkAssertion(context, user, held, given, where) {
@@ -3045,6 +3115,7 @@ async function signInOptions(context, where) {
3045
3115
  async function signInWithPasskey(context, type, given, where) {
3046
3116
  const { store } = requireFirstFactor(context, where);
3047
3117
  const device = deviceHint(context, given.options, where);
3118
+ const guard = guardOf(given.options, where);
3048
3119
  const challenge = given.challenge;
3049
3120
  if (typeof challenge !== "string" || challenge === "") {
3050
3121
  throw unknownOneTime(where, "challenge");
@@ -3070,7 +3141,10 @@ async function signInWithPasskey(context, type, given, where) {
3070
3141
  assertion: given.response,
3071
3142
  expectedChallenge: challenge,
3072
3143
  requireUserVerified: true,
3073
- beforeRecord: async () => refuseAfterPassword(type, record, where)
3144
+ beforeRecord: async () => {
3145
+ refuseAfterPassword(type, record, where);
3146
+ await guard?.(toUser(record));
3147
+ }
3074
3148
  }, where);
3075
3149
  if (!accepted)
3076
3150
  throw refuse();
@@ -3078,6 +3152,13 @@ async function signInWithPasskey(context, type, given, where) {
3078
3152
  await reportNewDevice(context, signedIn);
3079
3153
  return signedIn;
3080
3154
  }
3155
+ function guardOf(options, where) {
3156
+ const guard = options?.guard;
3157
+ if (guard !== undefined && typeof guard !== "function") {
3158
+ throw new TypeError(`${where}: options.guard must be a function`);
3159
+ }
3160
+ return guard;
3161
+ }
3081
3162
  function userHandleOf(response) {
3082
3163
  const handle = response?.response?.userHandle;
3083
3164
  return typeof handle === "string" && handle !== "" ? handle : null;
@@ -3820,7 +3901,7 @@ function provenSignInFlows(context, type, at, finish) {
3820
3901
  }
3821
3902
 
3822
3903
  // src/auth/passkeys/assertion-options.ts
3823
- async function assertionOptions(context, userId, purpose, secret, where) {
3904
+ async function assertionOptions(context, userId, purpose, secret, where, requireUserVerified = false) {
3824
3905
  const settings = context.config.passkeys;
3825
3906
  const store = context.store.passkeys;
3826
3907
  if (settings === null || store === undefined)
@@ -3830,7 +3911,7 @@ async function assertionOptions(context, userId, purpose, secret, where) {
3830
3911
  return null;
3831
3912
  const sealer = requireSettings(context, where, "a passkey challenge is being made").sealer;
3832
3913
  return settings.verifier.authenticationOptions({
3833
- rp: settings.rp,
3914
+ rp: requireUserVerified ? { ...settings.rp, userVerification: "required" } : settings.rp,
3834
3915
  challenge: assertionChallenge(sealer, purpose, secret),
3835
3916
  allow: held.map((passkey) => ({
3836
3917
  credentialId: passkey.credentialId,
@@ -3979,7 +4060,7 @@ async function confirmChallenge(context, type, challenge, code, at, options) {
3979
4060
  await restartSignInCount(context, type, written, where);
3980
4061
  const signedIn = await openSession(context, type, written, device, false, secondFactorAmr(opened, AMR.appCode));
3981
4062
  await reportNewDevice(context, signedIn);
3982
- return signedIn;
4063
+ return { ...signedIn, method: "totp" };
3983
4064
  }
3984
4065
 
3985
4066
  // src/auth/second-factor/codes-left.ts
@@ -4212,7 +4293,7 @@ async function confirmWithPasskey(context, type, given, at) {
4212
4293
  await restartSignInCount(context, type, record, where);
4213
4294
  const signedIn = await openSession(context, type, record, device, false, secondFactorAmr(opened, AMR.passkeySecondFactor));
4214
4295
  await reportNewDevice(context, signedIn);
4215
- return signedIn;
4296
+ return { ...signedIn, method: "passkey" };
4216
4297
  }
4217
4298
 
4218
4299
  // src/auth/second-factor/recovery.ts
@@ -4241,7 +4322,11 @@ async function recoverWithCode(context, type, given, at) {
4241
4322
  await emit(context, "user.recoveryCodeUsed", written, written.updatedAt);
4242
4323
  }
4243
4324
  await reportNewDevice(context, signedIn);
4244
- return { ...signedIn, recoveryCodesLeft: recoveryCodes.length };
4325
+ return {
4326
+ ...signedIn,
4327
+ method: "recovery",
4328
+ recoveryCodesLeft: recoveryCodes.length
4329
+ };
4245
4330
  }
4246
4331
 
4247
4332
  // src/auth/second-factor/reseal.ts
@@ -4396,9 +4481,9 @@ var spendStepUp = (context, secret, where) => spendOneTime(context, secret, "ste
4396
4481
  // src/auth/step-up/passkey.ts
4397
4482
  var PASSKEY_MARK = "passkey";
4398
4483
  async function byPasskey(context, type, record, where) {
4399
- requirePasskeys(context, where);
4400
- if (!isActive(record.secondFactor)) {
4401
- throw new SecondFactorError2("SECOND_FACTOR_NOT_ENROLLED", `${where}: the user has no active second factor — a passkey is only registered beside one`, { operation: where, userId: record.id, userType: type.name });
4484
+ const { settings } = requirePasskeys(context, where);
4485
+ if (!settings.firstFactor && !isActive(record.secondFactor)) {
4486
+ throw new SecondFactorError2("SECOND_FACTOR_NOT_ENROLLED", `${where}: the user has no active second factor — a passkey is only registered beside one (or turn on passkeys.firstFactor)`, { operation: where, userId: record.id, userType: type.name });
4402
4487
  }
4403
4488
  const { secret, expiresAt } = await issueOneTime(context, {
4404
4489
  kind: "stepUp",
@@ -4406,7 +4491,7 @@ async function byPasskey(context, type, record, where) {
4406
4491
  address: PASSKEY_MARK,
4407
4492
  ttlMs: context.config.tokenTtlMs.stepUp
4408
4493
  });
4409
- const options = await assertionOptions(context, record.id, "stepUp", secret, where);
4494
+ const options = await assertionOptions(context, record.id, "stepUp", secret, where, !isActive(record.secondFactor));
4410
4495
  if (options === null) {
4411
4496
  await burnOneTime(context, secret, "stepUp");
4412
4497
  throw new SecondFactorError2("SECOND_FACTOR_NOT_ENROLLED", `${where}: the user holds no passkey — register one, or request the step-up without via`, { operation: where, userId: record.id, userType: type.name });
@@ -4424,11 +4509,17 @@ async function checkPasskey(context, type, user, counted, assertion, where) {
4424
4509
  if (token.address !== PASSKEY_MARK) {
4425
4510
  throw await unknownChallenge(context, token, secret, where);
4426
4511
  }
4427
- if (!isActive(user.secondFactor)) {
4512
+ const { settings } = requirePasskeys(context, where);
4513
+ if (!settings.firstFactor && !isActive(user.secondFactor)) {
4428
4514
  await spendStepUp(context, secret, where);
4429
4515
  throw new SecondFactorError2("SECOND_FACTOR_NOT_ENROLLED", `${where}: the user no longer has a second factor — request a step-up again`, { operation: where, userId: user.id, userType: type.name });
4430
4516
  }
4431
- const accepted = await acceptAssertion(context, user, { assertion, purpose: "stepUp", secret }, where);
4517
+ const accepted = await acceptAssertion(context, user, {
4518
+ assertion,
4519
+ purpose: "stepUp",
4520
+ secret,
4521
+ requireUserVerified: !isActive(user.secondFactor)
4522
+ }, where);
4432
4523
  if (!accepted) {
4433
4524
  if (attemptsLeft === 0)
4434
4525
  await burnOneTime(context, secret, "stepUp");
@@ -5975,7 +6066,7 @@ function afterFlow(ending, provider) {
5975
6066
  };
5976
6067
  }
5977
6068
  async function finishSocial(ending, record, outcome) {
5978
- const { context, type, finish, device, returnTo, stepUp, where } = ending;
6069
+ const { context, type, finish, device, returnTo, stepUp, amr, where } = ending;
5979
6070
  if (!record.active) {
5980
6071
  throw new UserInactiveError2(`${where}: the user is inactive`, {
5981
6072
  userId: record.id,
@@ -5983,7 +6074,7 @@ async function finishSocial(ending, record, outcome) {
5983
6074
  ...afterFlow(ending)
5984
6075
  });
5985
6076
  }
5986
- const result = await finish(record, where, device, AMR.social);
6077
+ const result = await finish(record, where, device, amr);
5987
6078
  await reportNewDevice(context, result);
5988
6079
  return result.status === "signedIn" ? { ...result, ...outcome, returnTo, stepUp } : { ...result, provider: outcome.provider, returnTo, stepUp };
5989
6080
  }
@@ -6136,6 +6227,7 @@ async function findProvider(social, name, staticNames) {
6136
6227
  if (!isSocialProvider(resolved)) {
6137
6228
  throw new TypeError(`social.resolveProvider("${name}") must answer a provider — an object with authorizationUrl and exchange — or null`);
6138
6229
  }
6230
+ checkFederatedAmr(resolved.federatedAmr, `social.resolveProvider("${name}")`);
6139
6231
  return resolved;
6140
6232
  }
6141
6233
 
@@ -6551,6 +6643,7 @@ async function completeFlow(context, finishers, input, options) {
6551
6643
  device,
6552
6644
  returnTo: meta.returnTo,
6553
6645
  stepUp,
6646
+ amr: federatedMethods(configured.federatedAmr, identity),
6554
6647
  where: WHERE7
6555
6648
  };
6556
6649
  return redeemed.userId === null ? signInAccount(ending, meta.provider, identity) : completeLink(ending, redeemed.userId, meta.provider, identity);
@@ -6944,5 +7037,5 @@ export {
6944
7037
  systemClock
6945
7038
  };
6946
7039
 
6947
- //# debugId=0EFDFA41D3F43A2F64756E2164756E21
7040
+ //# debugId=FF3059166E410A0064756E2164756E21
6948
7041
  //# sourceMappingURL=index.js.map