How can I extend expiry time of Knox-Token

I haven't changed the settings of Knox in my Django app. The default expiry time is 10hours, how can I change this that it won't expiry.

Upvotes: 1

Views: 1683

Answers (3)

Sushang Agnihotri
Sushang Agnihotri

Reputation: 666

TOKEN_TTL

    REST_KNOX = {
       'TOKEN_TTL': timedelta(hours=10),  # default time 10h
    }

just do

    REST_KNOX = {
       'TOKEN_TTL': None,  # will create tokens that never expire
    }

check the documentation

Upvotes: 2

Eventually, I have found the answer. "TOKEN_TTL": None for an unexpiry token. Thanks, all

Upvotes: 0

Dad
Dad

Reputation: 447

Change the TOKEN_TTL item on REST_KNOX. Based on docs. TOKEN_TTL This is how long a token can exist before it expires. Expired tokens are automatically removed from the system.

from datetime import timedelta
from rest_framework.settings import api_settings
REST_KNOX = {
  'SECURE_HASH_ALGORITHM': 'cryptography.hazmat.primitives.hashes.SHA512',
  'AUTH_TOKEN_CHARACTER_LENGTH': 64,
  'TOKEN_TTL': timedelta(hours=10),  # default time 10h
  'USER_SERIALIZER': 'knox.serializers.UserSerializer',
  'TOKEN_LIMIT_PER_USER': None,
  'AUTO_REFRESH': False,
  'EXPIRY_DATETIME_FORMAT': api_settings.DATETME_FORMAT,
}

Look at docs for more info.

Upvotes: 1

Related Questions