Socket
Socket
Sign inDemoInstall

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.2 to 6.0.0-next.3

3

lib/http/headers.d.ts

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

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

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

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

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

@@ -198,3 +197,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, error_5, error_6;
var appKey, appSecret, masterSecret, session, mfaSessionToken, value, credentials, credentials, error_1, error_2, error_3, error_4;
return __generator(this, function (_a) {

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

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

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

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

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

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

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

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

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

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

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

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

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

case 26: return [2 /*return*/, _a.sent()];
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:
case 27:
this.set('Authorization', value);

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

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

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

@@ -19,6 +15,5 @@ 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 setMFASession(mfaSession: MFASessionObject): Promise<boolean>;
export declare function removeMFASession(): Promise<boolean>;
export declare function setMFASessionToken(token: string): Promise<boolean>;
export declare function removeMFASessionToken(): Promise<boolean>;
export declare function getDeviceToken(username: string): Promise<string>;

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

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

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

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

}
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*/, _setObjectInStore(getKey(), session)];
return [2 /*return*/, getStore().set(getKey(), JSON.stringify(session))];
});

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

function getMFAKey() {
return kinvey_1.getAppKey() + ".mfa_user";
return kinvey_1.getAppKey() + ".mfa_session_token";
}
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) {
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];
}
return [2 /*return*/, getStore().get(getMFAKey())];
});

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

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

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

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

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

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

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

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

@@ -39,5 +39,3 @@ "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) {

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

create: function create(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)];
}
});
});
return callOnActiveUser('createAuthenticator', newAuthenticator, verify);
},

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

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

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

return __awaiter(this, void 0, void 0, function () {
var authenticators, activeUser;
return __generator(this, function (_a) {
return [2 /*return*/, callOnActiveUser('disableMFA')];
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 [4 /*yield*/, Promise.all(authenticators.map(function (a) { return activeUser.removeAuthenticator(a.id); }))];
case 3:
_a.sent();
return [2 /*return*/, true];
}
});

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

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

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

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

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

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

if (!(err_2.message !== errMsgNoAuthenticators)) return [3 /*break*/, 3];
return [4 /*yield*/, http_1.removeMFASession()];
return [4 /*yield*/, http_1.removeMFASessionToken()];
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 {

@@ -10,2 +9,24 @@ _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 {

@@ -40,2 +61,3 @@ data: UserData;

}): Promise<boolean>;
_verifyAuthenticatorRetryable(verify: (authenticator: MFAAuthenticator, context: VerifyContext) => Promise<string>, context: VerifyContext, maxRetriesCount: number): Promise<any>;
createAuthenticator(newAuthenticator: NewMFAAuthenticator, verify: (authenticator: MFAAuthenticator, context: VerifyContext) => Promise<string>): Promise<CreateMFAAuthenticatorResult>;

@@ -46,4 +68,2 @@ listAuthenticators(): Promise<MFAAuthenticator[]>;

regenerateRecoveryCodes(): Promise<string[]>;
isMFAEnabled(): Promise<boolean>;
disableMFA(): Promise<any>;
_cleanup(kinveyRequest: any, operationName: any, cleanEntireSessionStore?: boolean): Promise<this>;

@@ -50,0 +70,0 @@ logout(options?: {

@@ -42,2 +42,4 @@ "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");

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

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

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

};
User.prototype._verifyAuthenticatorRetryable = function (verify, context, maxRetriesCount) {
return __awaiter(this, void 0, void 0, function () {
var code, request, data, err_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
if (context.retries >= maxRetriesCount) {
throw new kinvey_1.KinveyError('Max retries count for authenticator verification exceeded.');
}
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, maxRetriesCount)];
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) {
return [2 /*return*/, createMFAAuthenticator_1.createMFAAuthenticator(this._id, newAuthenticator, verify)];
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 }, 10)];
case 2:
verifyResult = _a.sent();
return [2 /*return*/, {
authenticator: pick_1.default(authenticator, ['id', 'name', 'type', 'config']),
recoveryCodes: verifyResult.recoveryCodes || null,
}];
}
});

@@ -397,29 +462,2 @@ });

};
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) {

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

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

@@ -456,0 +494,0 @@ _a.sent();

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

@@ -6,0 +6,0 @@ "keywords": [

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