Add option to provide a custom getToken function

This adds the support asked discussed in #38. @kretz asked me to submit this instead of pushing to his repository and so on.