A previous answer (no longer available apparently due to AI plagiarism) made me realize that I can simply recreate the connection once I've retrieved the token with the unauthorized connection.
That way, the AccessTokenProvider
function - that is only executed once starting a connection - is run again for the new one, now with the token.
This is an option that works fine so far for me (since I have no other ongoing calls than getting the token before going authorized). I do not know if this is the intended solution, so if someone knows how to set a token on running connections or there are other ways to accomplish this, please let me know in a better answer.