Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kinvey-js-sdk

Package Overview
Dependencies
Maintainers
5
Versions
108
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kinvey-js-sdk - npm Package Compare versions

Comparing version 6.0.0-next.1 to 6.0.0-next.2

lib/user/createMFAAuthenticator.d.ts

3

lib/http/headers.d.ts

@@ -30,3 +30,4 @@ export declare class HttpHeaders {

SessionOrMaster = "SessionOrMaster",
MFASessionToken = "MFASessionToken"
MFASessionToken = "MFASessionToken",
SessionOrMFASessionTokenOrMaster = "SessionOrMFASessionTokenOrMaster"
}

@@ -33,0 +34,0 @@ export declare function getAppVersion(): string;

@@ -157,2 +157,3 @@ "use strict";

KinveyHttpAuth["MFASessionToken"] = "MFASessionToken";
KinveyHttpAuth["SessionOrMFASessionTokenOrMaster"] = "SessionOrMFASessionTokenOrMaster";
})(KinveyHttpAuth = exports.KinveyHttpAuth || (exports.KinveyHttpAuth = {}));

@@ -197,3 +198,3 @@ var globalHeaders = new HttpHeaders();

return __awaiter(this, void 0, void 0, function () {
var appKey, appSecret, masterSecret, session, mfaSessionToken, value, credentials, credentials, error_1, error_2, error_3, error_4;
var appKey, appSecret, masterSecret, session, mfaSessionToken, value, credentials, credentials, error_1, error_2, error_3, error_4, error_5, error_6;
return __generator(this, function (_a) {

@@ -218,3 +219,3 @@ switch (_a.label) {

value = "Basic " + credentials;
return [3 /*break*/, 27];
return [3 /*break*/, 37];
case 3:

@@ -227,3 +228,3 @@ if (!(auth === KinveyHttpAuth.Master)) return [3 /*break*/, 4];

value = "Basic " + credentials;
return [3 /*break*/, 27];
return [3 /*break*/, 37];
case 4:

@@ -235,3 +236,3 @@ if (!(auth === KinveyHttpAuth.Session)) return [3 /*break*/, 5];

value = "Kinvey " + session._kmd.authtoken;
return [3 /*break*/, 27];
return [3 /*break*/, 37];
case 5:

@@ -243,3 +244,3 @@ if (!(auth === KinveyHttpAuth.MFASessionToken)) return [3 /*break*/, 6];

value = "KinveyMFA " + mfaSessionToken;
return [3 /*break*/, 27];
return [3 /*break*/, 37];
case 6:

@@ -264,3 +265,3 @@ if (!(auth === KinveyHttpAuth.All)) return [3 /*break*/, 16];

case 14: return [3 /*break*/, 15];
case 15: return [3 /*break*/, 27];
case 15: return [3 /*break*/, 37];
case 16:

@@ -277,5 +278,5 @@ if (!(auth === KinveyHttpAuth.SessionOrApp)) return [3 /*break*/, 22];

case 20: return [2 /*return*/, _a.sent()];
case 21: return [3 /*break*/, 27];
case 21: return [3 /*break*/, 37];
case 22:
if (!(auth === KinveyHttpAuth.SessionOrMaster)) return [3 /*break*/, 27];
if (!(auth === KinveyHttpAuth.SessionOrMaster)) return [3 /*break*/, 28];
_a.label = 23;

@@ -290,3 +291,23 @@ case 23:

case 26: return [2 /*return*/, _a.sent()];
case 27:
case 27: return [3 /*break*/, 37];
case 28:
if (!(auth === KinveyHttpAuth.SessionOrMFASessionTokenOrMaster)) return [3 /*break*/, 37];
_a.label = 29;
case 29:
_a.trys.push([29, 31, , 37]);
return [4 /*yield*/, this.setAuthorization(KinveyHttpAuth.Session)];
case 30: return [2 /*return*/, _a.sent()];
case 31:
error_5 = _a.sent();
_a.label = 32;
case 32:
_a.trys.push([32, 34, , 36]);
return [4 /*yield*/, this.setAuthorization(KinveyHttpAuth.MFASessionToken)];
case 33: return [2 /*return*/, _a.sent()];
case 34:
error_6 = _a.sent();
return [4 /*yield*/, this.setAuthorization(KinveyHttpAuth.Master)];
case 35: return [2 /*return*/, _a.sent()];
case 36: return [3 /*break*/, 37];
case 37:
this.set('Authorization', value);

@@ -293,0 +314,0 @@ return [2 /*return*/];

@@ -10,2 +10,6 @@ import { Entity } from '../storage';

}
export interface MFASessionObject {
userId: string;
mfaSessionToken: string;
}
export declare function getKey(): string;

@@ -15,5 +19,6 @@ export declare function getSession(): Promise<SessionObject>;

export declare function removeSession(): Promise<boolean>;
export declare function getMFASession(): Promise<MFASessionObject>;
export declare function getMFASessionToken(): Promise<string>;
export declare function setMFASessionToken(token: string): Promise<boolean>;
export declare function removeMFASessionToken(): Promise<boolean>;
export declare function setMFASession(mfaSession: MFASessionObject): Promise<boolean>;
export declare function removeMFASession(): Promise<boolean>;
export declare function getDeviceToken(username: string): Promise<string>;

@@ -20,0 +25,0 @@ export declare function hasDeviceToken(username: string): Promise<boolean>;

@@ -47,14 +47,14 @@ "use strict";

exports.getKey = getKey;
function getSession() {
function _getObjectFromStore(key) {
return __awaiter(this, void 0, void 0, function () {
var session;
var obj;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, getStore().get(getKey())];
case 0: return [4 /*yield*/, getStore().get(key)];
case 1:
session = _a.sent();
if (session) {
return [2 /*return*/, JSON.parse(session)];
obj = _a.sent();
if (!obj) {
return [2 /*return*/, null];
}
return [2 /*return*/, null];
return [2 /*return*/, JSON.parse(obj)];
}

@@ -64,7 +64,21 @@ });

}
function getSession() {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, _getObjectFromStore(getKey())];
});
});
}
exports.getSession = getSession;
function _setObjectInStore(key, obj) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, getStore().set(key, JSON.stringify(obj))];
});
});
}
function setSession(session) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, getStore().set(getKey(), JSON.stringify(session))];
return [2 /*return*/, _setObjectInStore(getKey(), session)];
});

