Skip to content

Instantly share code, notes, and snippets.

@BrockHerion
Created August 27, 2020 00:22
Show Gist options
  • Save BrockHerion/97bed0658bdf4898dcc54a699b9946b9 to your computer and use it in GitHub Desktop.
Save BrockHerion/97bed0658bdf4898dcc54a699b9946b9 to your computer and use it in GitHub Desktop.
Settings for DjangoRest and JWT
# Other settings not shown
# Set your auth user to the new user you have created
AUTH_USER_MODEL = 'api.User'
# We need to add our api app and the rest framework to INSTALLED_APPS
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'api.apps.ApiConfig'
]
# App the REST framework url conf
ROOT_URLCONF = 'django_rest_role_jwt.urls'
# REST framework settings
REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated'
),
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication'
),
}
# Configure the JWT settings
SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=5),
'REFRESH_TOKEN_LIFETIME': timedelta(days=14),
'ROTATE_REFRESH_TOKENS': True,
'BLACKLIST_AFTER_ROTATION': False,
'ALGORITHM': 'HS256',
'SIGNING_KEY': SECRET_KEY,
'VERIFYING_KEY': None,
'AUTH_HEADER_TYPES': ('JWT',),
'USER_ID_FIELD': 'id',
'USER_ID_CLAIM': 'user_id',
'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
'TOKEN_TYPE_CLAIM': 'token_type',
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment