def get_user_for_token(token, scope, max_age=None):
 try:
  data = signing.loads(token, max_age=max_age)
 except signing.BadSignature:
  raise exc.NotAuthenticated(_('Invalid token'))
 model_cls = get_user_model()
 try:
  user = model_cls.objects.get(pk=data[('user_%s_id' % scope)])
 except (model_cls.DoesNotExist, KeyError):
  raise exc.NotAuthenticated(_('Invalid token'))
 else:
  return user

def get_user_for_token ( token , scope , max_age = None ) : try : data = signing . loads ( token , max_age = max_age ) except signing . BadSignature : raise exc . NotAuthenticated ( _ ( 'Invalid token' ) ) model_cls = get_user_model ( ) try : user = model_cls . objects . get ( pk = data [ ( 'user_%s_id' % scope ) ] ) except ( model_cls . DoesNotExist , KeyError ) : raise exc . NotAuthenticated ( _ ( 'Invalid token' ) ) else : return user
given a selfcontained token and a scope try to parse and unsign it .