-
Notifications
You must be signed in to change notification settings - Fork 8
SQLAdmin authorization panel #95
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
Conversation
KaliszS
left a comment
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.
Thanks for your PR! Since there is no real code quality check in CI for that template (it would be difficult with jinja), can you generate a local project from the template (use: copier copy https://github.com/szyszkapiotr/python-ai-kit $YOUR_LOCAL_MANUALY_CREATED_DIRECTORY --trust -r sqladmin-auth) and confirm whether uv run pre-commit run --all-files ends up clean? Or fix linter issues if not.
| from app.config import settings | ||
| from fastapi import Request | ||
| from pydantic import SecretStr | ||
|
|
||
| from sqladmin.authentication import AuthenticationBackend |
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.
External modules and internal modules improts should be in different visual sections:
from fastapi import Request
from pydantic import SecretStr
from sqladmin.authentication import AuthenticationBackend
from app.config import settingsThere 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.
My IDE automatically sorts imports. For some reason it did not find it as internal module and placed it in such order. Changed it to be correct. Thanks!
|
|
||
| return hmac.compare_digest(token, current_token) | ||
|
|
||
| def _credentials_valid(self, username: str, password: str) -> bool: |
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.
Can you rename that method so it will be action? Like _validate_credentials
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.
Done
| return str(slot_number) | ||
|
|
||
| @property | ||
| def VALID_PASSWORD(self) -> str: # noqa: N802 |
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.
why noqa here and in property below?
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.
uv run pre-commit run --all-files
ruff check...............................................................Failed
- hook id: ruff-check
- exit code: 1
N802 Function name VALID_PASSWORD should be lowercase
--> app/integrations/sqladmin/auth.py:62:9

This pull request introduces a simple authorization mechanism for SQLAdmin by implementing a custom AuthenticationBackend. The solution uses username and password credentials combined with a rotating token for additional security.
The token is time-based and configurable via
SQLADMIN_TOKEN_TTLenv variable, ensuring that stored session tokens automatically expire and are replaced periodically.Key features added in this PR:
AdminAuth backend extending
sqladmin.authentication.AuthenticationBackendcredential-based login configurable from .env
time-based HMAC token with configurable TTL
Resolves #94