@softistx/janus 0.78.0 → 0.79.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.
- package/README.md +35 -13
- package/dist/auth/config/index.d.ts +1 -1
- package/dist/auth/config/index.d.ts.map +1 -1
- package/dist/auth/config/resolve-social.d.ts +1 -1
- package/dist/auth/config/resolve-social.d.ts.map +1 -1
- package/dist/auth/config/resolved-config.d.ts +3 -1
- package/dist/auth/config/resolved-config.d.ts.map +1 -1
- package/dist/auth/config/social-config.d.ts +31 -0
- package/dist/auth/config/social-config.d.ts.map +1 -1
- package/dist/auth/events.d.ts +3 -2
- package/dist/auth/events.d.ts.map +1 -1
- package/dist/auth/first-proof.d.ts +10 -2
- package/dist/auth/first-proof.d.ts.map +1 -1
- package/dist/auth/index.d.ts +1 -1
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/shared-api.d.ts.map +1 -1
- package/dist/auth/social/complete-link.d.ts +9 -1
- package/dist/auth/social/complete-link.d.ts.map +1 -1
- package/dist/auth/social/complete.d.ts +1 -0
- package/dist/auth/social/complete.d.ts.map +1 -1
- package/dist/auth/social/finish.d.ts +3 -0
- package/dist/auth/social/finish.d.ts.map +1 -1
- package/dist/auth/social/link-holder.d.ts +10 -1
- package/dist/auth/social/link-holder.d.ts.map +1 -1
- package/dist/auth/social/redeem.d.ts +2 -0
- package/dist/auth/social/redeem.d.ts.map +1 -1
- package/dist/auth/social/replace-holder.d.ts +37 -0
- package/dist/auth/social/replace-holder.d.ts.map +1 -0
- package/dist/auth/social/sign-in.d.ts +4 -1
- package/dist/auth/social/sign-in.d.ts.map +1 -1
- package/dist/auth/social/sign-up.d.ts +1 -0
- package/dist/auth/social/sign-up.d.ts.map +1 -1
- package/dist/auth/types/social.d.ts +4 -1
- package/dist/auth/types/social.d.ts.map +1 -1
- package/dist/index.js +91 -19
- package/dist/index.js.map +14 -13
- package/docs/guide/email-flows.md +6 -1
- package/docs/guide/errors.md +3 -3
- package/docs/guide/events.md +7 -7
- package/docs/guide/magic-link.md +1 -1
- package/docs/guide/social.md +102 -5
- package/docs/roadmap.md +1 -0
- package/docs/troubleshooting.md +21 -0
- package/package.json +1 -1
|
@@ -34,7 +34,9 @@ export interface SocialLinked<U> {
|
|
|
34
34
|
* - `signedIn`: a session, as every sign-in answers. `created` is whether a
|
|
35
35
|
* user was made for this account; `linked` whether this call linked the
|
|
36
36
|
* account (a sign-up or a match by e-mail), `false` for an account that was
|
|
37
|
-
* linked already
|
|
37
|
+
* linked already; `replaced` whether this call took over a user who held
|
|
38
|
+
* the e-mail and never proved it (`social.unverifiedHolder`): their
|
|
39
|
+
* credentials, links and sessions are gone. Record it in the audit trail.
|
|
38
40
|
* - `secondFactor`: the user has an active second factor; confirm it with
|
|
39
41
|
* `secondFactor.confirm`. Present only when `Challenge` is.
|
|
40
42
|
* - `linked`: a link flow completed.
|
|
@@ -47,6 +49,7 @@ export type SocialCompleted<U, Challenge extends SecondFactorRequired = SecondFa
|
|
|
47
49
|
readonly provider: string;
|
|
48
50
|
readonly created: boolean;
|
|
49
51
|
readonly linked: boolean;
|
|
52
|
+
readonly replaced: boolean;
|
|
50
53
|
readonly returnTo: string | null;
|
|
51
54
|
readonly stepUp: SocialStepUpProof | null;
|
|
52
55
|
}) | (Challenge & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"social.d.ts","sourceRoot":"","sources":["../../../src/auth/types/social.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,KAAK,EAAE,oBAAoB,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC/E,OAAO,KAAK,EAAE,eAAe,E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C,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACnD,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EACjB,WAAW,CAAC,CAAC,CAAC,EACd,eAAe,CAAC,CAAC,CAAC,EAClB,eAAe,CAAC,CAAC,EAAE,SAAS,CAAC,CAC7B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -982,10 +982,15 @@ function resolveSocial(social, type, at) {
|
|
|
982
982
|
if (signUp !== false && type.login !== null && type.login !== type.email) {
|
|
983
983
|
throw new TypeError(`${at}: social.signUp needs a type whose login is its e-mail — password.login is "${type.login}", not "${type.email}"`);
|
|
984
984
|
}
|
|
985
|
+
const unverifiedHolder = social.unverifiedHolder ?? "refuse";
|
|
986
|
+
if (unverifiedHolder !== "refuse" && unverifiedHolder !== "replace" && typeof unverifiedHolder !== "function") {
|
|
987
|
+
throw new TypeError(`${at}: social.unverifiedHolder must be 'refuse', 'replace' or a function that takes the holder and the profile and answers one of them`);
|
|
988
|
+
}
|
|
985
989
|
return {
|
|
986
990
|
providers,
|
|
987
991
|
resolveProvider,
|
|
988
992
|
signUp,
|
|
993
|
+
unverifiedHolder,
|
|
989
994
|
freshWithinMs: parseDuration(social.freshWithin ?? "10m", `${at}: social.freshWithin`)
|
|
990
995
|
};
|
|
991
996
|
}
|
|
@@ -2167,8 +2172,10 @@ async function sweepWaitingFactorPasskeys(context, type, user, where) {
|
|
|
2167
2172
|
}
|
|
2168
2173
|
|
|
2169
2174
|
// src/auth/first-proof.ts
|
|
2170
|
-
async function proveFirstEmail(context, type, user, where) {
|
|
2171
|
-
|
|
2175
|
+
async function proveFirstEmail(context, type, user, where, options = {}) {
|
|
2176
|
+
if (options.revokeFirst !== false) {
|
|
2177
|
+
await endWhatTheSquatterOpened(context, user);
|
|
2178
|
+
}
|
|
2172
2179
|
let dropped = false;
|
|
2173
2180
|
let disabled = false;
|
|
2174
2181
|
let formerAvatarId = null;
|
|
@@ -2183,6 +2190,7 @@ async function proveFirstEmail(context, type, user, where) {
|
|
|
2183
2190
|
...formerAvatarId === null ? {} : { avatar: null }
|
|
2184
2191
|
};
|
|
2185
2192
|
});
|
|
2193
|
+
options.onWritten?.();
|
|
2186
2194
|
try {
|
|
2187
2195
|
await endWhatTheSquatterOpened(context, proved);
|
|
2188
2196
|
} finally {
|
|
@@ -2210,6 +2218,12 @@ async function proveFirstEmail(context, type, user, where) {
|
|
|
2210
2218
|
}
|
|
2211
2219
|
return proved;
|
|
2212
2220
|
}
|
|
2221
|
+
var LEFT_WAITING = [
|
|
2222
|
+
"changeEmail",
|
|
2223
|
+
"socialFlow",
|
|
2224
|
+
"passkeyRegistration",
|
|
2225
|
+
"stepUp"
|
|
2226
|
+
];
|
|
2213
2227
|
async function endWhatTheSquatterOpened(context, user) {
|
|
2214
2228
|
const userId = user.id;
|
|
2215
2229
|
await endEach([
|
|
@@ -2219,7 +2233,8 @@ async function endWhatTheSquatterOpened(context, user) {
|
|
|
2219
2233
|
const count = await context.apiKeys?.revokeUserApiKeys(userId, at);
|
|
2220
2234
|
await keysRevoked(context, user, at, count ?? 0);
|
|
2221
2235
|
},
|
|
2222
|
-
() => endWhatThePasswordOpened(context, userId)
|
|
2236
|
+
() => endWhatThePasswordOpened(context, userId),
|
|
2237
|
+
...LEFT_WAITING.map((kind) => () => context.store.tokens.spendUserTokens(userId, kind, context.clock.now()))
|
|
2223
2238
|
]);
|
|
2224
2239
|
}
|
|
2225
2240
|
|
|
@@ -6375,9 +6390,9 @@ function accountTaken(ending, provider) {
|
|
|
6375
6390
|
}
|
|
6376
6391
|
|
|
6377
6392
|
// src/auth/social/complete-link.ts
|
|
6378
|
-
async function completeLink(ending,
|
|
6393
|
+
async function completeLink(ending, flow, provider, identity) {
|
|
6379
6394
|
const { context, type, returnTo, stepUp, where } = ending;
|
|
6380
|
-
const record = await getRecord(context, userId, type.name, where);
|
|
6395
|
+
const record = await getRecord(context, flow.userId, type.name, where);
|
|
6381
6396
|
if (!record.active) {
|
|
6382
6397
|
throw new UserInactiveError2(`${where}: the user is inactive`, {
|
|
6383
6398
|
userId: record.id,
|
|
@@ -6385,6 +6400,9 @@ async function completeLink(ending, userId, provider, identity) {
|
|
|
6385
6400
|
...afterFlow(ending)
|
|
6386
6401
|
});
|
|
6387
6402
|
}
|
|
6403
|
+
if (record.emailVerifiedAt !== null && record.emailVerifiedAt.getTime() > flow.startedAt.getTime()) {
|
|
6404
|
+
throw new SocialError2("FLOW_MISMATCH", `${where}: the user's e-mail was proved after this link was started — start it again`, { provider, flowSpent: true });
|
|
6405
|
+
}
|
|
6388
6406
|
const attached = await attachLink(context, record, provider, identity);
|
|
6389
6407
|
if (attached.taken)
|
|
6390
6408
|
throw accountTaken(ending, provider);
|
|
@@ -6712,31 +6730,79 @@ async function redeemFlow(context, input, where) {
|
|
|
6712
6730
|
meta,
|
|
6713
6731
|
provider,
|
|
6714
6732
|
values,
|
|
6715
|
-
userId: meta.link ? token.userId : null
|
|
6733
|
+
userId: meta.link ? token.userId : null,
|
|
6734
|
+
startedAt: token.createdAt
|
|
6716
6735
|
};
|
|
6717
6736
|
}
|
|
6718
6737
|
|
|
6738
|
+
// src/auth/social/replace-holder.ts
|
|
6739
|
+
async function allowsReplacing(ending, holder, provider, identity) {
|
|
6740
|
+
const policy = ending.type.social?.unverifiedHolder ?? "refuse";
|
|
6741
|
+
if (typeof policy !== "function")
|
|
6742
|
+
return policy === "replace";
|
|
6743
|
+
const answer = await policy(Object.freeze({ id: holder.id, type: holder.type }), Object.freeze({ ...identity, provider }));
|
|
6744
|
+
return answer === "replace";
|
|
6745
|
+
}
|
|
6746
|
+
async function replaceHolder(ending, record) {
|
|
6747
|
+
const { context, type, where } = ending;
|
|
6748
|
+
let written = false;
|
|
6749
|
+
try {
|
|
6750
|
+
return await proveFirstEmail(context, type, record, where, {
|
|
6751
|
+
revokeFirst: false,
|
|
6752
|
+
onWritten: () => {
|
|
6753
|
+
written = true;
|
|
6754
|
+
}
|
|
6755
|
+
});
|
|
6756
|
+
} finally {
|
|
6757
|
+
if (written)
|
|
6758
|
+
await dropLinks(context, record);
|
|
6759
|
+
}
|
|
6760
|
+
}
|
|
6761
|
+
async function dropLinks(context, user) {
|
|
6762
|
+
const store = linkStore(context);
|
|
6763
|
+
for (const link of await store.listUserSocialLinks(user.id)) {
|
|
6764
|
+
if (await store.deleteSocialLink(user.id, link.provider, link.accountId)) {
|
|
6765
|
+
await emit(context, "user.socialUnlinked", user, context.clock.now(), {
|
|
6766
|
+
provider: link.provider
|
|
6767
|
+
});
|
|
6768
|
+
}
|
|
6769
|
+
}
|
|
6770
|
+
}
|
|
6771
|
+
|
|
6719
6772
|
// src/auth/social/link-holder.ts
|
|
6720
6773
|
async function linkHolder(ending, holder, provider, identity) {
|
|
6721
|
-
const { context, where } = ending;
|
|
6722
|
-
|
|
6723
|
-
|
|
6724
|
-
|
|
6725
|
-
const
|
|
6726
|
-
if (!
|
|
6774
|
+
const { context, type, where } = ending;
|
|
6775
|
+
const unverified = () => new SocialError2("EMAIL_NOT_VERIFIED_FOR_LINK", `${where}: a user holds this e-mail, and the provider or the account does not vouch for it — sign in another way, then link the account`, afterFlow(ending, provider));
|
|
6776
|
+
if (!identity.emailVerified)
|
|
6777
|
+
throw unverified();
|
|
6778
|
+
const replacing = holder.emailVerifiedAt === null;
|
|
6779
|
+
if (replacing && !await allowsReplacing(ending, holder, provider, identity)) {
|
|
6780
|
+
throw unverified();
|
|
6781
|
+
}
|
|
6782
|
+
const read = await getRecord(context, holder.id, holder.type, where);
|
|
6783
|
+
if (!read.active) {
|
|
6727
6784
|
throw new UserInactiveError2(`${where}: the user is inactive`, {
|
|
6728
|
-
userId:
|
|
6729
|
-
userType:
|
|
6785
|
+
userId: read.id,
|
|
6786
|
+
userType: read.type,
|
|
6730
6787
|
...afterFlow(ending)
|
|
6731
6788
|
});
|
|
6732
6789
|
}
|
|
6790
|
+
let record = read;
|
|
6791
|
+
if (read.emailVerifiedAt === null) {
|
|
6792
|
+
const held = emailOf(type, read.fields);
|
|
6793
|
+
if (!replacing || identity.email === null || held === null || normalizeEmail(held) !== normalizeEmail(identity.email)) {
|
|
6794
|
+
throw unverified();
|
|
6795
|
+
}
|
|
6796
|
+
record = await replaceHolder(ending, read);
|
|
6797
|
+
}
|
|
6733
6798
|
const attached = await attachLink(context, record, provider, identity);
|
|
6734
6799
|
if (attached.taken)
|
|
6735
6800
|
throw accountTaken(ending, provider);
|
|
6736
6801
|
return finishSocial(ending, record, {
|
|
6737
6802
|
provider,
|
|
6738
6803
|
created: false,
|
|
6739
|
-
linked: attached.won
|
|
6804
|
+
linked: attached.won,
|
|
6805
|
+
replaced: record !== read
|
|
6740
6806
|
});
|
|
6741
6807
|
}
|
|
6742
6808
|
|
|
@@ -6777,7 +6843,8 @@ async function signUpNew(ending, provider, identity) {
|
|
|
6777
6843
|
return finishSocial(ending, written, {
|
|
6778
6844
|
provider,
|
|
6779
6845
|
created: true,
|
|
6780
|
-
linked: true
|
|
6846
|
+
linked: true,
|
|
6847
|
+
replaced: false
|
|
6781
6848
|
});
|
|
6782
6849
|
}
|
|
6783
6850
|
function mustBeTheirs(fields, ending, email) {
|
|
@@ -6808,7 +6875,8 @@ async function signInAccount(ending, provider, identity) {
|
|
|
6808
6875
|
return finishSocial(ending, record, {
|
|
6809
6876
|
provider,
|
|
6810
6877
|
created: false,
|
|
6811
|
-
linked: false
|
|
6878
|
+
linked: false,
|
|
6879
|
+
replaced: false
|
|
6812
6880
|
});
|
|
6813
6881
|
}
|
|
6814
6882
|
await store.deleteSocialLink(link.userId, provider, identity.accountId);
|
|
@@ -6902,7 +6970,11 @@ async function completeFlow(context, finishers, input, options) {
|
|
|
6902
6970
|
amr: federatedMethods(configured.federatedAmr, identity),
|
|
6903
6971
|
where: WHERE8
|
|
6904
6972
|
};
|
|
6905
|
-
return
|
|
6973
|
+
return endFlow(ending, redeemed, identity);
|
|
6974
|
+
}
|
|
6975
|
+
function endFlow(ending, redeemed, identity) {
|
|
6976
|
+
const { userId, startedAt, meta } = redeemed;
|
|
6977
|
+
return userId === null ? signInAccount(ending, meta.provider, identity) : completeLink(ending, { userId, startedAt }, meta.provider, identity);
|
|
6906
6978
|
}
|
|
6907
6979
|
|
|
6908
6980
|
// src/auth/social/return-to.ts
|
|
@@ -7365,5 +7437,5 @@ export {
|
|
|
7365
7437
|
verifyToken
|
|
7366
7438
|
};
|
|
7367
7439
|
|
|
7368
|
-
//# debugId=
|
|
7440
|
+
//# debugId=51DCD587093E020564756E2164756E21
|
|
7369
7441
|
//# sourceMappingURL=index.js.map
|