python - Django Rest Framework Token Authentication failure results in Pop up -
i using django rest framework token authentication. in case if call url, providing token (token aesdghfhkjdsajgaadsa) invalid or deleted, pop asking username , password. how can avoid pop up? need response
{"status": -1, "errors": "token expired"}
i using custom token authentication given,
class expiringtokenauthentication(tokenauthentication): def authenticate_credentials(self, key): try: token = self.model.objects.get(key=key) except self.model.doesnotexist: raise exceptions.authenticationfailed('invalid token') if not token.user.is_active: raise exceptions.authenticationfailed('user inactive or deleted') # required time comparison utc_now = datetime.utcnow() utc_now = utc_now.replace(tzinfo=pytz.utc) if token.created < utc_now - timedelta(hours=24): token.delete() raise exceptions.authenticationfailed('token has expired') return token.user, token
is there solution this?
i assume pop-up username/password generated http basic/digest authentication schemes? that's coming basicauthentication authentication class.
django rest framework iterate through authentication methods listed in default_authentication_classes unless have explicitly provided list in apiview.authentication_classes.
http://www.django-rest-framework.org/api-guide/authentication/#setting-the-authentication-scheme
Comments
Post a Comment