@@ -83,8 +97,25 @@ });

function getMFAKey() {
return kinvey_1.getAppKey() + ".mfa_session_token";
return kinvey_1.getAppKey() + ".mfa_user";
}
function getMFASession() {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, _getObjectFromStore(getMFAKey())];
});
});
}
exports.getMFASession = getMFASession;
function getMFASessionToken() {
return __awaiter(this, void 0, void 0, function () {
var mfaUser;
return __generator(this, function (_a) {
return [2 /*return*/, getStore().get(getMFAKey())];
switch (_a.label) {
case 0: return [4 /*yield*/, getMFASession()];
case 1:
mfaUser = _a.sent();
if (!mfaUser) {
return [2 /*return*/, null];
}
return [2 /*return*/, mfaUser.mfaSessionToken];
}
});

@@ -94,11 +125,11 @@ });

exports.getMFASessionToken = getMFASessionToken;
function setMFASessionToken(token) {
function setMFASession(mfaSession) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, getStore().set(getMFAKey(), token)];
return [2 /*return*/, _setObjectInStore(getMFAKey(), mfaSession)];
});
});
}
exports.setMFASessionToken = setMFASessionToken;
function removeMFASessionToken() {
exports.setMFASession = setMFASession;
function removeMFASession() {
return __awaiter(this, void 0, void 0, function () {

@@ -110,3 +141,3 @@ return __generator(this, function (_a) {

}
exports.removeMFASessionToken = removeMFASessionToken;
exports.removeMFASession = removeMFASession;
function getDeviceTokenKey(username) {

@@ -113,0 +144,0 @@ return kinvey_1.getAppKey() + "." + username + ".device_token";

@@ -14,2 +14,4 @@ import { Acl } from './acl';

import { User, AuthorizationGrant } from './user';
import { LoginOptions } from './user/login';
import { MFAContext, MFACompleteResult } from './user/loginWithMFA';
import { getAppVersion, setAppVersion } from './http';

@@ -24,2 +26,2 @@ declare const CustomEndpoint: {

};
export { init, initialize, getAppVersion, setAppVersion, logger, ping, Acl, Aggregation, CustomEndpoint, DataStore, DataStoreType, Errors, Files, Kmd, Kmd as Metadata, Query, User, AuthorizationGrant, MFA };
export { init, initialize, getAppVersion, setAppVersion, logger, ping, Acl, Aggregation, CustomEndpoint, DataStore, DataStoreType, Errors, Files, Kmd, Kmd as Metadata, Query, User, AuthorizationGrant, LoginOptions, MFAContext, MFACompleteResult, MFA };

@@ -1,2 +0,2 @@

import { CreateMFAAuthenticatorResult, MFAAuthenticator, NewMFAAuthenticator, VerifyContext } from '../user/user';
import { CreateMFAAuthenticatorResult, MFAAuthenticator, NewMFAAuthenticator, VerifyContext } from '../user/createMFAAuthenticator';
declare const Authenticators: {

@@ -3,0 +3,0 @@ create: (newAuthenticator: NewMFAAuthenticator, verify: (authenticator: MFAAuthenticator, context: VerifyContext) => Promise<string>) => Promise<CreateMFAAuthenticatorResult>;

@@ -39,3 +39,5 @@ "use strict";

var getActiveUser_1 = require("../user/getActiveUser");
var createMFAAuthenticator_1 = require("../user/createMFAAuthenticator");
var kinvey_1 = require("../errors/kinvey");
var http_1 = require("../http");
function callOnActiveUser(funcName) {

@@ -63,3 +65,22 @@ var args = [];

create: function create(newAuthenticator, verify) {
return callOnActiveUser('createAuthenticator', newAuthenticator, verify);
return __awaiter(this, void 0, void 0, function () {
var activeUser, mfaUser;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, getActiveUser_1.getActiveUser()];
case 1:
activeUser = _a.sent();
if (activeUser) {
return [2 /*return*/, createMFAAuthenticator_1.createMFAAuthenticator(activeUser.data._id, newAuthenticator, verify)];
}
return [4 /*yield*/, http_1.getMFASession()];
case 2:
mfaUser = _a.sent();
if (!mfaUser) {
throw new kinvey_1.KinveyError('An active user, nor an MFA user exists. Please login one first.');
}
return [2 /*return*/, createMFAAuthenticator_1.createMFAAuthenticator(mfaUser.userId, newAuthenticator, verify)];
}
});
});
},

@@ -85,6 +106,3 @@ list: function list() {

return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Authenticators.list()];
case 1: return [2 /*return*/, (_a.sent()).length > 0];
}
return [2 /*return*/, callOnActiveUser('isMFAEnabled')];
});

@@ -96,13 +114,4 @@ });

