-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add TOTP/MFA support for local controller auth #10
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,6 +70,7 @@ def __init__( | |
| self.password = password or settings.controller_password | ||
| self.site = site or settings.controller_site | ||
| self.verify_ssl = verify_ssl if verify_ssl is not None else settings.controller_verify_ssl | ||
| self.totp = settings.controller_totp | ||
|
|
||
| # Timeout priority: explicit param > --quick flag > settings | ||
| if timeout is not None: | ||
|
|
@@ -200,20 +201,27 @@ async def login(self) -> bool: | |
| try: | ||
| # Try UDM-style auth first | ||
| if self._is_udm: | ||
| login_data = { | ||
| "username": self.username, | ||
| "password": self.password, | ||
| "remember": True, | ||
| } | ||
| if self.totp: | ||
| login_data["token"] = self.totp | ||
| response = await client.post( | ||
| f"{self.controller_url}/api/auth/login", | ||
| json={ | ||
| "username": self.username, | ||
| "password": self.password, | ||
| "remember": True, | ||
| }, | ||
| json=login_data, | ||
| ) | ||
|
|
||
| if response.status_code == 200: | ||
| self._cookies = dict(response.cookies) | ||
| self._csrf_token = response.headers.get("X-CSRF-Token") | ||
| self._save_session() | ||
| return True | ||
| elif response.status_code == 499: | ||
| raise LocalAuthenticationError( | ||
| "MFA token required. Set UNIFI_CONTROLLER_TOTP to your current TOTP code." | ||
| ) | ||
|
Comment on lines
203
to
+224
|
||
| elif response.status_code == 403: | ||
| # 403 on UDM often means wrong credentials | ||
| raise LocalAuthenticationError( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new
controller_totpsetting is user-facing, but.env.example(and any related setup docs) doesn’t includeUNIFI_CONTROLLER_TOTP, so it’s hard to discover/configure. Please add the new variable to the example env file and any relevant documentation sections so users know how to supply the MFA token.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot apply changes based on this feedback