Skip to content

Commit

Permalink
fix: totp recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Nov 10, 2023
1 parent 9d379f6 commit 9fd1020
Show file tree
Hide file tree
Showing 33 changed files with 1,605 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/build/recipe/totp/api/createDevice.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @ts-nocheck
import { APIInterface, APIOptions } from "..";
export default function createDeviceAPI(
apiImplementation: APIInterface,
options: APIOptions,
userContext: any
): Promise<boolean>;
58 changes: 58 additions & 0 deletions lib/build/recipe/totp/api/createDevice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
"use strict";
/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../../../utils");
const session_1 = __importDefault(require("../../session"));
async function createDeviceAPI(apiImplementation, options, userContext) {
if (apiImplementation.createDevicePOST === undefined) {
return false;
}
const session = await session_1.default.getSession(
options.req,
options.res,
{ overrideGlobalClaimValidators: () => [], sessionRequired: true },
userContext
);
const bodyParams = await options.req.getJSONBody();
const deviceName = bodyParams.deviceName;
const period = bodyParams.period;
const skew = bodyParams.skew;
if (deviceName !== undefined && typeof deviceName !== "string") {
throw new Error("deviceName must be a string");
}
if (period !== undefined && typeof period !== "number") {
throw new Error("period must be a number");
}
if (skew !== undefined && typeof skew !== "number") {
throw new Error("skew must be a number");
}
let response = await apiImplementation.createDevicePOST({
deviceName,
period,
skew,
options,
session,
userContext,
});
utils_1.send200Response(options.res, response);
return true;
}
exports.default = createDeviceAPI;
3 changes: 3 additions & 0 deletions lib/build/recipe/totp/api/implementation.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @ts-nocheck
import { APIInterface } from "../";
export default function getAPIInterface(): APIInterface;
38 changes: 38 additions & 0 deletions lib/build/recipe/totp/api/implementation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function getAPIInterface() {
return {
createDevicePOST: async function ({ deviceName, period, skew, options, session, userContext }) {
const userId = session.getUserId();
return await options.recipeImplementation.createDevice({
userId,
deviceName: deviceName,
period: period,
skew: skew,
userContext: userContext,
});
},
verifyDevicePOST: async function ({ deviceName, totp, options, session, userContext }) {
const userId = session.getUserId();
const tenantId = session.getTenantId();
return await options.recipeImplementation.verifyDevice({
tenantId,
userId,
deviceName,
totp,
userContext,
});
},
verifyTOTPPOST: async function ({ totp, options, session, userContext }) {
const userId = session.getUserId();
const tenantId = session.getTenantId();
return await options.recipeImplementation.verifyTOTP({
tenantId,
userId,
totp,
userContext,
});
},
};
}
exports.default = getAPIInterface;
7 changes: 7 additions & 0 deletions lib/build/recipe/totp/api/verifyDevice.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @ts-nocheck
import { APIInterface, APIOptions } from "..";
export default function verifyDeviceAPI(
apiImplementation: APIInterface,
options: APIOptions,
userContext: any
): Promise<boolean>;
53 changes: 53 additions & 0 deletions lib/build/recipe/totp/api/verifyDevice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"use strict";
/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../../../utils");
const session_1 = __importDefault(require("../../session"));
async function verifyDeviceAPI(apiImplementation, options, userContext) {
if (apiImplementation.createDevicePOST === undefined) {
return false;
}
const session = await session_1.default.getSession(
options.req,
options.res,
{ overrideGlobalClaimValidators: () => [], sessionRequired: true },
userContext
);
const bodyParams = await options.req.getJSONBody();
const deviceName = bodyParams.deviceName;
const totp = bodyParams.totp;
if (deviceName === undefined || typeof deviceName !== "string") {
throw new Error("deviceName is required and must be a string");
}
if (totp === undefined || typeof totp !== "string") {
throw new Error("totp is required and must be a string");
}
let response = await apiImplementation.verifyDevicePOST({
deviceName,
totp,
options,
session,
userContext,
});
utils_1.send200Response(options.res, response);
return true;
}
exports.default = verifyDeviceAPI;
7 changes: 7 additions & 0 deletions lib/build/recipe/totp/api/verifyTOTP.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// @ts-nocheck
import { APIInterface, APIOptions } from "..";
export default function verifyTOTPAPI(
apiImplementation: APIInterface,
options: APIOptions,
userContext: any
): Promise<boolean>;
48 changes: 48 additions & 0 deletions lib/build/recipe/totp/api/verifyTOTP.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"use strict";
/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
var __importDefault =
(this && this.__importDefault) ||
function (mod) {
return mod && mod.__esModule ? mod : { default: mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../../../utils");
const session_1 = __importDefault(require("../../session"));
async function verifyTOTPAPI(apiImplementation, options, userContext) {
if (apiImplementation.createDevicePOST === undefined) {
return false;
}
const session = await session_1.default.getSession(
options.req,
options.res,
{ overrideGlobalClaimValidators: () => [], sessionRequired: true },
userContext
);
const bodyParams = await options.req.getJSONBody();
const totp = bodyParams.totp;
if (totp === undefined || typeof totp !== "string") {
throw new Error("totp is required and must be a string");
}
let response = await apiImplementation.verifyTOTPPOST({
totp,
options,
session,
userContext,
});
utils_1.send200Response(options.res, response);
return true;
}
exports.default = verifyTOTPAPI;
4 changes: 4 additions & 0 deletions lib/build/recipe/totp/constants.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// @ts-nocheck
export declare const CREATE_TOTP_DEVICE = "/totp/device";
export declare const VERIFY_TOTP_DEVICE = "/totp/device/verify";
export declare const VERIFY_TOTP = "/totp/verify";
20 changes: 20 additions & 0 deletions lib/build/recipe/totp/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use strict";
/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.VERIFY_TOTP = exports.VERIFY_TOTP_DEVICE = exports.CREATE_TOTP_DEVICE = void 0;
exports.CREATE_TOTP_DEVICE = "/totp/device";
exports.VERIFY_TOTP_DEVICE = "/totp/device/verify";
exports.VERIFY_TOTP = "/totp/verify";
1 change: 1 addition & 0 deletions lib/build/recipe/totp/error.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// @ts-nocheck
16 changes: 16 additions & 0 deletions lib/build/recipe/totp/error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use strict";
/* Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved.
*
* This software is licensed under the Apache License, Version 2.0 (the
* "License") as published by the Apache Software Foundation.
*
* You may not use this file except in compliance with the License. You may
* obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
// import STError from "../../error";
81 changes: 81 additions & 0 deletions lib/build/recipe/totp/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// @ts-nocheck
import Recipe from "./recipe";
import { RecipeInterface, APIOptions, APIInterface } from "./types";
export default class Wrapper {
static init: typeof Recipe.init;
static createDevice(
userId: string,
deviceName?: string,
skew?: number,
period?: number,
userContext?: any
): Promise<
| {
status: "OK";
deviceName: string;
secret: string;
}
| {
status: "DEVICE_ALREADY_EXISTS_ERROR";
}
>;
static updateDevice(
userId: string,
existingDeviceName: string,
newDeviceName: string,
userContext?: any
): Promise<{
status: "OK" | "DEVICE_ALREADY_EXISTS_ERROR" | "UNKNOWN_DEVICE_ERROR";
}>;
static listDevices(
userId: string,
userContext?: any
): Promise<{
status: "OK";
devices: {
name: string;
period: number;
skew: number;
verified: boolean;
}[];
}>;
static removeDevice(
userId: string,
deviceName: string,
userContext?: any
): Promise<{
status: "OK";
didDeviceExist: boolean;
}>;
static verifyDevice(
tenantId: string,
userId: string,
deviceName: string,
totp: string,
userContext?: any
): Promise<
| {
status: "OK";
wasAlreadyVerified: boolean;
}
| {
status: "UNKNOWN_DEVICE_ERROR" | "INVALID_TOTP_ERROR" | "LIMIT_REACHED_ERROR";
}
>;
static verifyTOTP(
tenantId: string,
userId: string,
totp: string,
userContext?: any
): Promise<
| {
status: "OK" | "UNKNOWN_USER_ID_ERROR" | "INVALID_TOTP_ERROR";
}
| {
status: "LIMIT_REACHED_ERROR";
retryAfterMs: number;
}
>;
}
export declare let init: typeof Recipe.init;
export type { RecipeInterface, APIOptions, APIInterface };
Loading

0 comments on commit 9fd1020

Please sign in to comment.