MCPcopy Index your code
hub / github.com/restify/node-restify / parseBasic

Function parseBasic

lib/plugins/authorization.js:26–63  ·  view source on GitHub ↗
(string)

Source from the content-addressed store, hash-verified

24///--- Helpers
25
26function parseBasic(string) {
27 var decoded;
28 var index;
29 var pieces;
30
31 decoded = new Buffer(string, 'base64').toString('utf8');
32
33 if (!decoded) {
34 throw new InvalidHeaderError('Authorization header invalid');
35 }
36
37 index = decoded.indexOf(':');
38
39 if (index === -1) {
40 pieces = [decoded];
41 } else {
42 pieces = [decoded.slice(0, index), decoded.slice(index + 1)];
43 }
44
45 if (!pieces || typeof pieces[0] !== 'string') {
46 throw new InvalidHeaderError('Authorization header invalid');
47 }
48
49 // Allows for usernameless authentication
50 if (!pieces[0]) {
51 pieces[0] = null;
52 }
53
54 // Allows for passwordless authentication
55 if (!pieces[1]) {
56 pieces[1] = null;
57 }
58
59 return {
60 username: pieces[0],
61 password: pieces[1]
62 };
63}
64
65function parseSignature(request, options) {
66 var opts = options || {};

Callers 1

parseAuthorizationFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected