Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / basic-auth / README.md
1 # basic-auth
2
3 [![NPM Version][npm-image]][npm-url]
4 [![NPM Downloads][downloads-image]][downloads-url]
5 [![Node.js Version][node-version-image]][node-version-url]
6 [![Build Status][travis-image]][travis-url]
7 [![Test Coverage][coveralls-image]][coveralls-url]
8
9 Generic basic auth Authorization header field parser for whatever.
10
11 ## Installation
12
13 ```
14 $ npm install basic-auth
15 ```
16
17 ## API
18
19 ```js
20 var auth = require('basic-auth')
21 ```
22
23 ### auth(req)
24
25 Get the basic auth credentials from the given request. The `Authorization`
26 header is parsed and if the header is invalid, `undefined` is returned,
27 otherwise an object with `name` and `pass` properties.
28
29 ## Example
30
31 Pass a node request or koa Context object to the module exported. If
32 parsing fails `undefined` is returned, otherwise an object with
33 `.name` and `.pass`.
34
35 ```js
36 var auth = require('basic-auth');
37 var user = auth(req);
38 // => { name: 'something', pass: 'whatever' }
39
40 ```
41
42 ### With vanilla node.js http server
43
44 ```js
45 var http = require('http')
46 var auth = require('basic-auth')
47
48 // Create server
49 var server = http.createServer(function (req, res) {
50   var credentials = auth(req)
51
52   if (!credentials || credentials.name !== 'john' || credentials.pass !== 'secret') {
53     res.statusCode = 401
54     res.setHeader('WWW-Authenticate', 'Basic realm="example"')
55     res.end('Access denied')
56   } else {
57     res.end('Access granted')
58   }
59 })
60
61 // Listen
62 server.listen(3000)
63 ```
64
65 # License
66
67 [MIT](LICENSE)
68
69 [npm-image]: https://img.shields.io/npm/v/basic-auth.svg
70 [npm-url]: https://npmjs.org/package/basic-auth
71 [node-version-image]: https://img.shields.io/node/v/basic-auth.svg
72 [node-version-url]: https://nodejs.org/en/download
73 [travis-image]: https://img.shields.io/travis/jshttp/basic-auth/master.svg
74 [travis-url]: https://travis-ci.org/jshttp/basic-auth
75 [coveralls-image]: https://img.shields.io/coveralls/jshttp/basic-auth/master.svg
76 [coveralls-url]: https://coveralls.io/r/jshttp/basic-auth?branch=master
77 [downloads-image]: https://img.shields.io/npm/dm/basic-auth.svg
78 [downloads-url]: https://npmjs.org/package/basic-auth