HttpBasicAuthenticator does not work if username or password contains certain special characters #261
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I noticed that the HttpBasicAuthenticator does not work if a username or password contains certain special characters, for instance Scandinavian letters (å, ä, ö). The login always fails in this case. The reason seems to be that the Base64-encoded string in the header is not correct, and the reason for this is that the conversion from String to Byte array in the method WebHelpers.Base64Encode does not handle special characters correctly.
For instance if the username is "testuser" and the password is "passwordä" then the correct Base64 encoded string is (this is given by for instance curl and base64 command line utilities):
dGVzdHVzZXI6cGFzc3dvcmTDpA==
but the Base64 encoded string given by the method WebHelpers.Base64Encode is
dGVzdHVzZXI6cGFzc3dvcmTk
I managed to fix this issue in a way that works for my use case by changing the String to Byte() conversion (see method StringConverter.Utf8BytesFromString). This code is taken from the page http://www.di-mgt.com.au/howto-convert-vba-unicode-to-utf8.html and modified to support 64bit Excel using the guide at http://stackoverflow.com/questions/21982682/code-does-not-work-on-64-bit-office. Unfortunately I didn't have the time to change the Base64Decode-method, so now if a string is first encoded and then decoded it might be changed. This pull request should thus not in any case be merged directly. I just made it to demonstrate how this issue can be fixed. Hopefully someone else can find a way to also fix the decoding method to work with special characters.