Fix browser lib

The browser lib was generating the wrong authorization header and upon comparing with the nodejs client lib I noticed some inconsistencies, so I refactored it to reuse as much of the node version as possible which fixed the issue.

I have verified that the authorization header is being created properly and that the tests pass.