-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add `excluded_paths` to `SessionsAuthBackend` * try fixing mypy test * fix typo
- Loading branch information
1 parent
9cc0966
commit 7dae866
Showing
6 changed files
with
170 additions
and
26 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,43 @@ | ||
from __future__ import annotations | ||
|
||
import functools | ||
import typing as t | ||
|
||
from starlette.authentication import AuthCredentials, AuthenticationBackend | ||
from starlette.requests import HTTPConnection | ||
|
||
from piccolo_api.shared.auth import UnauthenticatedUser | ||
|
||
|
||
def check_excluded_paths(authenticate_func: t.Callable): | ||
|
||
@functools.wraps(authenticate_func) | ||
async def authenticate(self: AuthenticationBackend, conn: HTTPConnection): | ||
conn_path = dict(conn) | ||
|
||
excluded_paths = getattr(self, "excluded_paths", None) | ||
|
||
if excluded_paths is None: | ||
raise ValueError("excluded_paths isn't defined") | ||
|
||
for excluded_path in excluded_paths: | ||
if excluded_path.endswith("*"): | ||
if ( | ||
conn_path["raw_path"] | ||
.decode("utf-8") | ||
.startswith(excluded_path.rstrip("*")) | ||
): | ||
return ( | ||
AuthCredentials(scopes=[]), | ||
UnauthenticatedUser(), | ||
) | ||
else: | ||
if conn_path["path"] == excluded_path: | ||
return ( | ||
AuthCredentials(scopes=[]), | ||
UnauthenticatedUser(), | ||
) | ||
|
||
return await authenticate_func(self=self, conn=conn) | ||
|
||
return authenticate |
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