package/package.json000644 000765 000024 0000000461 12035064024013012 0ustar00000000 000000 { "name": "basic-auth-parser", "description": "Parse Basic Auth `Authorization` HTTP headers", "author": "Maciej Małecki ", "version": "0.0.2", "main": "./lib/basic-auth-parser.js", "devDependencies": { "vows": "0.6.x" }, "scripts": { "test": "vows --spec" } } package/.npmignore000644 000765 000024 0000000057 11766352270012541 0ustar00000000 000000 npm-debug.log node_modules .DS_Store .*.sw[op] package/README.md000644 000765 000024 0000000717 11766352270012024 0ustar00000000 000000 # basic-auth-parser [![Build Status](https://secure.travis-ci.org/mmalecki/basic-auth-parser.png)](http://travis-ci.org/mmalecki/basic-auth-parser) `basic-auth-parser` parses Basic Auth `Authorization` HTTP headers. ## Installation npm install basic-auth-parser ## Usage ```js var basicAuthParser = require('./'); console.dir(basicAuthParser('Basic YWRtaW46cGFzc3dvcmQ=')); ``` Output: ``` { scheme: 'Basic', username: 'admin', password: 'password' } ``` package/LICENSE000644 000765 000024 0000002046 11766352270011547 0ustar00000000 000000 Copyright (C) 2012 by Maciej Małecki Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. package/.travis.yml000644 000765 000024 0000000053 11766352731012651 0ustar00000000 000000 language: node_js node_js: - 0.6 - 0.7 package/lib/basic-auth-parser.js000644 000765 000024 0000000763 12035063745015160 0ustar00000000 000000 module.exports = function parse(auth) { if (!auth || typeof auth !== 'string') { throw new Error('No or wrong argument'); } var result = {}, parts, decoded, colon; parts = auth.split(' '); result.scheme = parts[0]; if (result.scheme !== 'Basic') { return result; } decoded = new Buffer(parts[1], 'base64').toString('utf8'); colon = decoded.indexOf(':'); result.username = decoded.substr(0, colon); result.password = decoded.substr(colon + 1); return result; }; package/test/basic-auth-parser-test.js000644 000765 000024 0000002043 12035063232016326 0ustar00000000 000000 var assert = require('assert'), vows = require('vows'), basicAuthParser = require('../'); vows.describe('basic-auth-parser').addBatch({ 'When using `basic-auth-parser`': { 'with a correct string input': { topic: basicAuthParser('Basic YWRtaW46cGFzc3dvcmQ='), 'it should return parsed data': function (result) { assert.deepEqual(result, { scheme: 'Basic', username: 'admin', password: 'password' }); } }, 'with a wrong scheme': { topic: basicAuthParser('Digest DEADC0FFEE'), 'it should return parsed data': function (result) { assert.deepEqual(result, { scheme: 'Digest' }); } }, 'with a correct string and a colon in password': { topic: basicAuthParser('Basic YWRtaW46cGFzczp3b3Jk'), 'it should return parsed data': function (result) { assert.deepEqual(result, { scheme: 'Basic', username: 'admin', password: 'pass:word' }); } } } }).export(module);