Created
April 26, 2018 16:11
-
-
Save Fusl/c41e66cb63f0de6684accfdf4ff4242a to your computer and use it in GitHub Desktop.
Node.js/Javascript function to extract HTTP Basic auth from Authorization header string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getBasicAuthArray = data => { | |
data = data.split(' '); | |
if (data.length !== 2 || !data[0].length || !data[1].length || data[0].toLowerCase() !== 'basic') return [null, null]; | |
let basicAuthData = Buffer.from(data[1], 'base64').toString('utf8').split(':'); | |
return [basicAuthData.shift(), basicAuthData.join(':')]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment