You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
'signing_secret_key': 'secret', # secret or private key
125
+
'verifying_secret_key': "", # public key
126
+
'audience': None,
127
+
128
+
'issuer': None,
129
+
'jwk_url': None,
130
+
131
+
'jti': "jti",
132
+
'lifetime': timedelta(minutes=5), # token lifetime, this will example in 5 mins
133
+
134
+
'json_encoder':json.JSONEncoder # token lifetime, this will example
135
+
}
136
+
```
137
+
138
+
-### `lifetime`
139
+
A `datetime.timedelta`objectis employed to define the validity duration of the tokens.
140
+
When generating a token, this `timedelta` value is combined with the present `UTC` time to establish the default `exp` claim value for the token.
141
+
142
+
-### `algorithm`
143
+
The chosen algorithm from the `PyJWT` library governs the signing and verification procedures for tokens.
144
+
For symmetric HMAC signing and verification, you have the option to use the following algorithms: `HS256`, `HS384`, and`HS512`.
145
+
In the case of an HMAC algorithm, the signing_secret_key serves both as the signing and verifying key, rendering the `verifying_secret_key` setting redundant.
146
+
On the other hand, for asymmetric RSA signing and verification, you can opt for the following algorithms: `RS256`, `RS384`, and`RS512`.
147
+
In this scenario, selecting an RSA algorithm mandates configuring the `signing_secret_key` setting with an RSA private key string. Correspondingly, the `verifying_secret_key` setting must contain an RSA public key string
148
+
149
+
-### `signing_secret_key`
150
+
The signing key utilized for signing the content of generated tokens has distinct requirements based on the signing protocol.
151
+
For HMAC signing, it should be a randomly generated string containing at least as many bits as dictated by the signing protocol.
152
+
Conversely, forRSA signing, it should be a string encompassing an RSA private key with a length of 2048 bits or more.
153
+
As Simple JWT defaults to 256-bit HMAC signing, the `signing_secret_key` setting automatically takes on the value of your django project's `SECRET_KEY`.
154
+
While this default is practical, it's advisable for developers to modify this setting to a value separate from the django project's secret key.
155
+
This adjustment facilitates easier token signing key changes if the key is ever compromised.
156
+
157
+
-### `verifying_secret_key`
158
+
The verification key is employed to authenticate the contents of generated tokens.
159
+
In case an HMAC algorithm is indicated by the `algorithm` setting, the `verifying_secret_key` configuration is disregarded, and the `signing_secret_key` setting value will be utilized.
160
+
However, if an RSA algorithm is designated by the `algorithm` setting, the `verifying_secret_key` parameter must be populated with an RSA public key string
161
+
162
+
-### `audience`
163
+
The audience claim is incorporated into generated tokens and/or verified within decoded tokens.
164
+
If configured as`None`, this element is omitted from tokens and isn't subjected to validation.
165
+
166
+
-### `issuer`
167
+
The issuer claim is added to generated tokens and/or validated within decoded tokens.
168
+
If configured as`None`, this attribute is omitted from tokens and isn't subjected to validation.
169
+
170
+
-### `jwk_url`
171
+
The JWK_URL serves the purpose of dynamically retrieving the required public keys for token signature verification.
172
+
For instance, with Auth0, you could configure it as'https://yourdomain.auth0.com/.well-known/jwks.json'.
173
+
If set to `None`, this field is omitted from the token backend and remains inactive during validation.
174
+
175
+
-### `leeway`
176
+
Leeway provides a buffer for the expiration time, which can be defined as an integer representing seconds or a datetime.timedelta object.
177
+
For further details, please consult the following link: https://pyjwt.readthedocs.io/en/latest/usage.html#expiration-time-claim-exp
178
+
179
+
-### `jti`
180
+
The claim designated for storing a token's unique identifier, which is utilized to distinguish revoked tokens within the blacklist application.
181
+
There might be instances where an alternative claim other than the default "jti" claim needs to be employed for storing this value
182
+
183
+
-### `json_encoder`
184
+
JSON Encoder class that will be used by the `PYJWT` to encode the `jwt_payload`.
185
+
186
+
187
+
188
+
## API Spec
189
+
190
+
The `JwtService` uses [PYJWT](https://pypi.org/project/PyJWT/) underneath.
0 commit comments