return __awaiter(this, void 0, void 0, function () {
var authenticators, activeUser;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, Authenticators.list()];
case 1:
authenticators = _a.sent();
return [4 /*yield*/, getActiveUser_1.getActiveUser()];
case 2:
activeUser = _a.sent();
return [2 /*return*/, Promise.all(authenticators.map(function (a) { return activeUser.removeAuthenticator(a.id); }))];
}
return [2 /*return*/, callOnActiveUser('disableMFA')];
});

@@ -109,0 +118,0 @@ });

@@ -172,3 +172,3 @@ "use strict";

_b.label = 9;
case 9: return [4 /*yield*/, http_1.setMFASessionToken(loginResult.mfaSessionToken)];
case 9: return [4 /*yield*/, http_1.setMFASession({ mfaSessionToken: loginResult.mfaSessionToken, userId: loginResult.userId })];
case 10:

@@ -202,3 +202,3 @@ _b.sent();

_b.label = 15;
case 15: return [4 /*yield*/, http_1.removeMFASessionToken()];
case 15: return [4 /*yield*/, http_1.removeMFASession()];
case 16:

@@ -226,3 +226,3 @@ _b.sent();

if (!(err_2.message !== errMsgNoAuthenticators)) return [3 /*break*/, 3];
return [4 /*yield*/, http_1.removeMFASessionToken()];
return [4 /*yield*/, http_1.removeMFASession()];
case 2:

