Guest User

Untitled

a guest
Dec 29th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. var nano = require('nano')('http://localhost:5984')
  2. const username = 'test'
  3. const userpass = '123123'
  4. const callback = console.log // this would normally be some callback
  5. const cookies = {} // store cookies, normally redis or something
  6.  
  7. nano.auth(username, userpass, function (err, body, headers)
  8. {
  9. if (err)
  10. {
  11. return callback(err);
  12. }
  13.  
  14. if (headers && headers['set-cookie'])
  15. {
  16. cookies[username] = headers['set-cookie'];
  17. console.log(cookies)
  18. }
  19.  
  20. if (!err)
  21. {
  22. callback("success ", "it worked");
  23. }
  24. });
  25.  
  26. { test:
  27. [ 'AuthSession=dGVzdDo1QTQ1RTFENDoVzjtA5v82S3bJRyI9Mz_J9dXrWA; Version=1;
  28. Expires=Thu, 28-Dec-2017 22:43:56 GMT; Max-Age=600; Path=/; HttpOnly' ] }
  29. success it worked
  30.  
  31. name: 'Error',
  32. error: 'unauthorized',
  33. reason: 'Authentication required.',
  34. scope: 'couch',
  35. statusCode: 401,
  36. request:
  37. { method: 'POST',
  38. headers:
  39. { 'content-type': 'application/x-www-form-urlencoded; charset=utf-8',
  40. accept: 'application/json' },
  41. uri: 'http://localhost:5984/_session',
  42. body: 'name=test&password=123123' },
  43. headers:
  44. { 'www-authenticate': 'Basic realm="server"',
  45. date: 'Fri, 29 Dec 2017 06:42:10 GMT',
  46. 'content-type': 'application/json',
  47. 'cache-control': 'must-revalidate',
  48. statusCode: 401,
  49. uri: 'http://localhost:5984/_session' },
  50. errid: 'non_200',
  51. description: 'couch returned 401' }
Add Comment
Please, Sign In to add comment