我正在使用 django rest 框架令牌身份验证。如果我调用一个 url,提供一个无效或已删除的令牌 (Token aesdghfhkjdsajgaadsa),我会弹出一个询问用户名和密码的窗口。我怎样才能避免弹出?我只需要一个回应
{"status": -1, "errors": "Token Expired"}
我正在使用给定的自定义令牌身份验证,
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')
# This is required for the 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
有解决方案吗?