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

Support validity window for Flowauth 2factor #3204

Merged
merged 2 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added
- Previously run, or currently running queries can now be referenced as a subscriber subset via FlowAPI. [#1009](https://github.com/Flowminder/FlowKit/issues/1009)
- total_network_objects, location_introversion, and unique_subscriber_counts now also accept subscriber subsets.
- The validity window for FlowAuth 2factor codes can now be configured using the `TWO_FACTOR_VALID_WINDOW` env variable. [#3203](https://github.com/Flowminder/FlowKit/issues/3203)

### Changed
- `get_cached_query_objects_ordered_by_score` is now a generator. [#3116](https://github.com/Flowminder/FlowKit/issues/3116)
Expand Down
1 change: 1 addition & 0 deletions flowauth/backend/flowauth/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ def get_config():
DB_IS_SET_UP=Event(),
CACHE_BACKEND=get_cache_backend(),
FLOWAUTH_TWO_FACTOR_ISSUER=getenv("FLOWAUTH_TWO_FACTOR_ISSUER", "FlowAuth"),
TWO_FACTOR_VALID_WINDOW=int(getenv("TWO_FACTOR_VALID_WINDOW", 0)),
)
except KeyError as e:
raise UndefinedConfigOption(
Expand Down
4 changes: 3 additions & 1 deletion flowauth/backend/flowauth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,9 @@ def validate(self, code: str) -> bool:
current_app.logger.debug(
"Verifying 2factor code", code=code, secret_key=self.decrypted_secret_key
)
is_valid = pyotp.totp.TOTP(self.decrypted_secret_key).verify(code)
is_valid = pyotp.totp.TOTP(self.decrypted_secret_key).verify(
code, valid_window=current_app.config["TWO_FACTOR_VALID_WINDOW"]
)
if is_valid:
if (
current_app.config["CACHE_BACKEND"].get(
Expand Down