@bitblit/ratchet-warden-server 4.0.419-alpha → 4.0.421-alpha

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 (63) hide show
  1. package/lib/build/index.d.ts +1 -0
  2. package/lib/build/index.js +2 -0
  3. package/lib/build/index.js.map +1 -0
  4. package/lib/build/ratchet-warden-server-info.d.ts +5 -0
  5. package/lib/build/ratchet-warden-server-info.js +15 -0
  6. package/lib/build/ratchet-warden-server-info.js.map +1 -0
  7. package/lib/server/index.d.ts +17 -0
  8. package/lib/server/index.js +18 -0
  9. package/lib/server/index.js.map +1 -0
  10. package/lib/server/provider/warden-default-send-magic-link-command-validator.d.ts +6 -0
  11. package/lib/server/provider/warden-default-send-magic-link-command-validator.js +14 -0
  12. package/lib/server/provider/warden-default-send-magic-link-command-validator.js.map +1 -0
  13. package/lib/server/provider/warden-default-user-decoration-provider.d.ts +7 -0
  14. package/lib/server/provider/warden-default-user-decoration-provider.js +12 -0
  15. package/lib/server/provider/warden-default-user-decoration-provider.js.map +1 -0
  16. package/lib/server/provider/warden-event-processing-provider.d.ts +5 -0
  17. package/lib/server/provider/warden-event-processing-provider.js +2 -0
  18. package/lib/server/provider/warden-event-processing-provider.js.map +1 -0
  19. package/lib/server/provider/warden-mailer-and-expiring-code-ratchet-single-use-code-provider.d.ts +22 -0
  20. package/lib/server/provider/warden-mailer-and-expiring-code-ratchet-single-use-code-provider.js +101 -0
  21. package/lib/server/provider/warden-mailer-and-expiring-code-ratchet-single-use-code-provider.js.map +1 -0
  22. package/lib/server/provider/warden-mailer-and-expiring-code-ratchet-single-user-provider-options.d.ts +8 -0
  23. package/lib/server/provider/warden-mailer-and-expiring-code-ratchet-single-user-provider-options.js +2 -0
  24. package/lib/server/provider/warden-mailer-and-expiring-code-ratchet-single-user-provider-options.js.map +1 -0
  25. package/lib/server/provider/warden-message-sending-provider.d.ts +8 -0
  26. package/lib/server/provider/warden-message-sending-provider.js +2 -0
  27. package/lib/server/provider/warden-message-sending-provider.js.map +1 -0
  28. package/lib/server/provider/warden-no-op-event-processing-provider.d.ts +6 -0
  29. package/lib/server/provider/warden-no-op-event-processing-provider.js +5 -0
  30. package/lib/server/provider/warden-no-op-event-processing-provider.js.map +1 -0
  31. package/lib/server/provider/warden-s3-single-file-storage-provider-options.d.ts +4 -0
  32. package/lib/server/provider/warden-s3-single-file-storage-provider-options.js +2 -0
  33. package/lib/server/provider/warden-s3-single-file-storage-provider-options.js.map +1 -0
  34. package/lib/server/provider/warden-s3-single-file-storage-provider.d.ts +31 -0
  35. package/lib/server/provider/warden-s3-single-file-storage-provider.js +91 -0
  36. package/lib/server/provider/warden-s3-single-file-storage-provider.js.map +1 -0
  37. package/lib/server/provider/warden-send-magic-link-command-validator.d.ts +5 -0
  38. package/lib/server/provider/warden-send-magic-link-command-validator.js +2 -0
  39. package/lib/server/provider/warden-send-magic-link-command-validator.js.map +1 -0
  40. package/lib/server/provider/warden-single-use-code-provider.d.ts +9 -0
  41. package/lib/server/provider/warden-single-use-code-provider.js +2 -0
  42. package/lib/server/provider/warden-single-use-code-provider.js.map +1 -0
  43. package/lib/server/provider/warden-storage-provider.d.ts +12 -0
  44. package/lib/server/provider/warden-storage-provider.js +2 -0
  45. package/lib/server/provider/warden-storage-provider.js.map +1 -0
  46. package/lib/server/provider/warden-twilio-verify-single-use-code-provider-options.d.ts +5 -0
  47. package/lib/server/provider/warden-twilio-verify-single-use-code-provider-options.js +2 -0
  48. package/lib/server/provider/warden-twilio-verify-single-use-code-provider-options.js.map +1 -0
  49. package/lib/server/provider/warden-twilio-verify-single-use-code-provider.d.ts +13 -0
  50. package/lib/server/provider/warden-twilio-verify-single-use-code-provider.js +32 -0
  51. package/lib/server/provider/warden-twilio-verify-single-use-code-provider.js.map +1 -0
  52. package/lib/server/provider/warden-user-decoration-provider.d.ts +5 -0
  53. package/lib/server/provider/warden-user-decoration-provider.js +2 -0
  54. package/lib/server/provider/warden-user-decoration-provider.js.map +1 -0
  55. package/lib/server/warden-service-options.d.ts +16 -0
  56. package/lib/server/warden-service-options.js +2 -0
  57. package/lib/server/warden-service-options.js.map +1 -0
  58. package/lib/server/warden-service.d.ts +35 -0
  59. package/lib/server/warden-service.js +518 -0
  60. package/lib/server/warden-service.js.map +1 -0
  61. package/package.json +17 -18
  62. package/lib/index.mjs +0 -2
  63. package/lib/types.d.ts +0 -168
