Thanks for the info,
I am trying to avoid this kind of scripting altogether by sticking with multibranch pipeline plugin with declarative Jenkinsfile coming from single config file. The credentials approach would have handled the password masking etc. out-of-the-box on my behalf and much more which I state below.
I was also hoping that this approach could have given an alternative for github-plugin personal access tokens. I don't like to be creating a github bot account and hence I'm still using git-plugin and maintaining manually SSH creds. for each job/repo but using the same OAuth access tokens used for authentication would have been indeed made it possible to shift away from this and also given better auditing over who is doing what. Creation of the repo level webhooks automatically using OAuth app. access token would have become also possibility not to mention passing of the access token forward as maven repository password.
I've been tracking https://issues.jenkins-ci.org/browse/JENKINS-38963 (Stephen Connoly's option 1 with AuthorizedProject. Parameters are not what I'm after) for user-scope "Run as the user who triggered the build" credentials and I would really like to see still this addition to somehow evolve into that direction but my knowledge of Jenkins is too limited to be of any help whatsoever.
Is this hope security wise a lost cause or shall I create an issue here or to some other plugin for this?
This issue has been resolved by merging https://github.com/jenkinsci/github-oauth-plugin/pull/87. The GitHub API token granted by user consent to the OAuth app is now stored as a user property.
Example usage in the script console: