Skip to content

Commit

Permalink
Merge pull request #3 from perseidesjs/fix/fixes-timestep-generation
Browse files Browse the repository at this point in the history
feat: Add timeStep option and update project assets
  • Loading branch information
adevinwild authored Feb 24, 2025
2 parents 6a58b90 + bf9d218 commit cde0063
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
github: adevinwild
buy_me_a_coffee: adevinwild
Binary file added .github/dark_mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .github/light_mode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file removed .r/dark.png
Binary file not shown.
Binary file removed .r/light.png
Binary file not shown.
Binary file removed .r/logo.png
Binary file not shown.
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<p align="center">
<a href="https://github.com/perseidesjs">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="./.r/dark.png" width="128" height="128">
<source media="(prefers-color-scheme: light)" srcset="./.r/light.png" width="128" height="128">
<img alt="Perseides logo" src="./.r/light.png">
<source media="(prefers-color-scheme: dark)" srcset="./.github/dark_mode.png" width="128" height="128">
<source media="(prefers-color-scheme: light)" srcset="./.github/light_mode.png" width="128" height="128">
<img alt="Perseides logo" src="./.github/light_mode.png">
</picture>
</a>
</p>
Expand All @@ -26,14 +26,11 @@
</p>

<p align="center">
<img src="./.r/preview.gif" alt="Plugin Preview">
<img src="./.github/preview.gif" alt="Plugin Preview">
</p>

<blockquote>
<p>
Here's a quick preview of the plugin in action allowing you to authenticate your customers using OTP and without the need of a password.
</p>
</blockquote>
> [!WARNING]
> This package is only for Medusa 1.x, if you need an OTP provider for Medusa 2.x, please refer to the [@perseidesjs/auth-otp](https://github.com/perseidesjs/auth-otp) package.

<h2>
Expand Down Expand Up @@ -79,6 +76,7 @@ const plugins = [
options: {
ttl: 30, // In seconds, the time to live of the OTP before expiration
digits: 6, // The number of digits of the OTP (e.g. 123456)
timeStep: 30, // The time step in seconds for TOTP generation, this is used to generate a new OTP at a different time each time
},
},
]
Expand Down Expand Up @@ -110,6 +108,12 @@ const plugins = [
<td><code>6</code></td>
<td>The number of digits of the OTP (e.g. 123456)</td>
</tr>
<tr>
<td>timeStep</td>
<td><code>Number</code></td>
<td><code>30</code></td>
<td>The time step in seconds for TOTP generation</td>
</tr>
</tbody>
</table>

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@
"ts-jest": "^27.0.7",
"ts-loader": "^9.2.6",
"typescript": "^4.5.2"
}
},
"packageManager": "yarn@1.22.22"
}
3 changes: 2 additions & 1 deletion src/services/totp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class TOTPService extends TransactionBaseService {
private readonly defaultOptions: Required<PluginOptions> = {
ttl: 60, // 1 minute
digits: 6, // 6 digits
timeStep: 30, // 30 seconds time step for TOTP generation
}

constructor(container: InjectedDependencies, options: PluginOptions) {
Expand Down Expand Up @@ -58,7 +59,7 @@ class TOTPService extends TransactionBaseService {
}

async generate(key: string, secret?: string): Promise<string> {
const otp = this.generateTOTP(secret || this.generateSecret(), this.defaultOptions.ttl)
const otp = this.generateTOTP(secret || this.generateSecret(), this.defaultOptions.timeStep)
await this.redisClient_.set(`totp:${key}`, otp, 'EX', this.defaultOptions.ttl)
await this.eventBus_.emit(TOTPService.Events.GENERATED, { key, otp } as OTPGeneratedEventData)
return otp
Expand Down
Loading

0 comments on commit cde0063

Please # to comment.