@@ -229,0 +229,0 @@ _a.sent();

import { Acl } from '../acl';
import { Kmd } from '../kmd';
import { Entity } from '../storage';
import { CreateMFAAuthenticatorResult, MFAAuthenticator, NewMFAAuthenticator, VerifyContext } from './createMFAAuthenticator';
export interface UserData extends Entity {

@@ -9,24 +10,2 @@ _socialIdentity?: object;

}
export interface MFAAuthenticator {
id: string;
name: string;
type: string;
config?: object;
}
export interface CreateMFAAuthenticatorResult {
authenticator: MFAAuthenticator;
recoveryCodes?: string[];
}
export declare enum MFAAuthenticatorType {
TOTP = "totp"
}
export interface NewMFAAuthenticator {
name: string;
type?: MFAAuthenticatorType;
}
export interface VerifyContext {
retries: number;
authenticator: MFAAuthenticator;
error?: any;
}
export declare class User {

@@ -61,8 +40,9 @@ data: UserData;

}): Promise<boolean>;
_verifyAuthenticatorRetryable(verify: (authenticator: MFAAuthenticator, context: VerifyContext) => Promise<string>, context: VerifyContext): Promise<any>;
createAuthenticator(newAuthenticator: NewMFAAuthenticator, verify: (authenticator: MFAAuthenticator, context: VerifyContext) => Promise<string>): Promise<CreateMFAAuthenticatorResult>;
listAuthenticators(): Promise<MFAAuthenticator[]>;
removeAuthenticator(id: string): Promise<void>;
removeAuthenticator(id: string): Promise<any>;
listRecoveryCodes(): Promise<string[]>;
regenerateRecoveryCodes(): Promise<string[]>;
isMFAEnabled(): Promise<boolean>;
disableMFA(): Promise<any>;
_cleanup(kinveyRequest: any, operationName: any, cleanEntireSessionStore?: boolean): Promise<this>;

