Hi Michael,
How is this code not been updated in 4 years? or at least a github repo so that the community could contribute to make the code more stable.
One issue we had to add custom code was for authentication pending (202) returned from the authentication request.