I want to add data (such as the token expiration date or user info) to the payload of the JWT generated by this library.
The current decoded payload of a JWT generated by this library is the following:
{
"token": "sXF6EE6jlZRmKhx1mgodOCdUMuSE1I"
}
And I want something like this
{
"expiration_date": 1588329561
}
I don't have any serializer or view implemented, because the library manages the serializers and the views.
I only have to declare the following URL in the urls.py file:
urlpatterns = [
...,
path('auth/', include('drf_social_oauth2.urls', namespace='drf')),
...,
]
and then I can make POST requests to generate or refresh the JWTs to auth/token/.
I've seen solutions (of people that use other libraries) that try to modify the library, and others that implement a serializer and a view, but since the library I'm using is in charge of this task, I don't know how to address this problem.
Note:
- The maintainers of
drf-social-auth2indicate that it relies onpython-social-authanddjango-oauth-toolkit.
drf-social-oauth2doesn't provide a mechanism to easily override this setting, it overridesoauth2_provider.settings.ACCESS_TOKEN_GENERATORwith theirgenerate_tokenmethod (https://github.com/wagnerdelima/drf-social-oauth2/blob/master/drf_social_oauth2/settings.py#L11-L14), this method doesn't include extra values, only the token.You can do the same on your side overriding the value with a custom method that adds the needed keys.