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
* fix: check RelayState exist but not a token
- RelayState can also be a "/" (%2F char)
* feat(trigger): add custom token query
- can pas custom function to create token query in settings
- update README
- update Contributors
* Update README.md
Better CUSTOM_TOKEN_QUERY description
Co-authored-by: Mostafa Moradian <[email protected]>
* feat(jwt): better check of RelayState
- check if RelayState is a token before trying to decode it
- add test of is_jwt_well_formed
* feat(trigger): add custom jwt creator and decoder
- use custom trigger or default function for jwt management
- update README
- update tests with new functions
* fix: remove unused imports
* Update README.md
Change jwt to JWT
Co-authored-by: Mostafa Moradian <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+22Lines changed: 22 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -177,6 +177,9 @@ For IdP-initiated SSO, the user will be created if it doesn't exist, but for SP-
177
177
|**TRIGGER.BEFORE\_LOGIN** | A method to be called when an existing user logs in. This method will be called before the user is logged in and after the SAML2 identity provider returns user attributes. This method should accept ONE parameter of user dict. | `str` | `None` | `my_app.models.users.before_login` |
178
178
|**TRIGGER.AFTER\_LOGIN** | A method to be called when an existing user logs in. This method will be called after the user is logged in and after the SAML2 identity provider returns user attributes. This method should accept TWO parameters of session and user dict. | `str` | `None` | `my_app.models.users.after_login` |
179
179
|**TRIGGER.GET\_METADATA\_AUTO\_CONF\_URLS** | A hook function that returns a list of metadata Autoconf URLs. This can override the `METADATA_AUTO_CONF_URL` to enumerate all existing metadata autoconf URLs. | `str` | `None` | `my_app.models.users.get_metadata_autoconf_urls` |
180
+
|**TRIGGER.CUSTOM\_DECODE\_JWT** | A hook function to decode the user JWT. This method will be called instead of the `decode_jwt_token` default function and should return the user_model.USERNAME_FIELD. This method accepts one parameter: `token`. | `str` | `None` | `my_app.models.users.decode_custom_token` |
181
+
|**TRIGGER.CUSTOM\_CREATE\_JWT** | A hook function to create a custom JWT for the user. This method will be called instead of the `create_jwt_token` default function and should return the token. This method accepts one parameter: `user`. | `str` | `None` | `my_app.models.users.create_custom_token` |
182
+
|**TRIGGER.CUSTOM\_TOKEN\_QUERY** | A hook function to create a custom query params with the JWT for the user. This method will be called after `CUSTOM_CREATE_JWT` to populate a query and attach it to a URL; should return the query params containing the token (e.g., `?token=encoded.jwt.token`). This method accepts one parameter: `token`. | `str` | `None` | `my_app.models.users.get_custom_token_query` |
180
183
|**ASSERTION\_URL** | A URL to validate incoming SAML responses against. By default, `django-saml2-auth` will validate the SAML response's Service Provider address against the actual HTTP request's host and scheme. If this value is set, it will validate against `ASSERTION_URL` instead - perfect for when Django is running behind a reverse proxy. | `str` | `https://example.com` | |
181
184
|**ENTITY\_ID** | The optional entity ID string to be passed in the 'Issuer' element of authentication request, if required by the IDP. | `str` | `None` | `https://exmaple.com/sso/acs` |
182
185
|**NAME\_ID\_FORMAT** | Set to the string `'None'`, to exclude sending the `'Format'` property of the `'NameIDPolicy'` element in authentication requests. | `str` | `<urn:oasis:names:tc:SAML:2.0:nameid-format:transient>` | |
@@ -240,6 +243,25 @@ Otherwise if you want to use your PKI key-pair to sign JWT tokens, use either of
240
243
241
244
*Note:* If both PKI fields and`JWT_SECRET` are defined, the `JWT_ALGORITHM` decides which method to use for signing tokens.
242
245
246
+
### Custom token triggers
247
+
248
+
This is an example of the functions that could be passed to the `TRIGGER.CUSTOM_CREATE_JWT` (it uses the [DRF Simple JWT library](https://github.com/jazzband/djangorestframework-simplejwt/blob/master/docs/index.rst)) and to `TRIGGER.CUSTOM_TOKEN_QUERY`:
249
+
250
+
``` python
251
+
from rest_framework_simplejwt.tokens import RefreshToken
252
+
253
+
254
+
def get_custom_jwt(user):
255
+
"""Create token for user and return it"""
256
+
return RefreshToken.for_user(user)
257
+
258
+
259
+
def get_custom_token_query(refresh):
260
+
"""Create url query with refresh and access token"""
0 commit comments