728x90
1. Make new CustomTokenStrategy inherit TokenStrategy
from djoser.social.token.jwt import TokenStrategy
# REf. https://stackoverflow.com/questions/65934755/django-how-do-i-return-jwt-with-custom-claim-after-user-sign-up
class CustomTokenStrategy(TokenStrategy):
@classmethod
def obtain(cls, user):
from rest_framework_simplejwt.tokens import RefreshToken
refresh = RefreshToken.for_user(user)
refresh["username"] = user.username
return {"access": str(refresh.access_token), "refresh": str(refresh)}
2. Update settings.py for CustomTokenStrategy
DJOSER = {
...
"SOCIAL_AUTH_TOKEN_STRATEGY": "backend.token.CustomTokenStrategy",
...
}
You can add whatever you want.
Djoser uses rest_framework_simplejwt so the package is wrapped.
So sometimes you want to change something about jwt things. you need to change more codes not only rest_framework_simplejwt also Djoser.
Make sure that.
728x90
'IT > Django' 카테고리의 다른 글
django request.user가 anonymous로만 나오는 이유? (0) | 2023.06.28 |
---|---|
제대로된 해결 방법 - received a naive datetime while time zone support is active. (0) | 2023.06.22 |
python script에서 django model 얻는법 (0) | 2023.05.23 |
UnicodeDecodeError: 'cp949' codec can't decode bytes in position : illegal multibyte sequence (0) | 2023.05.09 |
Setup django-allauth social login (0) | 2022.09.08 |