401 is expected when the token has expired federation issues are not very important
Put functions in lib/activitypub instead