Skip to content

jwt token generation public api #338

@AriaMoradi

Description

@AriaMoradi

Hey, I had to write this code for creating the correct token payload, can the library be modified to provide an appropriate public api for usecases like this?
Sorry if the language is not polite.

from strawberry_django_jwt.object_types import TokenDataType, TokenPayloadType
from strawberry_django_jwt.decorators import on_token_auth_resolve, refresh_expiration
from strawberry_django_jwt.settings import jwt_settings
from calendar import timegm
from datetime import datetime


def generate_jwt_token_payload(info: Info, user: User):
    """
    This little abomination uses strawberry_django_jwt's cursed internals to generate a token
    compatible with `strawberry_django_jwt.mutations.ObtainJSONWebToken.obtain`
    """
    payload = TokenDataType(payload=TokenPayloadType())
    payload = on_token_auth_resolve((info, user, payload))
    payload.refresh_expires_in = timegm(
        datetime.utcnow().utctimetuple()) + jwt_settings.JWT_REFRESH_EXPIRATION_DELTA.total_seconds()
    return payload

Metadata

Metadata

Assignees

Labels

enhancementNew feature or requestpythonPull requests that update Python code

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions