Giter Site home page Giter Site logo

Comments (5)

jpadilla avatar jpadilla commented on July 28, 2024 1

You should be able do something like this.

from rest_framework_jwt.settings import api_settings

jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
jwt_encode_handler = api_settings.JWT_ENCODE_HANDLER

payload = jwt_payload_handler(user)
token = jwt_encode_handler(payload)

from django-rest-framework-jwt.

ConorMcGee avatar ConorMcGee commented on July 28, 2024 1

Just wondering if you think this might belong in the docs? Or have it's own utility function? I'm using it for automatic login after registration/activation, which I think would be a pretty common use case. Great app!

from django-rest-framework-jwt.

DavidMuller avatar DavidMuller commented on July 28, 2024

@jpadilla

Will using

payload = jwt_payload_handler(user)
token = jwt_encode_handler(payload)

skip adding'orig_iat'? That's something the JSONWebTokenSerializer does:

payload = jwt_payload_handler(user)

# Include original issued at time for a brand new token,
# to allow token refresh
if api_settings.JWT_ALLOW_REFRESH:
    payload['orig_iat'] = timegm(
        datetime.utcnow().utctimetuple()
    )

return {
    'token': jwt_encode_handler(payload)
}

from django-rest-framework-jwt.

jpadilla avatar jpadilla commented on July 28, 2024

@DavidMuller yup, it will skip adding 'orig_iat'. You'll only need that if you're using token refresh. If you still need it, you can do:

payload = jwt_payload_handler(user)
payload['orig_iat'] = timegm(datetime.utcnow().utctimetuple())
token = jwt_encode_handler(payload)

from django-rest-framework-jwt.

jpadilla avatar jpadilla commented on July 28, 2024

Closing this, since it's mostly a usage question.

from django-rest-framework-jwt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.