This code is from early 2020 and does not demonstrate all the various ways to obtain a valid token, but it is a start. Check out the latest version MostOfDavesClass for the latest classes and methods.
You can find MostOfDavesClasses here: https://github.com/DaveBrumbaugh/MostOfDavesClasses-CSharp-Wrappers-For-ProjectWise