@casual-simulation/aux-records 3.2.16 → 3.2.17-alpha.8117520706
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/AAGUID.d.ts +11 -0
- package/AAGUID.js +100 -0
- package/AAGUID.js.map +1 -0
- package/AuthController.d.ts +171 -3
- package/AuthController.js +426 -1
- package/AuthController.js.map +1 -1
- package/AuthStore.d.ts +182 -0
- package/Base64UrlUtils.d.ts +16 -0
- package/Base64UrlUtils.js +59 -0
- package/Base64UrlUtils.js.map +1 -0
- package/FileRecordsStore.d.ts +12 -1
- package/MemoryFileRecordsLookup.d.ts +1 -1
- package/MemoryFileRecordsLookup.js +4 -1
- package/MemoryFileRecordsLookup.js.map +1 -1
- package/MemoryStore.d.ts +14 -1
- package/MemoryStore.js +89 -0
- package/MemoryStore.js.map +1 -1
- package/RecordsServer.d.ts +6 -0
- package/RecordsServer.js +214 -0
- package/RecordsServer.js.map +1 -1
- package/Utils.d.ts +1 -1
- package/Utils.js +3 -0
- package/Utils.js.map +1 -1
- package/package.json +5 -3
package/AuthController.js
CHANGED
|
@@ -15,6 +15,8 @@ import { cleanupObject, isActiveSubscription, isStringValid, } from './Utils';
|
|
|
15
15
|
import { formatV1ConnectionKey, formatV1SessionKey, parseSessionKey, randomCode, verifyConnectionToken, } from './AuthUtils';
|
|
16
16
|
import { parseConnectionToken, } from '@casual-simulation/aux-common';
|
|
17
17
|
import { DateTime } from 'luxon';
|
|
18
|
+
import { generateAuthenticationOptions, generateRegistrationOptions, verifyAuthenticationResponse, verifyRegistrationResponse, } from '@simplewebauthn/server';
|
|
19
|
+
import { base64URLStringToBuffer, bufferToBase64URLString, } from './Base64UrlUtils';
|
|
18
20
|
/**
|
|
19
21
|
* The number of miliseconds that a login request should be valid for before expiration.
|
|
20
22
|
*/
|
|
@@ -23,6 +25,10 @@ export const LOGIN_REQUEST_LIFETIME_MS = 1000 * 60 * 5; // 5 minutes
|
|
|
23
25
|
* The number of miliseconds that an Open ID login request should be valid for before expiration.
|
|
24
26
|
*/
|
|
25
27
|
export const OPEN_ID_LOGIN_REQUEST_LIFETIME_MS = 1000 * 60 * 20; // 20 minutes
|
|
28
|
+
/**
|
|
29
|
+
* The number of miliseconds that a WebAuthN request should be valid for before expiration.
|
|
30
|
+
*/
|
|
31
|
+
export const WEB_AUTHN_LOGIN_REQUEST_LIFETIME_MS = 1000 * 60 * 5; // 5 minutes
|
|
26
32
|
/**
|
|
27
33
|
* The number of bytes that should be used for login request IDs.
|
|
28
34
|
*/
|
|
@@ -79,13 +85,20 @@ export const PRIVO_OPEN_ID_PROVIDER = 'privo';
|
|
|
79
85
|
* Defines a class that is able to authenticate users.
|
|
80
86
|
*/
|
|
81
87
|
export class AuthController {
|
|
82
|
-
|
|
88
|
+
get relyingParties() {
|
|
89
|
+
return this._webAuthNRelyingParties;
|
|
90
|
+
}
|
|
91
|
+
set relyingParties(value) {
|
|
92
|
+
this._webAuthNRelyingParties = value;
|
|
93
|
+
}
|
|
94
|
+
constructor(authStore, messenger, configStore, forceAllowSubscriptionFeatures = false, privoClient = null, relyingParties = []) {
|
|
83
95
|
this._privoClient = null;
|
|
84
96
|
this._store = authStore;
|
|
85
97
|
this._messenger = messenger;
|
|
86
98
|
this._config = configStore;
|
|
87
99
|
this._forceAllowSubscriptionFeatures = forceAllowSubscriptionFeatures;
|
|
88
100
|
this._privoClient = privoClient;
|
|
101
|
+
this._webAuthNRelyingParties = relyingParties;
|
|
89
102
|
}
|
|
90
103
|
requestLogin(request) {
|
|
91
104
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -835,6 +848,404 @@ export class AuthController {
|
|
|
835
848
|
}
|
|
836
849
|
});
|
|
837
850
|
}
|
|
851
|
+
requestWebAuthnRegistration(request) {
|
|
852
|
+
var _a;
|
|
853
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
854
|
+
try {
|
|
855
|
+
if (this._webAuthNRelyingParties.length <= 0) {
|
|
856
|
+
return {
|
|
857
|
+
success: false,
|
|
858
|
+
errorCode: 'not_supported',
|
|
859
|
+
errorMessage: 'WebAuthn is not supported on this server.',
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
const relyingParty = findRelyingPartyForOrigin(this._webAuthNRelyingParties, request.originOrHost);
|
|
863
|
+
if (!relyingParty) {
|
|
864
|
+
return {
|
|
865
|
+
success: false,
|
|
866
|
+
errorCode: 'invalid_origin',
|
|
867
|
+
errorMessage: 'The request must be made from an authorized origin.',
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
const user = yield this._store.findUser(request.userId);
|
|
871
|
+
if (!user) {
|
|
872
|
+
return {
|
|
873
|
+
success: false,
|
|
874
|
+
errorCode: 'not_logged_in',
|
|
875
|
+
errorMessage: 'You need to be logged in for the operation to work.',
|
|
876
|
+
};
|
|
877
|
+
}
|
|
878
|
+
const authenticators = yield this._store.listUserAuthenticators(user.id);
|
|
879
|
+
const options = yield generateRegistrationOptions({
|
|
880
|
+
rpName: relyingParty.name,
|
|
881
|
+
rpID: relyingParty.id,
|
|
882
|
+
userID: user.id,
|
|
883
|
+
userName: (_a = user.email) !== null && _a !== void 0 ? _a : user.phoneNumber,
|
|
884
|
+
attestationType: 'none',
|
|
885
|
+
excludeCredentials: authenticators.map((auth) => ({
|
|
886
|
+
id: base64URLStringToBuffer(auth.credentialId),
|
|
887
|
+
type: 'public-key',
|
|
888
|
+
transports: auth.transports,
|
|
889
|
+
})),
|
|
890
|
+
authenticatorSelection: {
|
|
891
|
+
residentKey: 'preferred',
|
|
892
|
+
userVerification: 'preferred',
|
|
893
|
+
authenticatorAttachment: 'platform',
|
|
894
|
+
},
|
|
895
|
+
});
|
|
896
|
+
yield this._store.setCurrentWebAuthnChallenge(user.id, options.challenge);
|
|
897
|
+
return {
|
|
898
|
+
success: true,
|
|
899
|
+
options,
|
|
900
|
+
};
|
|
901
|
+
}
|
|
902
|
+
catch (err) {
|
|
903
|
+
console.error(`[AuthController] Error occurred while requesting WebAuthn registration options`, err);
|
|
904
|
+
return {
|
|
905
|
+
success: false,
|
|
906
|
+
errorCode: 'server_error',
|
|
907
|
+
errorMessage: 'A server error occurred.',
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
completeWebAuthnRegistration(request) {
|
|
913
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
914
|
+
try {
|
|
915
|
+
if (this._webAuthNRelyingParties.length <= 0) {
|
|
916
|
+
return {
|
|
917
|
+
success: false,
|
|
918
|
+
errorCode: 'not_supported',
|
|
919
|
+
errorMessage: 'WebAuthn is not supported on this server.',
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
const relyingParty = findRelyingPartyForOrigin(this._webAuthNRelyingParties, request.originOrHost);
|
|
923
|
+
if (!relyingParty) {
|
|
924
|
+
return {
|
|
925
|
+
success: false,
|
|
926
|
+
errorCode: 'invalid_origin',
|
|
927
|
+
errorMessage: 'The request must be made from an authorized origin.',
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
const user = yield this._store.findUser(request.userId);
|
|
931
|
+
if (!user) {
|
|
932
|
+
return {
|
|
933
|
+
success: false,
|
|
934
|
+
errorCode: 'not_logged_in',
|
|
935
|
+
errorMessage: 'You need to be logged in for the operation to work.',
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
const currentChallenge = user.currentWebAuthnChallenge;
|
|
939
|
+
try {
|
|
940
|
+
const verification = yield verifyRegistrationResponse({
|
|
941
|
+
response: request.response,
|
|
942
|
+
expectedChallenge: currentChallenge,
|
|
943
|
+
expectedOrigin: relyingParty.origin,
|
|
944
|
+
expectedRPID: relyingParty.id,
|
|
945
|
+
});
|
|
946
|
+
if (verification.verified) {
|
|
947
|
+
const registration = verification.registrationInfo;
|
|
948
|
+
const credentialId = bufferToBase64URLString(registration.credentialID);
|
|
949
|
+
const authenticator = {
|
|
950
|
+
id: uuid(),
|
|
951
|
+
userId: user.id,
|
|
952
|
+
credentialId,
|
|
953
|
+
credentialPublicKey: registration.credentialPublicKey,
|
|
954
|
+
counter: registration.counter,
|
|
955
|
+
credentialBackedUp: registration.credentialBackedUp,
|
|
956
|
+
credentialDeviceType: registration.credentialDeviceType,
|
|
957
|
+
transports: request.response.response.transports,
|
|
958
|
+
aaguid: verification.registrationInfo.aaguid,
|
|
959
|
+
registeringUserAgent: request.userAgent,
|
|
960
|
+
createdAtMs: Date.now(),
|
|
961
|
+
};
|
|
962
|
+
yield this._store.setCurrentWebAuthnChallenge(user.id, null);
|
|
963
|
+
yield this._store.saveUserAuthenticator(authenticator);
|
|
964
|
+
return {
|
|
965
|
+
success: true,
|
|
966
|
+
};
|
|
967
|
+
}
|
|
968
|
+
else {
|
|
969
|
+
return {
|
|
970
|
+
success: false,
|
|
971
|
+
errorCode: 'not_authorized',
|
|
972
|
+
errorMessage: 'The registration response was not authorized.',
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
catch (err) {
|
|
977
|
+
console.error(`[AuthController] Error occurred while verifying WebAuthn registration response`, err);
|
|
978
|
+
return {
|
|
979
|
+
success: false,
|
|
980
|
+
errorCode: 'unacceptable_request',
|
|
981
|
+
errorMessage: err.message,
|
|
982
|
+
};
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
catch (err) {
|
|
986
|
+
console.error(`[AuthController] Error occurred while completing WebAuthn registration`, err);
|
|
987
|
+
return {
|
|
988
|
+
success: false,
|
|
989
|
+
errorCode: 'server_error',
|
|
990
|
+
errorMessage: 'A server error occurred.',
|
|
991
|
+
};
|
|
992
|
+
}
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
requestWebAuthnLogin(request) {
|
|
996
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
997
|
+
try {
|
|
998
|
+
if (this._webAuthNRelyingParties.length <= 0) {
|
|
999
|
+
return {
|
|
1000
|
+
success: false,
|
|
1001
|
+
errorCode: 'not_supported',
|
|
1002
|
+
errorMessage: 'WebAuthn is not supported on this server.',
|
|
1003
|
+
};
|
|
1004
|
+
}
|
|
1005
|
+
const relyingParty = findRelyingPartyForOrigin(this._webAuthNRelyingParties, request.originOrHost);
|
|
1006
|
+
if (!relyingParty) {
|
|
1007
|
+
return {
|
|
1008
|
+
success: false,
|
|
1009
|
+
errorCode: 'invalid_origin',
|
|
1010
|
+
errorMessage: 'The request must be made from an authorized origin.',
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
const options = yield generateAuthenticationOptions({
|
|
1014
|
+
rpID: relyingParty.id,
|
|
1015
|
+
userVerification: 'preferred',
|
|
1016
|
+
});
|
|
1017
|
+
const requestId = uuid();
|
|
1018
|
+
const nowMs = Date.now();
|
|
1019
|
+
yield this._store.saveWebAuthnLoginRequest({
|
|
1020
|
+
requestId: requestId,
|
|
1021
|
+
challenge: options.challenge,
|
|
1022
|
+
requestTimeMs: nowMs,
|
|
1023
|
+
expireTimeMs: nowMs + WEB_AUTHN_LOGIN_REQUEST_LIFETIME_MS,
|
|
1024
|
+
completedTimeMs: null,
|
|
1025
|
+
ipAddress: request.ipAddress,
|
|
1026
|
+
userId: null,
|
|
1027
|
+
});
|
|
1028
|
+
return {
|
|
1029
|
+
success: true,
|
|
1030
|
+
requestId,
|
|
1031
|
+
options,
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
catch (err) {
|
|
1035
|
+
console.error(`[AuthController] Error occurred while requesting WebAuthn login`, err);
|
|
1036
|
+
return {
|
|
1037
|
+
success: false,
|
|
1038
|
+
errorCode: 'server_error',
|
|
1039
|
+
errorMessage: 'A server error occurred.',
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
});
|
|
1043
|
+
}
|
|
1044
|
+
completeWebAuthnLogin(request) {
|
|
1045
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1046
|
+
try {
|
|
1047
|
+
if (this._webAuthNRelyingParties.length <= 0) {
|
|
1048
|
+
return {
|
|
1049
|
+
success: false,
|
|
1050
|
+
errorCode: 'not_supported',
|
|
1051
|
+
errorMessage: 'WebAuthn is not supported on this server.',
|
|
1052
|
+
};
|
|
1053
|
+
}
|
|
1054
|
+
const relyingParty = findRelyingPartyForOrigin(this._webAuthNRelyingParties, request.originOrHost);
|
|
1055
|
+
if (!relyingParty) {
|
|
1056
|
+
return {
|
|
1057
|
+
success: false,
|
|
1058
|
+
errorCode: 'invalid_origin',
|
|
1059
|
+
errorMessage: 'The request must be made from an authorized origin.',
|
|
1060
|
+
};
|
|
1061
|
+
}
|
|
1062
|
+
const loginRequest = yield this._store.findWebAuthnLoginRequest(request.requestId);
|
|
1063
|
+
if (!loginRequest) {
|
|
1064
|
+
console.error('could not find login request!');
|
|
1065
|
+
return {
|
|
1066
|
+
success: false,
|
|
1067
|
+
errorCode: 'invalid_request',
|
|
1068
|
+
errorMessage: INVALID_REQUEST_ERROR_MESSAGE,
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
let validRequest = true;
|
|
1072
|
+
if (Date.now() >= loginRequest.expireTimeMs) {
|
|
1073
|
+
console.error('Expired!');
|
|
1074
|
+
validRequest = false;
|
|
1075
|
+
}
|
|
1076
|
+
else if (loginRequest.completedTimeMs > 0) {
|
|
1077
|
+
console.error('Completed!');
|
|
1078
|
+
validRequest = false;
|
|
1079
|
+
}
|
|
1080
|
+
else if (loginRequest.ipAddress !== request.ipAddress) {
|
|
1081
|
+
console.error('Wrong IP!');
|
|
1082
|
+
validRequest = false;
|
|
1083
|
+
}
|
|
1084
|
+
if (!validRequest) {
|
|
1085
|
+
return {
|
|
1086
|
+
success: false,
|
|
1087
|
+
errorCode: 'invalid_request',
|
|
1088
|
+
errorMessage: INVALID_REQUEST_ERROR_MESSAGE,
|
|
1089
|
+
};
|
|
1090
|
+
}
|
|
1091
|
+
const { authenticator, user } = yield this._store.findUserAuthenticatorByCredentialId(request.response.id);
|
|
1092
|
+
if (!authenticator) {
|
|
1093
|
+
console.error('No Authenticator!');
|
|
1094
|
+
return {
|
|
1095
|
+
success: false,
|
|
1096
|
+
errorCode: 'invalid_request',
|
|
1097
|
+
errorMessage: INVALID_REQUEST_ERROR_MESSAGE,
|
|
1098
|
+
};
|
|
1099
|
+
}
|
|
1100
|
+
if (user.banTimeMs > 0) {
|
|
1101
|
+
return {
|
|
1102
|
+
success: false,
|
|
1103
|
+
errorCode: 'user_is_banned',
|
|
1104
|
+
errorMessage: 'The user has been banned.',
|
|
1105
|
+
banReason: user.banReason,
|
|
1106
|
+
};
|
|
1107
|
+
}
|
|
1108
|
+
try {
|
|
1109
|
+
const options = yield verifyAuthenticationResponse({
|
|
1110
|
+
response: request.response,
|
|
1111
|
+
expectedChallenge: loginRequest.challenge,
|
|
1112
|
+
expectedOrigin: relyingParty.origin,
|
|
1113
|
+
expectedRPID: relyingParty.id,
|
|
1114
|
+
authenticator: {
|
|
1115
|
+
credentialID: new Uint8Array(base64URLStringToBuffer(authenticator.credentialId)),
|
|
1116
|
+
counter: authenticator.counter,
|
|
1117
|
+
credentialPublicKey: authenticator.credentialPublicKey,
|
|
1118
|
+
transports: authenticator.transports,
|
|
1119
|
+
},
|
|
1120
|
+
});
|
|
1121
|
+
if (!options.verified) {
|
|
1122
|
+
console.error('Not verified!');
|
|
1123
|
+
return {
|
|
1124
|
+
success: false,
|
|
1125
|
+
errorCode: 'invalid_request',
|
|
1126
|
+
errorMessage: INVALID_REQUEST_ERROR_MESSAGE,
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1129
|
+
yield this._store.saveUserAuthenticatorCounter(authenticator.id, options.authenticationInfo.newCounter);
|
|
1130
|
+
}
|
|
1131
|
+
catch (err) {
|
|
1132
|
+
console.error(`[AuthController] Error occurred while verifying WebAuthn login response`, err);
|
|
1133
|
+
return {
|
|
1134
|
+
success: false,
|
|
1135
|
+
errorCode: 'invalid_request',
|
|
1136
|
+
errorMessage: err.message,
|
|
1137
|
+
};
|
|
1138
|
+
}
|
|
1139
|
+
const sessionId = fromByteArray(randomBytes(SESSION_ID_BYTE_LENGTH));
|
|
1140
|
+
const sessionSecret = fromByteArray(randomBytes(SESSION_SECRET_BYTE_LENGTH));
|
|
1141
|
+
const connectionSecret = fromByteArray(randomBytes(SESSION_SECRET_BYTE_LENGTH));
|
|
1142
|
+
const now = Date.now();
|
|
1143
|
+
const session = {
|
|
1144
|
+
userId: user.id,
|
|
1145
|
+
sessionId: sessionId,
|
|
1146
|
+
requestId: null,
|
|
1147
|
+
oidRequestId: null,
|
|
1148
|
+
webauthnRequestId: loginRequest.requestId,
|
|
1149
|
+
// sessionSecret and sessionId are high-entropy (128 bits of random data)
|
|
1150
|
+
// so we should use a hash that is optimized for high-entropy inputs.
|
|
1151
|
+
secretHash: hashHighEntropyPasswordWithSalt(sessionSecret, sessionId),
|
|
1152
|
+
connectionSecret: connectionSecret,
|
|
1153
|
+
grantedTimeMs: now,
|
|
1154
|
+
revokeTimeMs: null,
|
|
1155
|
+
expireTimeMs: now + SESSION_LIFETIME_MS,
|
|
1156
|
+
previousSessionId: null,
|
|
1157
|
+
nextSessionId: null,
|
|
1158
|
+
ipAddress: request.ipAddress,
|
|
1159
|
+
};
|
|
1160
|
+
yield this._store.markWebAuthnLoginRequestComplete(loginRequest.requestId, user.id, Date.now());
|
|
1161
|
+
yield this._store.saveSession(session);
|
|
1162
|
+
return {
|
|
1163
|
+
success: true,
|
|
1164
|
+
userId: session.userId,
|
|
1165
|
+
sessionKey: formatV1SessionKey(user.id, sessionId, sessionSecret, session.expireTimeMs),
|
|
1166
|
+
connectionKey: formatV1ConnectionKey(user.id, sessionId, connectionSecret, session.expireTimeMs),
|
|
1167
|
+
expireTimeMs: session.expireTimeMs,
|
|
1168
|
+
};
|
|
1169
|
+
}
|
|
1170
|
+
catch (err) {
|
|
1171
|
+
console.error(`[AuthController] Error occurred while requesting WebAuthn login`, err);
|
|
1172
|
+
return {
|
|
1173
|
+
success: false,
|
|
1174
|
+
errorCode: 'server_error',
|
|
1175
|
+
errorMessage: 'A server error occurred.',
|
|
1176
|
+
};
|
|
1177
|
+
}
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1180
|
+
listUserAuthenticators(userId) {
|
|
1181
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1182
|
+
try {
|
|
1183
|
+
if (!userId) {
|
|
1184
|
+
return {
|
|
1185
|
+
success: false,
|
|
1186
|
+
errorCode: 'not_logged_in',
|
|
1187
|
+
errorMessage: 'You need to be logged in for the operation to work.',
|
|
1188
|
+
};
|
|
1189
|
+
}
|
|
1190
|
+
const authenticators = yield this._store.listUserAuthenticators(userId);
|
|
1191
|
+
return {
|
|
1192
|
+
success: true,
|
|
1193
|
+
authenticators: authenticators.map((a) => ({
|
|
1194
|
+
id: a.id,
|
|
1195
|
+
aaguid: a.aaguid,
|
|
1196
|
+
userId: a.userId,
|
|
1197
|
+
credentialId: a.credentialId,
|
|
1198
|
+
credentialDeviceType: a.credentialDeviceType,
|
|
1199
|
+
credentialBackedUp: a.credentialBackedUp,
|
|
1200
|
+
counter: a.counter,
|
|
1201
|
+
transports: a.transports,
|
|
1202
|
+
registeringUserAgent: a.registeringUserAgent,
|
|
1203
|
+
createdAtMs: a.createdAtMs,
|
|
1204
|
+
})),
|
|
1205
|
+
};
|
|
1206
|
+
}
|
|
1207
|
+
catch (err) {
|
|
1208
|
+
console.error(`[AuthController] Error occurred while listing user authenticators`, err);
|
|
1209
|
+
return {
|
|
1210
|
+
success: false,
|
|
1211
|
+
errorCode: 'server_error',
|
|
1212
|
+
errorMessage: 'A server error occurred.',
|
|
1213
|
+
};
|
|
1214
|
+
}
|
|
1215
|
+
});
|
|
1216
|
+
}
|
|
1217
|
+
deleteUserAuthenticator(userId, authenticatorId) {
|
|
1218
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1219
|
+
try {
|
|
1220
|
+
if (!userId) {
|
|
1221
|
+
return {
|
|
1222
|
+
success: false,
|
|
1223
|
+
errorCode: 'not_logged_in',
|
|
1224
|
+
errorMessage: 'You need to be logged in for the operation to work.',
|
|
1225
|
+
};
|
|
1226
|
+
}
|
|
1227
|
+
const numDeleted = yield this._store.deleteUserAuthenticator(userId, authenticatorId);
|
|
1228
|
+
if (numDeleted <= 0) {
|
|
1229
|
+
return {
|
|
1230
|
+
success: false,
|
|
1231
|
+
errorCode: 'not_found',
|
|
1232
|
+
errorMessage: 'The given authenticator was not found.',
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
return {
|
|
1236
|
+
success: true,
|
|
1237
|
+
};
|
|
1238
|
+
}
|
|
1239
|
+
catch (err) {
|
|
1240
|
+
console.error(`[AuthController] Error occurred while deleting a user authenticator`, err);
|
|
1241
|
+
return {
|
|
1242
|
+
success: false,
|
|
1243
|
+
errorCode: 'server_error',
|
|
1244
|
+
errorMessage: 'A server error occurred.',
|
|
1245
|
+
};
|
|
1246
|
+
}
|
|
1247
|
+
});
|
|
1248
|
+
}
|
|
838
1249
|
validateSessionKey(key) {
|
|
839
1250
|
return __awaiter(this, void 0, void 0, function* () {
|
|
840
1251
|
if (typeof key !== 'string' || key === '') {
|
|
@@ -1698,4 +2109,18 @@ export function getPrivacyFeaturesFromPermissions(featureIds, permissions) {
|
|
|
1698
2109
|
allowPublicInsts,
|
|
1699
2110
|
};
|
|
1700
2111
|
}
|
|
2112
|
+
export function findRelyingPartyForOrigin(relyingParties, originOrHost) {
|
|
2113
|
+
if (!originOrHost) {
|
|
2114
|
+
return relyingParties[0];
|
|
2115
|
+
}
|
|
2116
|
+
return relyingParties.find((rp) => {
|
|
2117
|
+
const matchesOrigin = rp.origin === originOrHost;
|
|
2118
|
+
if (matchesOrigin) {
|
|
2119
|
+
return true;
|
|
2120
|
+
}
|
|
2121
|
+
const originUrl = new URL(rp.origin);
|
|
2122
|
+
const host = originUrl.host;
|
|
2123
|
+
return originOrHost === host;
|
|
2124
|
+
});
|
|
2125
|
+
}
|
|
1701
2126
|
//# sourceMappingURL=AuthController.js.map
|