@@ -69,0 +49,0 @@ logout(options?: {

@@ -42,4 +42,2 @@ "use strict";

var isArray_1 = __importDefault(require("lodash/isArray"));
var pick_1 = __importDefault(require("lodash/pick"));
var defaults_1 = __importDefault(require("lodash/defaults"));
var acl_1 = require("../acl");

@@ -55,6 +53,3 @@ var kmd_1 = require("../kmd");

var signup_1 = require("./signup");
var MFAAuthenticatorType;
(function (MFAAuthenticatorType) {
MFAAuthenticatorType["TOTP"] = "totp";
})(MFAAuthenticatorType = exports.MFAAuthenticatorType || (exports.MFAAuthenticatorType = {}));
var createMFAAuthenticator_1 = require("./createMFAAuthenticator");
var User = /** @class */ (function () {

@@ -316,62 +311,6 @@ function User(data) {

};
User.prototype._verifyAuthenticatorRetryable = function (verify, context) {
return __awaiter(this, void 0, void 0, function () {
var code, request, data, err_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, verify(context.authenticator, context)];
case 1:
code = _a.sent();
if (code == null) {
throw new kinvey_1.KinveyError('MFA code is missing.');
}
_a.label = 2;
case 2:
_a.trys.push([2, 4, , 5]);
request = new http_1.KinveyHttpRequest({
method: http_1.HttpRequestMethod.POST,
auth: http_1.KinveyHttpAuth.SessionOrMaster,
url: http_1.formatKinveyBaasUrl(http_1.KinveyBaasNamespace.User, "/" + this._id + "/authenticators/" + context.authenticator.id + "/verify"),
body: { code: code },
});
return [4 /*yield*/, request.execute()];
case 3:
data = (_a.sent()).data;
return [2 /*return*/, data];
case 4:
err_1 = _a.sent();
context.retries += 1; // eslint-disable-line no-param-reassign
context.error = err_1; // eslint-disable-line no-param-reassign
return [2 /*return*/, this._verifyAuthenticatorRetryable(verify, context)];
case 5: return [2 /*return*/];
}
});
});
};
User.prototype.createAuthenticator = function (newAuthenticator, verify) {
return __awaiter(this, void 0, void 0, function () {
var request, authenticator, verifyResult;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (!verify) {
throw new kinvey_1.KinveyError('Function to verify authenticator is missing.');
}
request = new http_1.KinveyHttpRequest({
method: http_1.HttpRequestMethod.POST,
auth: http_1.KinveyHttpAuth.SessionOrMaster,
url: http_1.formatKinveyBaasUrl(http_1.KinveyBaasNamespace.User, "/" + this._id + "/authenticators"),
body: defaults_1.default(newAuthenticator, { type: MFAAuthenticatorType.TOTP }),
});
return [4 /*yield*/, request.execute()];
case 1:
authenticator = (_a.sent()).data;
return [4 /*yield*/, this._verifyAuthenticatorRetryable(verify, { authenticator: authenticator, retries: 0 })];
case 2:
verifyResult = _a.sent();
return [2 /*return*/, {
authenticator: pick_1.default(authenticator, ['id', 'name', 'type', 'config']),
recoveryCodes: verifyResult.recoveryCodes,
}];
}
return [2 /*return*/, createMFAAuthenticator_1.createMFAAuthenticator(this._id, newAuthenticator, verify)];
});

@@ -415,3 +354,3 @@ });

_a.sent();
return [2 /*return*/];
return [2 /*return*/, null];
}

@@ -459,2 +398,29 @@ });

};
User.prototype.isMFAEnabled = function () {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.listAuthenticators()];
case 1: return [2 /*return*/, (_a.sent()).length > 0];
}
});
});
};
User.prototype.disableMFA = function () {
return __awaiter(this, void 0, void 0, function () {
var authenticators;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.listAuthenticators()];
case 1:
authenticators = _a.sent();
return [4 /*yield*/, Promise.all(authenticators.map(function (a) { return _this.removeAuthenticator(a.id); }))];
case 2:
_a.sent();
return [2 /*return*/, true];
}
});
});
};
User.prototype._cleanup = function (kinveyRequest, operationName, cleanEntireSessionStore) {

@@ -488,3 +454,3 @@ if (cleanEntireSessionStore === void 0) { cleanEntireSessionStore = false; }

if (!cleanEntireSessionStore) return [3 /*break*/, 9];
return [4 /*yield*/, http_1.removeMFASessionToken()];
return [4 /*yield*/, http_1.removeMFASession()];
case 7:

@@ -491,0 +457,0 @@ _a.sent();

{
"name": "kinvey-js-sdk",
"description": "Kinvey JavaScript SDK for JavaScript applications.",
"version": "6.0.0-next.1",
"version": "6.0.0-next.2",
"license": "Apache-2.0",

@@ -21,3 +21,3 @@ "keywords": [

"js-base64": "2.5.1",
"lodash": "4.17.15",
"lodash": "4.17.21",
"loglevel": "1.6.3",

@@ -24,0 +24,0 @@ "loglevel-plugin-prefix": "0.8.4",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc