-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/feat/view-users-groups' into fea…
…t/view-users-groups
- Loading branch information
Showing
48 changed files
with
1,351 additions
and
741 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
".": "2.143.0" | ||
".": "2.144.0" | ||
} |
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
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
Empty file.
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,17 @@ | ||
from rest_framework.request import Request | ||
from rest_framework_simplejwt.authentication import JWTAuthentication | ||
from rest_framework_simplejwt.tokens import Token | ||
|
||
from custom_auth.jwt_cookie.constants import JWT_SLIDING_COOKIE_KEY | ||
from users.models import FFAdminUser | ||
|
||
|
||
class JWTCookieAuthentication(JWTAuthentication): | ||
def authenticate_header(self, request: Request) -> str: | ||
return f'Cookie realm="{self.www_authenticate_realm}"' | ||
|
||
def authenticate(self, request: Request) -> tuple[FFAdminUser, Token] | None: | ||
if raw_token := request.COOKIES.get(JWT_SLIDING_COOKIE_KEY): | ||
validated_token = self.get_validated_token(raw_token) | ||
return self.get_user(validated_token), validated_token | ||
return None |
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 @@ | ||
JWT_SLIDING_COOKIE_KEY = "jwt" |
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,18 @@ | ||
from django.conf import settings | ||
from rest_framework.response import Response | ||
from rest_framework_simplejwt.tokens import SlidingToken | ||
|
||
from custom_auth.jwt_cookie.constants import JWT_SLIDING_COOKIE_KEY | ||
from users.models import FFAdminUser | ||
|
||
|
||
def authorise_response(user: FFAdminUser, response: Response) -> Response: | ||
sliding_token = SlidingToken.for_user(user) | ||
response.set_cookie( | ||
JWT_SLIDING_COOKIE_KEY, | ||
str(sliding_token), | ||
httponly=True, | ||
secure=settings.USE_SECURE_COOKIES, | ||
samesite=settings.COOKIE_SAME_SITE, | ||
) | ||
return response |
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,20 @@ | ||
from typing import Any | ||
from urllib.parse import urlparse | ||
|
||
from core.helpers import get_current_site_url | ||
from corsheaders.signals import check_request_enabled | ||
from django.dispatch import receiver | ||
from django.http import HttpRequest | ||
|
||
|
||
@receiver(check_request_enabled) | ||
def cors_allow_current_site(request: HttpRequest, **kwargs: Any) -> bool: | ||
# The signal is expected to only be dispatched: | ||
# - When `settings.CORS_ORIGIN_ALLOW_ALL` is set to `False`. | ||
# - For requests with `HTTP_ORIGIN` set. | ||
origin_url = urlparse(request.META["HTTP_ORIGIN"]) | ||
current_site_url = urlparse(get_current_site_url(request)) | ||
return ( | ||
origin_url.scheme == current_site_url.scheme | ||
and origin_url.netloc == current_site_url.netloc | ||
) |
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,15 @@ | ||
from djoser.views import TokenDestroyView | ||
from rest_framework.request import Request | ||
from rest_framework.response import Response | ||
from rest_framework_simplejwt.tokens import SlidingToken | ||
|
||
from custom_auth.jwt_cookie.constants import JWT_SLIDING_COOKIE_KEY | ||
|
||
|
||
class JWTSlidingTokenLogoutView(TokenDestroyView): | ||
def post(self, request: Request) -> Response: | ||
response = super().post(request) | ||
if isinstance(jwt_token := request.auth, SlidingToken): | ||
jwt_token.blacklist() | ||
response.delete_cookie(JWT_SLIDING_COOKIE_KEY) | ||
return response |
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
Oops, something went wrong.