Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
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 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # digest-fetch
  2. [![Join the chat at https://gitter.im/devfans/digest-fetch](https://badges.gitter.im/devfans/digest-fetch.svg)](https://gitter.im/devfans/digest-fetch?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
  3. [![NPM Version][npm-image]][npm-url]
  4. [![NPM Downloads][downloads-image]][downloads-url]
  5. [![Build Status][travis-image]][travis-url]
  6. [![Test Coverage][coveralls-image]][coveralls-url]
  7. digest auth request plugin for fetch/node-fetch also supports http basic authentication
  8. ## Installation
  9. ```
  10. // dependencies for node
  11. npm install node-fetch
  12. // for browers, if to use it directly, please indcude file `digest-fetch.js` in a <script/>
  13. <script type="application/javascript" src="path-to-digest-fetch.js'></script>
  14. ```
  15. ## Get Started
  16. ```
  17. // Use require
  18. const DigestFetch = require('digest-fetch')
  19. // Use import
  20. import * as DigestFetch from "digest-fetch"
  21. // In browser
  22. const DigestFetch = window.DigestFetch;
  23. ```
  24. #### Http Basic Authentication
  25. Create a client using basic authentication challenge
  26. ```
  27. const client = new DigestFetch('user', 'password', { basic: true })
  28. client.fetch(url, options).then(res => res.json).then(console.dir)
  29. ```
  30. #### Digest Access Authentication
  31. Create a digest authentication request client with default options
  32. ```
  33. const client = new DigestFetch('user', 'password')
  34. ```
  35. Specify options for digest authentication
  36. ```
  37. const client = new DigestFetch('user', 'password', { algorithm: 'MD5' })
  38. ```
  39. Options fields:
  40. | field | type | default | description |
  41. | :------------- | :---------- | :-----------: | :---------- |
  42. | algorithm | string | 'MD5' | algorithm to be used: 'MD5' or 'MD5-sess' |
  43. | statusCode | number | 401 | custom alternate authentication failure code for avoiding browser prompt, see details below |
  44. | cnonceSize | number | 32 | length of the cnonce |
  45. | logger | object | none | logger for debug, can use `console`, default no logging |
  46. | basic | bool | false | switch to use basic authentication |
  47. | precomputeHash | bool | false | wether to attach hash of credentials to the client instance instead of raw credential |
  48. Details:
  49. + When using digest authentication in browsers, may encounter prompt window in foreground. Check: https://stackoverflow.com/questions/9859627/how-to-prevent-browser-to-invoke-basic-auth-popup-and-handle-401-error-using-jqu
  50. Do request same way as fetch or node-fetch
  51. ```
  52. const url = ''
  53. const options = {}
  54. client.fetch(url, options)
  55. .then(resp=>resp.json())
  56. .then(data=>console.log(data))
  57. .catch(e=>console.error(e))
  58. ```
  59. Pass in refresh request options factory function for conditions options needs be refreshed when trying again.
  60. For example when posting with file stream:
  61. ```
  62. const factory = () => ({ method: 'post', body: fs.createReadStream('path-to-file') })
  63. client.fetch(url, {factory})
  64. .then(resp=>resp.json())
  65. .then(data=>console.log(data))
  66. .catch(e=>console.error(e))
  67. ```
  68. ## About
  69. Digest authentication: https://en.wikipedia.org/wiki/Digest_access_authentication
  70. This plugin is implemented following RFC2069 and RFC2617, supports http basic authentication as well!
  71. Please open issues if you find bugs or meet problems during using this plugin.
  72. Feel free to open PRs whenever you have better ideas on this project!
  73. [npm-image]: https://img.shields.io/npm/v/digest-fetch.svg
  74. [npm-url]: https://npmjs.org/package/digest-fetch
  75. [travis-image]: https://img.shields.io/travis/devfans/digest-fetch/master.svg
  76. [travis-url]: https://travis-ci.org/devfans/digest-fetch
  77. [coveralls-image]: https://img.shields.io/coveralls/devfans/digest-fetch/master.svg
  78. [coveralls-url]: https://coveralls.io/r/devfans/digest-fetch?branch=master
  79. [downloads-image]: https://img.shields.io/npm/dm/digest-fetch.svg
  80. [downloads-url]: https://npmjs.org/package/digest-fetch