How to reliably get the current (logged-in) user into a plugin context?

Re-asking an unanswered question from community: asked by @Siegfried Nolte:

I need the username of the plugin “user” to use TrustedRequest#addTrustedTokenAuthentication.

To get this user during runtime, however, this suggested idiom does not reliably work:

   this.authContext = ComponentAccessor.getJiraAuthenticationContext();
   this.currentUser = this.authContext.getLoggedInUser();

The call to getLoggedInUser returns null at random, seemingly independent of the calling thread (ie. on an event listener thread or on a SchedulerService job thread).

What is the best way to reliably get the name of the “logged in user” in the context of the plugin thread?

I’ve run into this issue as well, calls to getLoggedInUser() are not reliable as they will periodically return null.