Skip to content

Commit

Permalink
Fix typo in function get_token_payload
Browse files Browse the repository at this point in the history
  • Loading branch information
BurnySc2 committed Oct 17, 2021
1 parent ef223bc commit 2bdbff0
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 12 deletions.
6 changes: 3 additions & 3 deletions graphql_auth/mixins.py
Expand Up @@ -26,7 +26,7 @@
PasswordAlreadySetError,
)
from .constants import Messages, TokenAction
from .utils import revoke_user_refresh_token, get_token_paylod, using_refresh_tokens
from .utils import revoke_user_refresh_token, get_token_payload, using_refresh_tokens
from .shortcuts import get_user_by_email, get_user_to_login
from .signals import user_registered, user_verified
from .decorators import (
Expand Down Expand Up @@ -296,7 +296,7 @@ class PasswordResetMixin(Output):
def resolve_mutation(cls, root, info, **kwargs):
try:
token = kwargs.pop("token")
payload = get_token_paylod(
payload = get_token_payload(
token,
TokenAction.PASSWORD_RESET,
app_settings.EXPIRATION_PASSWORD_RESET_TOKEN,
Expand Down Expand Up @@ -339,7 +339,7 @@ class PasswordSetMixin(Output):
def resolve_mutation(cls, root, info, **kwargs):
try:
token = kwargs.pop("token")
payload = get_token_paylod(
payload = get_token_payload(
token,
TokenAction.PASSWORD_SET,
app_settings.EXPIRATION_PASSWORD_SET_TOKEN,
Expand Down
6 changes: 3 additions & 3 deletions graphql_auth/models.py
Expand Up @@ -11,7 +11,7 @@

from .settings import graphql_auth_settings as app_settings
from .constants import TokenAction
from .utils import get_token, get_token_paylod
from .utils import get_token, get_token_payload
from .exceptions import (
UserAlreadyVerified,
UserNotVerified,
Expand Down Expand Up @@ -139,7 +139,7 @@ def clean_email(cls, email=False):

@classmethod
def verify(cls, token):
payload = get_token_paylod(
payload = get_token_payload(
token, TokenAction.ACTIVATION, app_settings.EXPIRATION_ACTIVATION_TOKEN
)
user = UserModel._default_manager.get(**payload)
Expand All @@ -153,7 +153,7 @@ def verify(cls, token):

@classmethod
def verify_secondary_email(cls, token):
payload = get_token_paylod(
payload = get_token_payload(
token,
TokenAction.ACTIVATION_SECONDARY_EMAIL,
app_settings.EXPIRATION_SECONDARY_EMAIL_ACTIVATION_TOKEN,
Expand Down
9 changes: 8 additions & 1 deletion graphql_auth/utils.py
@@ -1,9 +1,11 @@
import warnings
from django.core import signing
from django.contrib.auth import get_user_model
from django.conf import settings as django_settings
from django.core.signing import BadSignature

from .exceptions import TokenScopeError
warnings.simplefilter("once")


def get_token(user, action, **kwargs):
Expand All @@ -17,14 +19,19 @@ def get_token(user, action, **kwargs):
return token


def get_token_paylod(token, action, exp=None):
def get_token_payload(token, action, exp=None):
payload = signing.loads(token, max_age=exp)
_action = payload.pop("action")
if _action != action:
raise TokenScopeError
return payload


def get_token_paylod(token, action, exp=None):
warnings.warn("get_token_paylod is deprecated, use get_token_payload instead", DeprecationWarning, stacklevel=2)
return get_token_payload(token, action, exp)


def using_refresh_tokens():
if (
hasattr(django_settings, "GRAPHQL_JWT")
Expand Down
2 changes: 1 addition & 1 deletion tests/test_password_change.py
Expand Up @@ -6,7 +6,7 @@

from graphql_auth.utils import revoke_user_refresh_token
from graphql_auth.constants import Messages
from graphql_auth.utils import get_token, get_token_paylod
from graphql_auth.utils import get_token, get_token_payload


class PasswordChangeTestCaseMixin:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_password_reset.py
Expand Up @@ -2,7 +2,7 @@

from .testCases import RelayTestCase, DefaultTestCase
from graphql_auth.constants import Messages
from graphql_auth.utils import get_token, get_token_paylod
from graphql_auth.utils import get_token, get_token_payload


class PasswordResetTestCaseMixin:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_password_set.py
Expand Up @@ -2,7 +2,7 @@

from .testCases import RelayTestCase, DefaultTestCase
from graphql_auth.constants import Messages
from graphql_auth.utils import get_token, get_token_paylod
from graphql_auth.utils import get_token, get_token_payload


class PasswordSetTestCaseMixin:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_register.py
Expand Up @@ -10,7 +10,7 @@

from graphql_auth.constants import Messages
from graphql_auth.signals import user_registered
from graphql_auth.utils import get_token, get_token_paylod
from graphql_auth.utils import get_token, get_token_payload


class RegisterTestCaseMixin:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_verify_account.py
Expand Up @@ -2,7 +2,7 @@

from .testCases import RelayTestCase, DefaultTestCase
from graphql_auth.constants import Messages
from graphql_auth.utils import get_token, get_token_paylod
from graphql_auth.utils import get_token, get_token_payload
from graphql_auth.models import UserStatus
from graphql_auth.signals import user_verified

Expand Down

0 comments on commit 2bdbff0

Please sign in to comment.