Django JWT

In the root folder you will get a folder named servers in the servers folder you will get a folder named django . The structure of the folder is below

To start the server run the below command

python runserver 9000

All the routes are in app-> file. You will get below routes in this file

# Auth Route
    url(r'^api/secret/test', include(router.urls)),
    # No Authertication required
    url(r'^api/login', obtain_jwt_token),
    url(r'^api/refresh', refresh_jwt_token),
    url(r'^api/verify', verify_jwt_token),

We have given a user model you test it. Just check the app->server-> and the views app->server-> User Serializer below

class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = User
        fields = ('url', 'username', 'email')

User Views we Have used Django default viewset app->server->

class UserViewSet(viewsets.ModelViewSet):
    API endpoint that allows users to be viewed or edited.
    queryset = User.objects.all().order_by('-date_joined')
    serializer_class = UserSerializer

MOdify all of these to your need.

Important Notice:

For testing django server you need to change a few code as we have tested the server for GET method. So in the root directory

isomorphic-servers/src/helpers/authHelper.js Replace the below code

return await'secret/test', { token })

With below code

return await SuperFetch.get('secret/test', { token })

Here post has been replaced with get .

Another important thing is understanding the below settings. which resides in isomorphic-servers/servers/django/app/ path.

Here the below settings can be changed on your need






    'JWT_SECRET_KEY': 'secretKey',
    'JWT_PUBLIC_KEY': None,
    'JWT_PRIVATE_KEY': None,
    'JWT_ALGORITHM': 'HS256',
    'JWT_VERIFY': True,
    'JWT_LEEWAY': 0,
    # 'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=300),
    'JWT_AUDIENCE': None,
    'JWT_ISSUER': None,

    # 'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=7),

    'JWT_AUTH_COOKIE': None,


Here JWT_SECRET_KEY is the most important part. You have to use same secret key for both frontend and back end. The frontend config can be found in path isomorphic-servers/src/settings/index.js under below config

const jwtConfig = {
  fetchUrl: '/api/',
  secretKey: 'secretKey',

results matching ""

    No results matching ""