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.

test-server.js 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. const path = require("path");
  2. const express = require("express");
  3. const passport = require('passport');
  4. const Strategies = require("passport-http");
  5. const DigestStrategy = Strategies.DigestStrategy;
  6. const BasicStrategy = Strategies.BasicStrategy;
  7. module.exports = { getApp(method) {
  8. const app = express();
  9. const User = {
  10. findOne(user, callback) {
  11. return callback(null, { password: "test", username: user.username });
  12. }
  13. }
  14. passport.use(new BasicStrategy(
  15. function(userid, password, done) {
  16. User.findOne({ username: userid }, function (err, user) {
  17. if (err) { return done(err); }
  18. if (!user) { return done(null, false); }
  19. if (user.password != password) { return done(null, false); }
  20. return done(null, user);
  21. });
  22. }
  23. ));
  24. const options = {}
  25. if (method) options.qop = method
  26. passport.use(new DigestStrategy(options,
  27. function(username, done) {
  28. User.findOne({ username: username }, function (err, user) {
  29. if (err) { return done(err); }
  30. if (!user) { return done(null, false); }
  31. return done(null, user, user.password);
  32. });
  33. },
  34. function(params, done) {
  35. // validate nonces as necessary
  36. done(null, true)
  37. }
  38. ));
  39. // http basic authentication
  40. app.get('/basic',
  41. passport.authenticate('basic', { session: false }),
  42. function(req, res) {
  43. res.json(req.user);
  44. });
  45. // http digest authentication
  46. app.get('/auth',
  47. passport.authenticate('digest', { session: false }),
  48. function(req, res) {
  49. res.json(req.user);
  50. });
  51. // app.use("/static", express.static(path.join(__dirname, './static')));
  52. // app.get('/', (req, res) => res.sendFile("/home/stefan/digest/main.html") );
  53. // app.listen(3222, "0.0.0.0");
  54. return app
  55. }}