Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement OTP Store and enable client to set OTP expiry #1598

Closed
wants to merge 14 commits into from

Conversation

sitaram-kalluri
Copy link
Member

- What I did

  • Enable the client to pass the OTP expiry duration, beyond which the OTP becomes invalid.

- How I did it

  • Update the verb syntax for "OTP" to include a "TTL" parameter, which represents the duration in seconds.

  • Introduce a new class called "OTPStore" to store OTPs along with their expiration durations.

  • Implement a periodic job configured to run at specified intervals, responsible for removing expired OTPs from the "OTPStore"

  • Configure the duration for this job using the "otp"-> "gcDuration" setting in the config.yaml file. By default, it runs every 1 hour.

  • Changes in OtpVerbHandler.dart

    • Replace the "ExpireCache" - a third party library which is used to manage OTPs, with an instance of the "OTPStore" class. Since "ExpiryCache" is no longer used, removed it from the pubspec.yaml
    • In the constructor of the "OtpVerbHandler" class, initialize both the "OTPStore" and the "gcDuration." These are used to manage OTPs and determine how often the job for removing expired OTPs should run.
    • Introduce a new parameter called "otpExpiryDuration," which represents the duration beyond which an OTP expires. If the client does not specify a value for "TTL," it defaults to 5 minutes.
    • Implement the "isOTPValid" method, which returns a boolean value indicating whether an OTP is valid or not.

- How to verify it
Following are the unit tests:

  • A test to verify otp:get with TTL set is active before TTL is met
  • A test to verify otp:get with TTL set expires after the TTL is met
  • A test to verify gc removes the expired keys from the otp store

Following are the functional tests:

  • A test to generate OTP and returns valid before OTP is not expired

  • A test to generate OTP and returns invalid when TTL is met

  • Because the OTPs cannot be reused, updated the functional tests in enroll_verb_test.dart to fetch otp for each request

- Description for the changelog

  • Enable clients to configure OTPs expiry duration

Copy link
Contributor

@gkc gkc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since OTP lifespans can extend to weeks rather than just minutes or seconds, the OTPs need to persist through server restarts.

sitaram-kalluri and others added 13 commits October 12, 2023 11:31
Bumps [ossf/scorecard-action](https://github.com/ossf/scorecard-action) from 2.2.0 to 2.3.0.
- [Release notes](https://github.com/ossf/scorecard-action/releases)
- [Changelog](https://github.com/ossf/scorecard-action/blob/main/RELEASE.md)
- [Commits](ossf/scorecard-action@08b4669...483ef80)

---
updated-dependencies:
- dependency-name: ossf/scorecard-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2.21.9 to 2.22.0.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@ddccb87...2cb752a)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2.22.0 to 2.22.1.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@2cb752a...fdcae64)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
@sitaram-kalluri
Copy link
Member Author

sitaram-kalluri commented Oct 12, 2023

Closing this PR. The changes are pushed as a part of the following PR: #1609

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow client to configure the expiry on the OTP
2 participants