Skip to content

Commit

Permalink
Use import_string for token_backend (Fixes #434) (#435)
Browse files Browse the repository at this point in the history
* Use import_string for token_backend (Fixes #434)

* Fix syntax error

* Update CHANGELOG.md

* Run CI only on main branch or PR
  • Loading branch information
Andrew-Chen-Wang authored Aug 12, 2021
1 parent f97ef69 commit ff59830
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Test

on: [push, pull_request]
on:
push:
branches:
- main
pull_request:

jobs:
build:
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
## Unreleased

## Version 4.7.3

* Add integration instructions for drf-yasg ([#145](https://github.com/jazzband/djangorestframework-simplejwt/pull/145))
* Verify Serializer Should Honour Blacklist ([#239](https://github.com/jazzband/djangorestframework-simplejwt/pull/239))
* Added missing import in getting_started docs ([#431](https://github.com/jazzband/djangorestframework-simplejwt/pull/431))
* Use import_string for token_backend ([#435](https://github.com/jazzband/djangorestframework-simplejwt/pull/435))

## Version 4.7.2

* Fix BrowsableAPIRenderer needing `media_type` ([#426](https://github.com/jazzband/django-rest-framework-simplejwt/pull/426))
Expand Down
12 changes: 9 additions & 3 deletions rest_framework_simplejwt/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from django.conf import settings
from django.utils.translation import gettext_lazy as _
from django.utils.module_loading import import_string

from .exceptions import TokenBackendError, TokenError
from .settings import api_settings
Expand Down Expand Up @@ -164,10 +165,15 @@ def for_user(cls, user):
token[api_settings.USER_ID_CLAIM] = user_id

return token


_token_backend = None

def get_token_backend(self):
from .state import token_backend
return token_backend
if self._token_backend is None:
self._token_backend = import_string(
"rest_framework_simplejwt.state.token_backend"
)
return self._token_backend


class BlacklistMixin:
Expand Down

0 comments on commit ff59830

Please sign in to comment.