@@ -0,0 +1 @@
1
+ {"version":3,"file":"warden-twilio-verify-single-use-code-provider.js","sourceRoot":"","sources":["../../../src/server/provider/warden-twilio-verify-single-use-code-provider.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAE/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,kEAAkE,CAAC;AACvG,OAAO,EAAE,iBAAiB,EAAE,MAAM,iEAAiE,CAAC;AAGpG,MAAM,OAAO,uCAAuC;IAG9B;IAFZ,yBAAyB,CAAsB;IAEvD,YAAoB,WAAoE;QAApE,gBAAW,GAAX,WAAW,CAAyD;IAAG,CAAC;IAEpF,KAAK,CAAC,mBAAmB;QAC/B,IAAI,CAAC,IAAI,CAAC,yBAAyB,EAAE,CAAC;YACpC,MAAM,IAAI,GAAmD,MAAM,IAAI,CAAC,WAAW,CAAC;YACpF,IAAI,CAAC,yBAAyB,GAAG,IAAI,mBAAmB,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACnH,CAAC;QACD,OAAO,IAAI,CAAC,yBAAyB,CAAC;IACxC,CAAC;IAEM,kBAAkB,CAAC,IAAuB;QAC/C,OAAO,IAAI,KAAK,iBAAiB,CAAC,sBAAsB,CAAC;IAC3D,CAAC;IAEM,KAAK,CAAC,oBAAoB,CAAC,OAAsB,EAAE,uBAA+B;QAEvF,MAAM,OAAO,GAAwB,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACtE,MAAM,IAAI,GAAQ,MAAM,OAAO,CAAC,sCAAsC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;QACtF,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE,IAAI,CAAC,CAAC;QAC3C,OAAO,CAAC,CAAC,IAAI,CAAC;IAChB,CAAC;IACM,KAAK,CAAC,SAAS,CAAC,YAAoB,EAAE,IAAY;QACvD,MAAM,OAAO,GAAwB,MAAM,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACtE,MAAM,IAAI,GAAY,MAAM,OAAO,CAAC,6CAA6C,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC;QACtG,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ import { WardenEntry } from '@bitblit/ratchet-warden-common/common/model/warden-entry';
2
+ import { WardenUserDecoration } from '@bitblit/ratchet-warden-common/common/model/warden-user-decoration';
3
+ export interface WardenUserDecorationProvider<T> {
4
+ fetchDecoration(wardenUser: WardenEntry): Promise<WardenUserDecoration<T>>;
5
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=warden-user-decoration-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"warden-user-decoration-provider.js","sourceRoot":"","sources":["../../../src/server/provider/warden-user-decoration-provider.ts"],"names":[],"mappings":""}
@@ -0,0 +1,16 @@
1
+ import { WardenStorageProvider } from './provider/warden-storage-provider.js';
2
+ import { JwtRatchetLike } from '@bitblit/ratchet-common/jwt/jwt-ratchet-like';
3
+ import { WardenUserDecorationProvider } from './provider/warden-user-decoration-provider.js';
4
+ import { WardenEventProcessingProvider } from './provider/warden-event-processing-provider.js';
5
+ import { WardenSingleUseCodeProvider } from './provider/warden-single-use-code-provider.js';
6
+ import { WardenSendMagicLinkCommandValidator } from './provider/warden-send-magic-link-command-validator.js';
7
+ export interface WardenServiceOptions {
8
+ relyingPartyName: string;
9
+ allowedOrigins: string[];
10
+ singleUseCodeProviders: WardenSingleUseCodeProvider[];
11
+ storageProvider: WardenStorageProvider;
12
+ jwtRatchet: JwtRatchetLike;
13
+ userDecorationProvider?: WardenUserDecorationProvider<any>;
14
+ eventProcessor?: WardenEventProcessingProvider;
15
+ sendMagicLinkCommandValidator?: WardenSendMagicLinkCommandValidator;
16
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=warden-service-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"warden-service-options.js","sourceRoot":"","sources":["../../src/server/warden-service-options.ts"],"names":[],"mappings":""}
@@ -0,0 +1,35 @@
1
+ import { AuthenticationResponseJSON, PublicKeyCredentialCreationOptionsJSON, PublicKeyCredentialRequestOptionsJSON, RegistrationResponseJSON } from '@simplewebauthn/types';
2
+ import { WardenServiceOptions } from './warden-service-options.js';
3
+ import { WardenContact } from '@bitblit/ratchet-warden-common/common/model/warden-contact';
4
+ import { WardenCustomTemplateDescriptor } from '@bitblit/ratchet-warden-common/common/command/warden-custom-template-descriptor';
5
+ import { WardenEntry } from '@bitblit/ratchet-warden-common/common/model/warden-entry';
6
+ import { WardenLoginRequest } from '@bitblit/ratchet-warden-common/common/model/warden-login-request';
7
+ import { WardenCommand } from '@bitblit/ratchet-warden-common/common/command/warden-command';
8
+ import { WardenCommandResponse } from '@bitblit/ratchet-warden-common/common/command/warden-command-response';
9
+ import { WardenStoreRegistrationResponse } from '@bitblit/ratchet-warden-common/common/model/warden-store-registration-response';
10
+ import { WardenSingleUseCodeProvider } from './provider/warden-single-use-code-provider.js';
11
+ export declare class WardenService {
12
+ private inOptions;
13
+ private opts;
14
+ constructor(inOptions: WardenServiceOptions);
15
+ get options(): WardenServiceOptions;
16
+ findEntryByContact(contact: WardenContact): Promise<WardenEntry>;
17
+ findEntryById(userId: string): Promise<WardenEntry>;
18
+ processCommandStringToString(cmdString: string, origin: string, loggedInUserId: string): Promise<string>;
19
+ processCommandToResponse(cmd: WardenCommand, origin: string, loggedInUserId: string): Promise<WardenCommandResponse>;
20
+ urlIsOnAllowedOrigin(url: string): boolean;
21
+ singleUseCodeProvider(contact: WardenContact, requireMagicLinkSupport: boolean, returnNullIfNoProviders?: boolean): WardenSingleUseCodeProvider;
22
+ sendMagicLink(contact: WardenContact, overrideDestinationContact: WardenContact, relyingPartyName: string, landingUrl: string, metaIn?: Record<string, string>, ttlSeconds?: number, customTemplate?: WardenCustomTemplateDescriptor): Promise<boolean>;
23
+ createAccount(contact: WardenContact, sendCode?: boolean, label?: string, tags?: string[]): Promise<string>;
24
+ addContactMethodToUser(userId: string, contact: WardenContact): Promise<boolean>;
25
+ removeContactMethodFromUser(userId: string, contact: WardenContact): Promise<WardenEntry>;
26
+ generateWebAuthnRegistrationChallengeForLoggedInUser(userId: string, origin: string): Promise<PublicKeyCredentialCreationOptionsJSON>;
27
+ storeAuthnRegistration(userId: string, origin: string, applicationName: string, deviceLabel: string, data: RegistrationResponseJSON): Promise<WardenStoreRegistrationResponse>;
28
+ generateWebAuthnAuthenticationChallengeForUserId(userId: string, origin: string): Promise<PublicKeyCredentialRequestOptionsJSON>;
29
+ generateWebAuthnAuthenticationChallenge(user: WardenEntry, origin: string): Promise<PublicKeyCredentialRequestOptionsJSON>;
30
+ sendExpiringValidationToken(request: WardenContact): Promise<boolean>;
31
+ processLogin(request: WardenLoginRequest, origin: string): Promise<boolean>;
32
+ loginWithWebAuthnRequest(user: WardenEntry, origin: string, data: AuthenticationResponseJSON): Promise<boolean>;
33
+ removeSingleWebAuthnRegistration(userId: string, key: string): Promise<WardenEntry>;
34
+ removeUser(userId: string): Promise<boolean>;
35
+ }
@@ -0,0 +1,518 @@
1
+ import { generateAuthenticationOptions, generateRegistrationOptions, verifyAuthenticationResponse, verifyRegistrationResponse, } from '@simplewebauthn/server';
2
+ import { WardenUtils } from '@bitblit/ratchet-warden-common/common/util/warden-utils';
3
+ import { WardenStoreRegistrationResponseType } from '@bitblit/ratchet-warden-common/common/model/warden-store-registration-response-type';
4
+ import { RequireRatchet } from '@bitblit/ratchet-common/lang/require-ratchet';
5
+ import { Logger } from '@bitblit/ratchet-common/logger/logger';
6
+ import { ErrorRatchet } from '@bitblit/ratchet-common/lang/error-ratchet';
7
+ import { StringRatchet } from '@bitblit/ratchet-common/lang/string-ratchet';
8
+ import { Base64Ratchet } from '@bitblit/ratchet-common/lang/base64-ratchet';
9
+ import { WardenDefaultUserDecorationProvider } from './provider/warden-default-user-decoration-provider.js';
10
+ import { WardenNoOpEventProcessingProvider } from './provider/warden-no-op-event-processing-provider.js';
11
+ import { WardenDefaultSendMagicLinkCommandValidator } from './provider/warden-default-send-magic-link-command-validator.js';
12
+ export class WardenService {
13
+ inOptions;
14
+ opts;
15
+ constructor(inOptions) {
16
+ this.inOptions = inOptions;
17
+ RequireRatchet.notNullOrUndefined(inOptions, 'options');
18
+ RequireRatchet.notNullOrUndefined(inOptions.relyingPartyName, 'options.relyingPartyName');
19
+ RequireRatchet.notNullUndefinedOrEmptyArray(inOptions.allowedOrigins, 'options.allowedOrigins');
20
+ RequireRatchet.notNullOrUndefined(inOptions.storageProvider, 'options.storageProvider');
21
+ RequireRatchet.notNullOrUndefined(inOptions.jwtRatchet, 'options.jwtRatchet');
22
+ RequireRatchet.notNullUndefinedOrEmptyArray(inOptions.singleUseCodeProviders, 'options.singleUseCodeProviders');
23
+ this.opts = Object.assign({
24
+ userTokenDataProvider: new WardenDefaultUserDecorationProvider(),
25
+ eventProcessor: new WardenNoOpEventProcessingProvider(),
26
+ sendMagicLinkCommandValidator: new WardenDefaultSendMagicLinkCommandValidator(),
27
+ }, inOptions);
28
+ }
29
+ get options() {
30
+ return Object.assign({}, this.opts);
31
+ }
32
+ findEntryByContact(contact) {
33
+ return this.opts.storageProvider.findEntryByContact(contact);
34
+ }
35
+ findEntryById(userId) {
36
+ return this.opts.storageProvider.findEntryById(userId);
37
+ }
38
+ async processCommandStringToString(cmdString, origin, loggedInUserId) {
39
+ let rval = null;
40
+ try {
41
+ const cmd = JSON.parse(cmdString);
42
+ const resp = await this.processCommandToResponse(cmd, origin, loggedInUserId);
43
+ if (resp === null) {
44
+ Logger.warn('Response was null for %s %s %s', cmdString, origin, loggedInUserId);
45
+ }
46
+ else {
47
+ rval = JSON.stringify(resp);
48
+ }
49
+ }
50
+ catch (err) {
51
+ const errString = ErrorRatchet.safeStringifyErr(err);
52
+ Logger.error('Failed %s : %j', errString, cmdString, err);
53
+ rval = JSON.stringify({ error: errString });
54
+ }
55
+ return rval;
56
+ }
57
+ async processCommandToResponse(cmd, origin, loggedInUserId) {
58
+ let rval = null;
59
+ if (cmd) {
60
+ Logger.info('Processing command : UserID: %s Origin: %s Command: %j', loggedInUserId, origin, cmd);
61
+ if (cmd.sendExpiringValidationToken) {
62
+ rval = { sendExpiringValidationToken: await this.sendExpiringValidationToken(cmd.sendExpiringValidationToken) };
63
+ }
64
+ else if (cmd.generateWebAuthnAuthenticationChallengeForUserId) {
65
+ const tmp = await this.generateWebAuthnAuthenticationChallengeForUserId(cmd.generateWebAuthnAuthenticationChallengeForUserId, origin);
66
+ rval = { generateWebAuthnAuthenticationChallengeForUserId: { dataAsJson: JSON.stringify(tmp) } };
67
+ }
68
+ else if (cmd.createAccount) {
69
+ rval = {
70
+ createAccount: await this.createAccount(cmd.createAccount.contact, cmd.createAccount.sendCode, cmd.createAccount.label, cmd.createAccount.tags),
71
+ };
72
+ }
73
+ else if (cmd.sendMagicLink) {
74
+ if (cmd?.sendMagicLink?.contactLookup && cmd?.sendMagicLink?.contact) {
75
+ throw ErrorRatchet.fErr('You may not specify both contact and contactLookup');
76
+ }
77
+ if (!cmd?.sendMagicLink?.contactLookup && !cmd?.sendMagicLink?.contact) {
78
+ throw ErrorRatchet.fErr('You must not specify either contact and contactLookup');
79
+ }
80
+ if (cmd.sendMagicLink.contactLookup) {
81
+ const entry = await this.findEntryById(cmd.sendMagicLink.contactLookup.userId);
82
+ if (entry) {
83
+ if (cmd.sendMagicLink.contactLookup.contactType) {
84
+ cmd.sendMagicLink.contact = (entry.contactMethods || []).find((cm) => cm.type === cmd.sendMagicLink.contactLookup.contactType);
85
+ }
86
+ else {
87
+ cmd.sendMagicLink.contact = (entry.contactMethods || []).length > 0 ? entry.contactMethods[0] : null;
88
+ }
89
+ }
90
+ cmd.sendMagicLink.contactLookup = null;
91
+ }
92
+ if (!cmd.sendMagicLink.contact) {
93
+ throw ErrorRatchet.fErr('Could not find contract entry either directly or by lookup');
94
+ }
95
+ const loggedInUser = StringRatchet.trimToNull(loggedInUserId)
96
+ ? await this.opts.storageProvider.findEntryById(loggedInUserId)
97
+ : null;
98
+ await this.opts.sendMagicLinkCommandValidator.allowMagicLinkCommand(cmd.sendMagicLink, origin, loggedInUser);
99
+ const ttlSeconds = cmd?.sendMagicLink?.ttlSeconds || 300;
100
+ rval = {
101
+ sendMagicLink: await this.sendMagicLink(cmd.sendMagicLink.contact, cmd.sendMagicLink.overrideDestinationContact, this.opts.relyingPartyName, cmd.sendMagicLink.landingUrl, cmd.sendMagicLink.meta, ttlSeconds, cmd.sendMagicLink.customTemplate),
102
+ };
103
+ }
104
+ else if (cmd.generateWebAuthnRegistrationChallengeForLoggedInUser) {
105
+ if (!StringRatchet.trimToNull(loggedInUserId)) {
106
+ ErrorRatchet.throwFormattedErr('This requires a logged in user');
107
+ }
108
+ const tmp = await this.generateWebAuthnRegistrationChallengeForLoggedInUser(loggedInUserId, origin);
109
+ rval = { generateWebAuthnRegistrationChallengeForLoggedInUser: { dataAsJson: JSON.stringify(tmp) } };
110
+ }
111
+ else if (cmd.addContactToLoggedInUser) {
112
+ if (!WardenUtils.validContact(cmd.addContactToLoggedInUser)) {
113
+ ErrorRatchet.throwFormattedErr('Cannot add, invalid contact %j', cmd.addContactToLoggedInUser);
114
+ }
115
+ else {
116
+ const out = await this.addContactMethodToUser(loggedInUserId, cmd.addContactToLoggedInUser);
117
+ rval = { addContactToLoggedInUser: out };
118
+ }
119
+ }
120
+ else if (cmd.addWebAuthnRegistrationToLoggedInUser) {
121
+ if (!StringRatchet.trimToNull(loggedInUserId)) {
122
+ ErrorRatchet.throwFormattedErr('This requires a logged in user');
123
+ }
124
+ const data = JSON.parse(cmd.addWebAuthnRegistrationToLoggedInUser.webAuthn.dataAsJson);
125
+ const out = await this.storeAuthnRegistration(loggedInUserId, origin, cmd.addWebAuthnRegistrationToLoggedInUser.applicationName, cmd.addWebAuthnRegistrationToLoggedInUser.deviceLabel, data);
126
+ if (out.updatedEntry) {
127
+ rval = { addWebAuthnRegistrationToLoggedInUser: WardenUtils.stripWardenEntryToSummary(out.updatedEntry) };
128
+ }
129
+ else if (out.error) {
130
+ rval = { error: out.error };
131
+ }
132
+ else {
133
+ rval = { error: 'Cannot happen - neither user nor error set' };
134
+ }
135
+ }
136
+ else if (cmd.removeWebAuthnRegistration) {
137
+ const modified = await this.removeSingleWebAuthnRegistration(cmd.removeWebAuthnRegistration.userId, cmd.removeWebAuthnRegistration.credentialId);
138
+ rval = {
139
+ removeWebAuthnRegistration: WardenUtils.stripWardenEntryToSummary(modified),
140
+ };
141
+ }
142
+ else if (cmd.removeWebAuthnRegistrationFromLoggedInUser) {
143
+ const modified = await this.removeSingleWebAuthnRegistration(loggedInUserId, cmd.removeWebAuthnRegistrationFromLoggedInUser);
144
+ rval = {
145
+ removeWebAuthnRegistrationFromLoggedInUser: WardenUtils.stripWardenEntryToSummary(modified),
146
+ };
147
+ }
148
+ else if (cmd.removeContactFromLoggedInUser) {
149
+ const output = await this.removeContactMethodFromUser(loggedInUserId, cmd.removeContactFromLoggedInUser);
150
+ rval = {
151
+ removeContactFromLoggedInUser: WardenUtils.stripWardenEntryToSummary(output),
152
+ };
153
+ }
154
+ else if (cmd.performLogin) {
155
+ const loginData = cmd.performLogin;
156
+ const loginOk = await this.processLogin(loginData, origin);
157
+ Logger.info('Performing login - login auth check was : %s', loginOk);
158
+ if (loginOk) {
159
+ const user = StringRatchet.trimToNull(loginData.userId)
160
+ ? await this.opts.storageProvider.findEntryById(loginData.userId)
161
+ : await this.opts.storageProvider.findEntryByContact(loginData.contact);
162
+ const decoration = await this.opts.userDecorationProvider.fetchDecoration(user);
163
+ const wardenToken = {
164
+ loginData: WardenUtils.stripWardenEntryToSummary(user),
165
+ user: decoration.userTokenData,
166
+ roles: WardenUtils.teamRolesToRoles(decoration.userTeamRoles),
167
+ proxy: null,
168
+ };
169
+ const jwtToken = await this.opts.jwtRatchet.createTokenString(wardenToken, decoration.userTokenExpirationSeconds);
170
+ const output = {
171
+ request: loginData,
172
+ userId: user.userId,
173
+ jwtToken: jwtToken,
174
+ };
175
+ rval = { performLogin: output };
176
+ }
177
+ else {
178
+ rval = { error: 'Login failed' };
179
+ }
180
+ }
181
+ else if (cmd.refreshJwtToken) {
182
+ const parsed = await this.opts.jwtRatchet.decodeToken(cmd.refreshJwtToken, 1);
183
+ const user = await this.opts.storageProvider.findEntryById(parsed.loginData.userId);
184
+ const decoration = await this.opts.userDecorationProvider.fetchDecoration(user);
185
+ const wardenToken = {
186
+ loginData: WardenUtils.stripWardenEntryToSummary(user),
187
+ user: decoration.userTokenData,
188
+ roles: WardenUtils.teamRolesToRoles(decoration.userTeamRoles),
189
+ proxy: null,
190
+ };
191
+ const newToken = await this.opts.jwtRatchet.createTokenString(wardenToken, decoration.userTokenExpirationSeconds);
192
+ rval = {
193
+ refreshJwtToken: newToken,
194
+ };
195
+ }
196
+ }
197
+ else {
198
+ rval = { error: 'No command sent' };
199
+ }
200
+ return rval;
201
+ }
202
+ urlIsOnAllowedOrigin(url) {
203
+ let rval = false;
204
+ if (url) {
205
+ const u = new URL(url);
206
+ for (let i = 0; i < this.opts.allowedOrigins.length && !rval; i++) {
207
+ const test = new URL(this.opts.allowedOrigins[i]);
208
+ rval = test.origin === u.origin && test.protocol === u.protocol && test.port === u.port;
209
+ }
210
+ }
211
+ return rval;
212
+ }
213
+ singleUseCodeProvider(contact, requireMagicLinkSupport, returnNullIfNoProviders) {
214
+ const rval = this.opts.singleUseCodeProviders.find((s) => s.handlesContactType(contact.type) && (!requireMagicLinkSupport || s.createCodeAndSendMagicLink));
215
+ if (!rval && !returnNullIfNoProviders) {
216
+ throw ErrorRatchet.fErr('Cannot find a single use code provider for contact type : %s', contact.type);
217
+ }
218
+ return rval;
219
+ }
220
+ async sendMagicLink(contact, overrideDestinationContact, relyingPartyName, landingUrl, metaIn, ttlSeconds, customTemplate) {
221
+ let rval = false;
222
+ RequireRatchet.notNullOrUndefined(contact, 'contact');
223
+ RequireRatchet.notNullUndefinedOrOnlyWhitespaceString(landingUrl, 'landingUrl');
224
+ RequireRatchet.true(this.urlIsOnAllowedOrigin(landingUrl), 'landingUrl is not on an allowed origin for redirect');
225
+ if (contact?.type && StringRatchet.trimToNull(contact?.value)) {
226
+ const prov = this.singleUseCodeProvider(contact, true);
227
+ rval = await prov.createCodeAndSendMagicLink(contact, relyingPartyName, landingUrl, metaIn, ttlSeconds, overrideDestinationContact, customTemplate);
228
+ }
229
+ else {
230
+ ErrorRatchet.throwFormattedErr('Cannot send - invalid contact %j', contact);
231
+ }
232
+ return rval;
233
+ }
234
+ async createAccount(contact, sendCode, label, tags) {
235
+ let rval = null;
236
+ if (WardenUtils.validContact(contact)) {
237
+ const old = await this.opts.storageProvider.findEntryByContact(contact);
238
+ if (old) {
239
+ ErrorRatchet.throwFormattedErr('Cannot create - account already exists for %j', contact);
240
+ }
241
+ const guid = StringRatchet.createType4Guid();
242
+ const now = Date.now();
243
+ const newUser = {
244
+ userId: guid,
245
+ userLabel: label || 'User ' + guid,
246
+ contactMethods: [contact],
247
+ tags: tags || [],
248
+ webAuthnAuthenticators: [],
249
+ createdEpochMS: now,
250
+ updatedEpochMS: now,
251
+ };
252
+ const next = await this.opts.storageProvider.saveEntry(newUser);
253
+ rval = next.userId;
254
+ if (this?.opts?.eventProcessor) {
255
+ await this.opts.eventProcessor.userCreated(next);
256
+ }
257
+ if (sendCode) {
258
+ Logger.info('New user %j created and send requested - sending', next);
259
+ await this.sendExpiringValidationToken(contact);
260
+ }
261
+ }
262
+ else {
263
+ ErrorRatchet.throwFormattedErr('Cannot create - invalid contact (missing or invalid fields)');
264
+ }
265
+ return rval;
266
+ }
267
+ async addContactMethodToUser(userId, contact) {
268
+ let rval = false;
269
+ if (StringRatchet.trimToNull(userId) && WardenUtils.validContact(contact)) {
270
+ const otherUser = await this.opts.storageProvider.findEntryByContact(contact);
271
+ if (otherUser && otherUser.userId !== userId) {
272
+ ErrorRatchet.throwFormattedErr('Cannot add contact to this user, another user already has that contact');
273
+ }
274
+ const curUser = await this.opts.storageProvider.findEntryById(userId);
275
+ if (!curUser) {
276
+ ErrorRatchet.throwFormattedErr('Cannot add contact to this user, user does not exist');
277
+ }
278
+ curUser.contactMethods.push(contact);
279
+ await this.opts.storageProvider.saveEntry(curUser);
280
+ rval = true;
281
+ }
282
+ else {
283
+ ErrorRatchet.throwFormattedErr('Cannot add - invalid config : %s %j', userId, contact);
284
+ }
285
+ return rval;
286
+ }
287
+ async removeContactMethodFromUser(userId, contact) {
288
+ let rval = null;
289
+ if (StringRatchet.trimToNull(userId) && WardenUtils.validContact(contact)) {
290
+ const curUser = await this.opts.storageProvider.findEntryById(userId);
291
+ if (!curUser) {
292
+ ErrorRatchet.throwFormattedErr('Cannot remove contact from this user, user does not exist');
293
+ }
294
+ curUser.contactMethods = (curUser.contactMethods || []).filter((s) => s.type !== contact.type || s.value !== contact.value);
295
+ if (curUser.contactMethods.length === 0) {
296
+ ErrorRatchet.throwFormattedErr('Cannot remove the last contact method from a user');
297
+ }
298
+ await this.opts.storageProvider.saveEntry(curUser);
299
+ rval = await this.opts.storageProvider.findEntryById(userId);
300
+ }
301
+ else {
302
+ ErrorRatchet.throwFormattedErr('Cannot add - invalid config : %s %j', userId, contact);
303
+ }
304
+ return rval;
305
+ }
306
+ async generateWebAuthnRegistrationChallengeForLoggedInUser(userId, origin) {
307
+ if (!origin || !this.opts.allowedOrigins.includes(origin)) {
308
+ throw new Error('Invalid origin : ' + origin);
309
+ }
310
+ const asUrl = new URL(origin);
311
+ const rpID = asUrl.hostname;
312
+ const entry = await this.opts.storageProvider.findEntryById(userId);
313
+ if (!entry) {
314
+ throw ErrorRatchet.fErr('Cannot generateWebAuthnRegistrationChallengeForLoggedInUser - no user %s / %s', userId, origin);
315
+ }
316
+ const options = await generateRegistrationOptions({
317
+ rpName: this.opts.relyingPartyName,
318
+ rpID: rpID,
319
+ userID: StringRatchet.stringToUint8Array(entry.userId),
320
+ userName: entry.userLabel,
321
+ attestationType: 'none',
322
+ excludeCredentials: entry.webAuthnAuthenticators.map((authenticator) => ({
323
+ id: authenticator.credentialPublicKeyBase64,
324
+ transports: authenticator.transports,
325
+ })),
326
+ });
327
+ await this.opts.storageProvider.updateUserChallenge(entry.userId, rpID, options.challenge);
328
+ return options;
329
+ }
330
+ async storeAuthnRegistration(userId, origin, applicationName, deviceLabel, data) {
331
+ Logger.info('Store authn data : %j', data);
332
+ let rval = null;
333
+ try {
334
+ if (!origin || !this.opts.allowedOrigins.includes(origin)) {
335
+ throw new Error('Invalid origin : ' + origin);
336
+ }
337
+ const asUrl = new URL(origin);
338
+ const rpID = asUrl.hostname;
339
+ const user = await this.opts.storageProvider.findEntryById(userId);
340
+ if (!user) {
341
+ throw ErrorRatchet.fErr('Cannot storeAuthnRegistration - no user %s / %s', userId, origin);
342
+ }
343
+ const expectedChallenge = await this.opts.storageProvider.fetchCurrentUserChallenge(user.userId, rpID);
344
+ const vrOpts = {
345
+ response: data,
346
+ expectedChallenge: expectedChallenge,
347
+ expectedOrigin: origin,
348
+ expectedRPID: rpID,
349
+ };
350
+ Logger.info('Calling verifyRegistrationResponse: %j', vrOpts);
351
+ const verification = await verifyRegistrationResponse(vrOpts);
352
+ Logger.info('verifyRegistrationResponse Result : %j', verification);
353
+ rval = {
354
+ updatedEntry: null,
355
+ registrationResponseId: data.id,
356
+ result: verification.verified ? WardenStoreRegistrationResponseType.Verified : WardenStoreRegistrationResponseType.Failed,
357
+ };
358
+ if (rval.result === WardenStoreRegistrationResponseType.Verified) {
359
+ Logger.info('Storing registration');
360
+ const newAuth = {
361
+ origin: origin,
362
+ applicationName: applicationName || 'Unknown Application',
363
+ deviceLabel: deviceLabel || 'Unknown Device',
364
+ counter: verification.registrationInfo.counter,
365
+ credentialBackedUp: verification.registrationInfo.credentialBackedUp,
366
+ credentialDeviceType: verification.registrationInfo.credentialDeviceType,
367
+ credentialIdBase64: verification.registrationInfo.credentialID,
368
+ credentialPublicKeyBase64: Base64Ratchet.uint8ArrayToBase64UrlString(verification.registrationInfo.credentialPublicKey),
369
+ };
370
+ user.webAuthnAuthenticators = (user.webAuthnAuthenticators || []).filter((wa) => wa.credentialIdBase64 !== newAuth.credentialIdBase64);
371
+ user.webAuthnAuthenticators.push(newAuth);
372
+ const storedUser = await this.opts.storageProvider.saveEntry(user);
373
+ rval.updatedEntry = storedUser;
374
+ Logger.info('Stored auth : %j', storedUser);
375
+ }
376
+ }
377
+ catch (err) {
378
+ rval = {
379
+ registrationResponseId: data.id,
380
+ result: WardenStoreRegistrationResponseType.Error,
381
+ error: ErrorRatchet.safeStringifyErr(err),
382
+ };
383
+ }
384
+ return rval;
385
+ }
386
+ async generateWebAuthnAuthenticationChallengeForUserId(userId, origin) {
387
+ const user = await this.opts.storageProvider.findEntryById(userId);
388
+ const rval = await this.generateWebAuthnAuthenticationChallenge(user, origin);
389
+ return rval;
390
+ }
391
+ async generateWebAuthnAuthenticationChallenge(user, origin) {
392
+ const userAuthenticators = user.webAuthnAuthenticators;
393
+ if (!origin || !this.opts.allowedOrigins.includes(origin)) {
394
+ throw new Error('Invalid origin : ' + origin);
395
+ }
396
+ const asUrl = new URL(origin);
397
+ const rpID = asUrl.hostname;
398
+ const out = userAuthenticators.map((authenticator) => {
399
+ const next = {
400
+ id: authenticator.credentialIdBase64,
401
+ transports: authenticator.transports,
402
+ };
403
+ return next;
404
+ });
405
+ const opts = {
406
+ rpID: rpID,
407
+ allowCredentials: out,
408
+ userVerification: 'preferred',
409
+ };
410
+ const options = await generateAuthenticationOptions(opts);
411
+ await this.opts.storageProvider.updateUserChallenge(user.userId, rpID, options.challenge);
412
+ return options;
413
+ }
414
+ async sendExpiringValidationToken(request) {
415
+ let rval = false;
416
+ if (request?.type && StringRatchet.trimToNull(request?.value)) {
417
+ const prov = this.singleUseCodeProvider(request, false);
418
+ rval = await prov.createAndSendNewCode(request, this.opts.relyingPartyName);
419
+ }
420
+ else {
421
+ ErrorRatchet.throwFormattedErr('Cannot send - invalid request %j', request);
422
+ }
423
+ return rval;
424
+ }
425
+ async processLogin(request, origin) {
426
+ Logger.info('Processing login : %s : %j', origin, request);
427
+ let rval = false;
428
+ RequireRatchet.notNullOrUndefined(request, 'request');
429
+ RequireRatchet.true(!!StringRatchet.trimToNull(request?.userId) || WardenUtils.validContact(request?.contact), 'Invalid contact and no userId');
430
+ RequireRatchet.true(!!request?.webAuthn || !!StringRatchet.trimToNull(request?.expiringToken), 'You must provide one of webAuthn or expiringToken');
431
+ RequireRatchet.true(!request?.webAuthn || !StringRatchet.trimToNull(request?.expiringToken), 'WebAuthn and ExpiringToken may not BOTH be set');
432
+ let user = StringRatchet.trimToNull(request?.userId)
433
+ ? await this.opts.storageProvider.findEntryById(request?.userId)
434
+ : await this.opts.storageProvider.findEntryByContact(request.contact);
435
+ if (!user) {
436
+ Logger.info('User not found, and createUserIfMissing=%s / %j', request.createUserIfMissing, request.contact);
437
+ if (request.createUserIfMissing && request.contact) {
438
+ const newVal = await this.createAccount(request.contact);
439
+ Logger.info('Finished create, new id is %s', newVal);
440
+ user = await this.opts.storageProvider.findEntryById(newVal);
441
+ }
442
+ if (!user) {
443
+ ErrorRatchet.throwFormattedErr('No user found for %j / %s', request?.contact, request?.userId);
444
+ }
445
+ }
446
+ if (request.webAuthn) {
447
+ rval = await this.loginWithWebAuthnRequest(user, origin, request.webAuthn);
448
+ }
449
+ else if (StringRatchet.trimToNull(request.expiringToken)) {
450
+ const prov = this.singleUseCodeProvider(request.contact, false);
451
+ const lookup = await prov.checkCode(request.contact.value, request.expiringToken);
452
+ if (lookup) {
453
+ rval = true;
454
+ }
455
+ else {
456
+ ErrorRatchet.throwFormattedErr('Cannot login - token is invalid for this user');
457
+ }
458
+ }
459
+ return rval;
460
+ }
461
+ async loginWithWebAuthnRequest(user, origin, data) {
462
+ let rval = false;
463
+ const asUrl = new URL(origin);
464
+ const rpID = asUrl.hostname;
465
+ const expectedChallenge = await this.opts.storageProvider.fetchCurrentUserChallenge(user.userId, rpID);
466
+ const auth = (user.webAuthnAuthenticators || []).find((s) => s.credentialIdBase64 === data.id);
467
+ if (!auth) {
468
+ const allIds = (user.webAuthnAuthenticators || []).map((s) => s.credentialIdBase64);
469
+ throw ErrorRatchet.fErr('Could not find authenticator %s (%s) for user %s (avail were : %j)', data.id, data.id, user.userId, allIds);
470
+ }
471
+ const authenticator = {
472
+ counter: auth.counter,
473
+ credentialID: auth.credentialIdBase64,
474
+ credentialPublicKey: Base64Ratchet.base64UrlStringToBytes(auth.credentialPublicKeyBase64),
475
+ };
476
+ const vrOpts = {
477
+ response: data,
478
+ expectedChallenge,
479
+ expectedOrigin: origin,
480
+ expectedRPID: rpID,
481
+ authenticator,
482
+ };
483
+ const verification = await verifyAuthenticationResponse(vrOpts);
484
+ if (verification.verified) {
485
+ rval = true;
486
+ }
487
+ return rval;
488
+ }
489
+ async removeSingleWebAuthnRegistration(userId, key) {
490
+ let ent = await this.opts.storageProvider.findEntryById(userId);
491
+ if (ent) {
492
+ ent.webAuthnAuthenticators = (ent.webAuthnAuthenticators || []).filter((s) => s.credentialIdBase64 !== key);
493
+ ent = await this.opts.storageProvider.saveEntry(ent);
494
+ }
495
+ else {
496
+ Logger.info('Not removing - no such user as %s', userId);
497
+ }
498
+ return ent;
499
+ }
500
+ async removeUser(userId) {
501
+ let rval = false;
502
+ if (StringRatchet.trimToNull(userId)) {
503
+ const oldUser = await this.opts.storageProvider.findEntryById(userId);
504
+ if (oldUser) {
505
+ await this.opts.storageProvider.removeEntry(userId);
506
+ if (this?.opts?.eventProcessor) {
507
+ await this.opts.eventProcessor.userRemoved(oldUser);
508
+ }
509
+ rval = true;
510
+ }
511
+ else {
512
+ Logger.warn('Cannot remove non-existent user : %s', userId);
513
+ }
514
+ }
515
+ return rval;
516
+ }
517
+ }
518
+ //# sourceMappingURL=warden-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"warden-service.js","sourceRoot":"","sources":["../../src/server/warden-service.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,6BAA6B,EAE7B,2BAA2B,EAG3B,4BAA4B,EAE5B,0BAA0B,GAE3B,MAAM,wBAAwB,CAAC;AAahC,OAAO,EAAE,WAAW,EAAE,MAAM,yDAAyD,CAAC;AAQtF,OAAO,EAAE,mCAAmC,EAAE,MAAM,qFAAqF,CAAC;AAG1I,OAAO,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,uCAAuC,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAC1E,OAAO,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAG5E,OAAO,EAAE,mCAAmC,EAAE,MAAM,uDAAuD,CAAC;AAC5G,OAAO,EAAE,iCAAiC,EAAE,MAAM,sDAAsD,CAAC;AAEzG,OAAO,EAAE,0CAA0C,EAAE,MAAM,gEAAgE,CAAC;AAE5H,MAAM,OAAO,aAAa;IAGJ;IAFZ,IAAI,CAAuB;IAEnC,YAAoB,SAA+B;QAA/B,cAAS,GAAT,SAAS,CAAsB;QACjD,cAAc,CAAC,kBAAkB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QACxD,cAAc,CAAC,kBAAkB,CAAC,SAAS,CAAC,gBAAgB,EAAE,0BAA0B,CAAC,CAAC;QAC1F,cAAc,CAAC,4BAA4B,CAAC,SAAS,CAAC,cAAc,EAAE,wBAAwB,CAAC,CAAC;QAChG,cAAc,CAAC,kBAAkB,CAAC,SAAS,CAAC,eAAe,EAAE,yBAAyB,CAAC,CAAC;QACxF,cAAc,C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