Dieses Repository beinhaltet HTML- und Javascript Code zur einer NotizenWebApp auf Basis von Web Storage. Zudem sind Mocha/Chai Tests im Browser enthalten. https://meinenotizen.netlify.app/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 9.6KB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. # http-auth
  2. [Node.js](http://nodejs.org/) package for HTTP basic and digest access authentication.
  3. [![Build Status](https://api.travis-ci.org/http-auth/http-auth.png)](https://travis-ci.org/http-auth/http-auth)
  4. ## Installation
  5. Via git (or downloaded tarball):
  6. ```bash
  7. $ git clone git://github.com/http-auth/http-auth.git
  8. ```
  9. Via [npm](http://npmjs.org/):
  10. ```bash
  11. $ npm install http-auth
  12. ```
  13. ## Basic example
  14. ```javascript
  15. // Authentication module.
  16. var auth = require('http-auth');
  17. var basic = auth.basic({
  18. realm: "Simon Area.",
  19. file: __dirname + "/../data/users.htpasswd"
  20. });
  21. // Creating new HTTP server.
  22. http.createServer(basic, (req, res) => {
  23. res.end(`Welcome to private area - ${req.user}!`);
  24. }).listen(1337);
  25. ```
  26. ## Custom authentication
  27. ```javascript
  28. // Authentication module.
  29. var auth = require('http-auth');
  30. var basic = auth.basic({
  31. realm: "Simon Area."
  32. }, (username, password, callback) => {
  33. // Custom authentication
  34. // Use callback(error) if you want to throw async error.
  35. callback(username === "Tina" && password === "Bullock");
  36. }
  37. );
  38. // Creating new HTTP server.
  39. http.createServer(basic, (req, res) => {
  40. res.end(`Welcome to private area - ${req.user}!`);
  41. }).listen(1337);
  42. ```
  43. ## [express framework](http://expressjs.com/) integration
  44. ```javascript
  45. // Authentication module.
  46. var auth = require('http-auth');
  47. var basic = auth.basic({
  48. realm: "Simon Area.",
  49. file: __dirname + "/../data/users.htpasswd"
  50. });
  51. // Application setup.
  52. var app = express();
  53. app.use(auth.connect(basic));
  54. // Setup route.
  55. app.get('/', (req, res) => {
  56. res.send(`Hello from express - ${req.user}!`);
  57. });
  58. ```
  59. ## [koa framework](http://koajs.com/) integration
  60. ```javascript
  61. // Authentication module.
  62. var auth = require('http-auth');
  63. var basic = auth.basic({
  64. realm: "Simon Area.",
  65. file: __dirname + "/../data/users.htpasswd"
  66. });
  67. // Final handler.
  68. app.use(function *(next) {
  69. yield next;
  70. this.body = `Hello from koa - ${this.req.user}!`;
  71. });
  72. // Enable auth.
  73. app.use(auth.koa(basic));
  74. ```
  75. ## For [koa@next](https://github.com/koajs/koa/tree/v2.x) you can use [http-auth-koa](https://github.com/http-auth/http-auth-koa)
  76. ```javascript
  77. // Authentication module.
  78. import auth from 'http-auth'
  79. import koaAuth from 'http-auth-koa'
  80. const basic = auth.basic({
  81. realm: "Simon Area.",
  82. file: __dirname + "/../data/users.htpasswd"
  83. });
  84. // Koa setup.
  85. import Koa from 'koa'
  86. const app = new Koa();
  87. // Setup basic handler.
  88. app.use(async (ctx, next) => {
  89. await next();
  90. ctx.body = `Welcome to koa ${ctx.req.user}!`;
  91. });
  92. // Setup auth.
  93. app.use(koaAuth(basic));
  94. ```
  95. ## [hapi framework](http://hapijs.com/) integration
  96. ```javascript
  97. // Authentication module.
  98. const auth = require('http-auth');
  99. // Setup auth.
  100. const basic = auth.basic({
  101. realm: "Simon Area.",
  102. file: __dirname + "/../data/users.htpasswd"
  103. });
  104. // Create server.
  105. const server = new Hapi.Server();
  106. server.connection({ port: 1337 });
  107. // Register auth plugin.
  108. server.register(auth.hapi());
  109. // Setup strategy.
  110. server.auth.strategy('http-auth', 'http', basic);
  111. // Setup route.
  112. server.route({
  113. method: 'GET',
  114. path: '/',
  115. config: {
  116. auth: 'http-auth',
  117. handler: (request, reply) => {
  118. reply(`Welcome from Hapi - ${request.auth.credentials.name}!`);
  119. }
  120. }
  121. });
  122. ```
  123. ## Protecting specific path
  124. ```javascript
  125. // Authentication module.
  126. var auth = require('http-auth');
  127. var basic = auth.basic({
  128. realm: "Simon Area.",
  129. file: __dirname + "/../data/users.htpasswd"
  130. });
  131. // Application setup.
  132. var app = express();
  133. // Setup route.
  134. app.get('/admin', auth.connect(basic), (req, res) => {
  135. res.send(`Hello from admin area - ${req.user}!`);
  136. });
  137. // Setup route.
  138. app.get('/', (req, res) => {
  139. res.send("Not protected area!");
  140. });
  141. ```
  142. ## [passport](http://passportjs.org/) integration
  143. ```javascript
  144. // Authentication module.
  145. var auth = require('http-auth');
  146. var basic = auth.basic({
  147. realm: "Simon Area.",
  148. file: __dirname + "/../data/users.htpasswd"
  149. });
  150. // Application setup.
  151. var app = express();
  152. // Setup strategy.
  153. var passport = require('passport');
  154. passport.use(auth.passport(basic));
  155. // Setup route.
  156. app.get('/', passport.authenticate('http', {session: false}),
  157. (req, res) => {
  158. res.end(`Welcome to private area - ${req.user}!`);
  159. }
  160. );
  161. ```
  162. ## [http-proxy](https://github.com/nodejitsu/node-http-proxy/) integration
  163. ```javascript
  164. // Authentication module.
  165. var auth = require('http-auth');
  166. var basic = auth.basic({
  167. realm: "Simon Area.",
  168. file: __dirname + "/../data/users.htpasswd"
  169. });
  170. // Create your proxy server.
  171. httpProxy.createServer(basic, {
  172. target: 'http://localhost:1338'
  173. }).listen(1337);
  174. // Create your target server.
  175. http.createServer((req, res) => {
  176. res.end("Request successfully proxied!");
  177. }).listen(1338);
  178. ```
  179. ## Events
  180. The auth middleware emits three types of events: **error**, **fail** and **success**. Each event passes the result object (the error in case of `fail`) and the http request `req` to the listener function.
  181. ```javascript
  182. // Authentication module.
  183. var auth = require('http-auth');
  184. var basic = auth.basic({
  185. realm: "Simon Area.",
  186. file: __dirname + "/../data/users.htpasswd"
  187. });
  188. basic.on('success', (result, req) => {
  189. console.log(`User authenticated: ${result.user}`);
  190. });
  191. basic.on('fail', (result, req) => {
  192. console.log(`User authentication failed: ${result.user}`);
  193. });
  194. basic.on('error', (error, req) => {
  195. console.log(`Authentication error: ${error.code + " - " + error.message}`);
  196. });
  197. ```
  198. ## Configurations
  199. - `realm` - Authentication realm, by default it is **Users**.
  200. - `file` - File where user details are stored.
  201. - Line format is **{user:pass}** or **{user:passHash}** for basic access.
  202. - Line format is **{user:realm:passHash}** for digest access.
  203. - `algorithm` - Algorithm that will be used only for **digest** access authentication.
  204. - **MD5** by default.
  205. - **MD5-sess** can be set.
  206. - `qop` - Quality of protection that is used only for **digest** access authentication.
  207. - **auth** is set by default.
  208. - **none** this option is disabling protection.
  209. - `msg401` - Message for failed authentication 401 page.
  210. - `msg407` - Message for failed authentication 407 page.
  211. - `contentType` - Content type for failed authentication page.
  212. - `skipUser` - Set this to **true**, if you don't want req.user to be filled with authentication info.
  213. ## Running tests
  214. It uses [mocha](https://mochajs.org/), so just run following command in package directory:
  215. ```bash
  216. $ npm test
  217. ```
  218. ## Issues
  219. You can find list of issues using **[this link](http://github.com/http-auth/http-auth/issues)**.
  220. ## Questions
  221. You can also use [stackoverflow](http://stackoverflow.com/questions/tagged/http-auth) to ask questions using **[http-auth](http://stackoverflow.com/tags/http-auth/info)** tag.
  222. ## Requirements
  223. - **[Node.js](http://nodejs.org)** - Event-driven I/O server-side JavaScript environment based on V8.
  224. - **[npm](http://npmjs.org)** - Package manager. Installs, publishes and manages node programs.
  225. ## Utilities
  226. - **[htpasswd](https://github.com/http-auth/htpasswd/)** - Node.js package for HTTP Basic Authentication password file utility.
  227. - **[htdigest](https://github.com/http-auth/htdigest/)** - Node.js package for HTTP Digest Authentication password file utility.
  228. ## Dependencies
  229. - **[uuid](https://github.com/broofa/node-uuid/)** - Generate RFC4122(v4) UUIDs, and also non-RFC compact ids.
  230. - **[apache-md5](https://github.com/http-auth/apache-md5)** - Node.js module for Apache style password encryption using md5.
  231. - **[apache-crypt](https://github.com/http-auth/apache-crypt)** - Node.js module for Apache style password encryption using crypt(3).
  232. - **[bcrypt.js](https://github.com/dcodeIO/bcrypt.js)** - Optimized bcrypt in plain JavaScript with zero dependencies.
  233. ## Development dependencies
  234. - **[mocha](https://mochajs.org/)** - simple, flexible, fun javascript test framework for node.js & the browser.
  235. - **[chai](http://chaijs.com/)** - BDD / TDD assertion framework for node.js and the browser that can be paired with any testing framework.
  236. - **[express](http://expressjs.com/)** - Sinatra inspired web development framework for node.js -- insanely fast, flexible, and simple.
  237. - **[http-proxy](https://github.com/nodejitsu/node-http-proxy/)** - A full-featured http proxy for node.js.
  238. - **[request](https://github.com/request/request/)** - Simplified HTTP request client.
  239. - **[passport](http://passportjs.org/)** - Simple, unobtrusive authentication for Node.js.
  240. - **[koa](http://koajs.com/)** - next generation web framework for node.js.
  241. - **[hapi](http://hapijs.com/)** - A rich framework for building applications and services.
  242. ## License
  243. The MIT License (MIT)
  244. Copyright (c) 2016 Gevorg Harutyunyan
  245. Permission is hereby granted, free of charge, to any person obtaining a copy of
  246. this software and associated documentation files (the "Software"), to deal in
  247. the Software without restriction, including without limitation the rights to
  248. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  249. the Software, and to permit persons to whom the Software is furnished to do so,
  250. subject to the following conditions:
  251. The above copyright notice and this permission notice shall be included in all
  252. copies or substantial portions of the Software.
  253. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  254. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  255. FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  256. COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  257. IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  258. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.