code: def validate_key(request, group=None, perm=None, keytype=None):
      
      def update_last_access():
          if KEY_LAST_USED_UPDATE:
              request.key.save()
      
      if request.user.is_authenticated() and is_valid_consumer(request):
          if not group and not perm and not keytype:
              return update_last_access()
          elif keytype:
              if request.key.is_type( keytype ):
                  return update_last_access()
          elif group:
              if request.key.belongs_to_group( group ):
                  return update_last_access()
          elif perm:
              if request.key.has_perm( perm ):
                  return update_last_access()
          raise AccessForbidden
      raise AccessUnauthorized
docs: Validate the given key