-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from 4l3j0Ok/basic-auth-for-update-endpoints
Basic auth for update endpoints
- Loading branch information
Showing
6 changed files
with
45 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import secrets | ||
from fastapi import Depends, HTTPException, status | ||
from fastapi.security import HTTPBasic, HTTPBasicCredentials | ||
from typing import Annotated | ||
from modules.logger import logger | ||
from modules import config | ||
|
||
|
||
security = HTTPBasic() | ||
|
||
|
||
def validate_admin( | ||
credentials: Annotated[HTTPBasicCredentials, Depends(security)], | ||
): | ||
is_correct_username = secrets.compare_digest( | ||
credentials.username.encode("utf8"), | ||
config.ADMIN_USER.encode("utf8") | ||
) | ||
is_correct_password = secrets.compare_digest( | ||
credentials.password.encode("utf8"), | ||
config.ADMIN_PASS.encode("utf8") | ||
) | ||
return (is_correct_username and is_correct_password) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters