diff options
Diffstat (limited to 'web')
-rw-r--r-- | web/cobrands/fixmybarangay/message_manager_client.js | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/web/cobrands/fixmybarangay/message_manager_client.js b/web/cobrands/fixmybarangay/message_manager_client.js index eb9d8c925..fd2195124 100644 --- a/web/cobrands/fixmybarangay/message_manager_client.js +++ b/web/cobrands/fixmybarangay/message_manager_client.js @@ -133,12 +133,32 @@ var message_manager = (function() { } }; - // btoa doesn't work on all browers? var make_base_auth = function(user, password) { var tok = user + ':' + password; - var hash = window.btoa(tok); + var hash = encodeBase64(tok); // window.btoa(tok) doesn't work on all browers return "Basic " + hash; }; + + function encodeBase64(input) { + var + chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=', + INVALID_CHARACTER_ERR = (function () { + // fabricate a suitable error object + try { document.createElement('$'); } + catch (error) { return error; }}()); + // encoder + // [https://gist.github.com/999166] by [https://github.com/nignag] + for ( + var block, charCode, idx = 0, map = chars, output = ''; + input.charAt(idx | 0) || (map = '=', idx % 1); + output += map.charAt(63 & block >> 8 - idx % 1 * 8) + ) { + charCode = input.charCodeAt(idx += 3/4); + if (charCode > 0xFF) throw INVALID_CHARACTER_ERR; + block = block << 8 | charCode; + } + return output; + }; var get_current_auth_credentials = function() { var base_auth = ""; |