Django REST Framework With Simple JWT (JSON Web Token)_ Steps on How to Sign and Verify Using the RSA Algorithm - DeV Community
Django REST Framework With Simple JWT (JSON Web Token)_ Steps on How to Sign and Verify Using the RSA Algorithm - DeV Community
Posted on 22 de mar.
Prerequisites
Before getting started, ensure you have completed the setup for Simple JWT
Background
In order to use the RSA algorithm, we need to have a private key and a public key.
The private key is used during the signing process of generating the token. The
public key is used to verify that the token is valid.
Step-by-Step Guide
1. Generate Private and Public Keys
openssl genpkey -algorithm RSA -out private.key -pkeyopt rsa_keygen_bits:2048
and
However, the key values contain newline characters, which are invalid in .env files. To
fix this, convert the keys into a valid format before setting the values.
For example, in VSCode, enable Regex and find all \n in the key value and replace it
with \\n
After formatting:
4. Configure SIMPLE_JWT
Make sure to provide ALGORITHM , SIGNING_KEY and VERIFYING_KEY in SIMPLE_JWT in
setting.py
SIMPLE_JWT = {
...
"ALGORITHM": "RS256",
"SIGNING_KEY": SIGNING_KEY,
"VERIFYING_KEY": VERIFYING_KEY
}
Postmark PROMOTED
Start free
Jen C.
JOINED
4 de jun. de 2023
Security - Solving the "Content Security Policy (CSP) Header Not Set" in Next.js
nextjs webdev security javascript
Jest - How to verify that an element does not exist in the rendered output
jest react testing webdev
Jest - Testing with React and React Testing Library: Useful APIs
jest react testing webdev
Sentry PROMOTED
Make it make sense
Make sense of fixing your code with straight-forward application monitoring.
Start debugging →