Skip to content

Commit 040ad2f

Browse files
feat: add support for Time based OTP
1 parent 9600695 commit 040ad2f

File tree

4 files changed

+89
-0
lines changed

4 files changed

+89
-0
lines changed

package-lock.json

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"http-proxy": "^1.18.1",
6161
"kleur": "^4.1.5",
6262
"micromatch": "^4.0.7",
63+
"otpauth": "^9.3.2",
6364
"pirates": "^4.0.5",
6465
"playwright": "=1.45.1",
6566
"playwright-chromium": "=1.45.1",

src/core/totp.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* MIT License
3+
*
4+
* Copyright (c) 2020-present, Elastic NV
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*
24+
*/
25+
26+
import { TOTP } from "otpauth";
27+
28+
type TOTPOptions = {
29+
/**
30+
* Service provider name.
31+
*/
32+
issuer?: string
33+
/**
34+
* Account Identifier.
35+
*/
36+
label?: string
37+
/**
38+
* Include issuer prefix in label.
39+
*/
40+
issuerInLabel?: boolean
41+
/**
42+
* The encoded secret key used to generate the TOTP.
43+
*/
44+
secret?: string
45+
/**
46+
* The algorithm used to generate the TOTP.
47+
* @default 'SHA1'
48+
*/
49+
algorithm?: string
50+
/**
51+
* Length of the generated token.
52+
* @default 6
53+
*/
54+
digits?: number
55+
/**
56+
* Interval in seconds for which the token is valid.
57+
* @default 30
58+
*/
59+
period?: number
60+
};
61+
62+
export function createTOTP(options: TOTPOptions) {
63+
return new TOTP({ ...options });
64+
}

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export {
4343
after,
4444
} from './core';
4545
export { expect } from './core/expect';
46+
export { createTOTP } from './core/totp';
4647

4748
/**
4849
* Export all the driver related types to be consumed

0 commit comments

Comments
 (0)