-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
1,605 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// @ts-nocheck | ||
import { APIInterface } from "../"; | ||
export default function getAPIInterface(): APIInterface; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// @ts-nocheck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
Oops, something went wrong.