Skip to content

Commit

Permalink
Property revision
Browse files Browse the repository at this point in the history
  • Loading branch information
na-stewart committed Jun 21, 2024
1 parent 69d958e commit 73526ec
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion sanic_security/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ async def authenticate(request: Request) -> AuthenticationSession:
authentication_session = await AuthenticationSession.decode(request)
try:
authentication_session.validate()
if not authentication_session.is_anonymous:
if not authentication_session.anonymous:
authentication_session.bearer.validate()
except ExpiredError as e:
if security_config.AUTHENTICATION_REFRESH_AUTO:
Expand Down
6 changes: 4 additions & 2 deletions sanic_security/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ async def check_permissions(
UnverifiedError
DisabledError
AuthorizationError
AnonymousError
"""
authentication_session = await authenticate(request)
if authentication_session.is_anonymous:
if authentication_session.anonymous:
raise AnonymousError()
roles = await authentication_session.bearer.roles.filter(deleted=False).all()
for role in roles:
Expand Down Expand Up @@ -90,9 +91,10 @@ async def check_roles(request: Request, *required_roles: str) -> AuthenticationS
UnverifiedError
DisabledError
AuthorizationError
AnonymousError
"""
authentication_session = await authenticate(request)
if authentication_session.is_anonymous:
if authentication_session.anonymous:
raise AnonymousError()
roles = await authentication_session.bearer.roles.filter(deleted=False).all()
for role in roles:
Expand Down
8 changes: 3 additions & 5 deletions sanic_security/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,9 @@ def encode(self, response: HTTPResponse) -> None:
security_config.SECRET,
security_config.SESSION_ENCODING_ALGORITHM,
)
if isinstance(encoded_session, bytes):
encoded_session = encoded_session.decode()
response.cookies.add_cookie(
cookie,
encoded_session,
str(encoded_session),
httponly=security_config.SESSION_HTTPONLY,
samesite=security_config.SESSION_SAMESITE,
secure=security_config.SESSION_SECURE,
Expand Down Expand Up @@ -321,12 +319,12 @@ async def location_familiarity(self, request):
raise UnfamiliarLocationError()

@property
def is_anonymous(self) -> bool:
def anonymous(self) -> bool:
"""
Determines if an account is associated with session.
Returns:
is_anonymous
anonymous
"""
return self.bearer is None

Expand Down

0 comments on commit 73526ec

Please sign in to comment.