私はdjango restフレームワークのトークン認証を使用しています。無効または既に削除されているトークン (トークン aesdghfhkjdsajgaadsa) を指定して URL を呼び出すと、ユーザー名とパスワードを要求するポップアップが表示されます。どうすればそのポップアップを回避できますか? 私はちょうど応答が必要です
{"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
これに対する解決策はありますか?