def view_auth_classes(is_user=False, is_authenticated=True):
 def _decorator(func_or_class):
  '\n        Requires either OAuth2 or Session-based authentication.\n        If is_user is True, also requires username in URL matches the request user.\n        '
  func_or_class.authentication_classes = (JwtAuthentication, OAuth2AuthenticationAllowInactiveUser, SessionAuthenticationAllowInactiveUser)
  func_or_class.permission_classes = ()
  if is_authenticated:
   func_or_class.permission_classes += (IsAuthenticated,)
  if is_user:
   func_or_class.permission_classes += (IsUserInUrl,)
  return func_or_class
 return _decorator

def view_auth_classes ( is_user = False , is_authenticated = True ) : def _decorator ( func_or_class ) : func_or_class . authentication_classes = ( JwtAuthentication , OAuth2AuthenticationAllowInactiveUser , SessionAuthenticationAllowInactiveUser ) func_or_class . permission_classes = ( ) if is_authenticated : func_or_class . permission_classes += ( IsAuthenticated , ) if is_user : func_or_class . permission_classes += ( IsUserInUrl , ) return func_or_class return _decorator
function and class decorator that abstracts the authentication and permission checks for api views .