0

I am beginner in drf (Django rest framework), and now I'm making authorization logic with JWT. I heard that djangorestframework-simplejwt is most famous library in drf.

I saw docs, but there are no way to verify token. (exactly i cannot find it :( )

thank you.

2
  • 1
    you only need to verify it by the login API, and you have already TokenObtainPairSerializer and TokenObtainPairView Commented Jul 6, 2022 at 11:17
  • Thank you for your opinion @K.D Yeah, and I know that there is also TokenVerifyView that verify token, but i want verify token in middleware with verifing function like make token with function (which says in docs.) Commented Jul 7, 2022 at 5:01

1 Answer 1

1

in JWT you can verify if a token is valid by decoding it, your key = any key used during token creation, your algorithm = algorithm used during token creation, token = value of the token to decode

import jwt
decoded_result = jwt.decode(<token>, key=<your key>, algorithms=<your algorithm>)
print(decoded_result)

this prints decoded payload from your token if valid, else raises jwt exceptions which can be caught in a try-catch block for further processing.

Sign up to request clarification or add additional context in comments.

2 Comments

Your opinion is that It is no problem to use any library for decoding jwt if algoriths are matched. Is it right ??
oh sorry for missing out on mentioning the library, i've used PyJWT for the above piece of code, you can find info regarding the library here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.