Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support basic authentication headers with ISO-1 encoding #171

Open
dblock opened this issue Nov 29, 2014 · 1 comment
Open

Support basic authentication headers with ISO-1 encoding #171

dblock opened this issue Nov 29, 2014 · 1 comment
Labels

Comments

@dblock
Copy link
Collaborator

dblock commented Nov 29, 2014

Some browsers and also Java client send basic authentication headers with ISO-1 encoding. Other browser send it with UTF-8. Here is a patch to solve this. It try first an UTF-8 encoding and if this failing then use ISO-1 encoding.

-        final String usernamePassword = new String(authorizationHeader.getTokenBytes(), Charsets.UTF_8);
+        byte[] tokenBytes = authorizationHeader.getTokenBytes();
+        String usernamePassword = new String(tokenBytes, Charsets.UTF_8);
+        if( usernamePassword.contains( "\ufffd" ) ) { 
+            // if UTF-8 converting failing use ISO_8859_1
+            // Chrome use UTF-8, Java use ISO-1, IE and FF use ISO or platform default like CP1252
+            usernamePassword = new String(tokenBytes, Charsets.ISO_8859_1);
+        }
@dblock dblock added the bug? label Nov 29, 2014
@dblock
Copy link
Collaborator Author

dblock commented Nov 29, 2014

The patch above is likely incorrect, see http:https://stackoverflow.com/questions/7242316/what-encoding-should-i-use-for-http-basic-authentication of how to determine the encoding of the credentials.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant