Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

mod_auth_token.lua 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. -- Token authentication
  2. -- Copyright (C) 2015 Atlassian
  3. local usermanager = require "core.usermanager";
  4. local new_sasl = require "util.sasl".new;
  5. local log = module._log;
  6. local host = module.host;
  7. local token_util = module:require "token/util";
  8. -- define auth provider
  9. local provider = {};
  10. --do
  11. -- local list;
  12. -- for mechanism in pairs(new_sasl(module.host):mechanisms()) do
  13. -- list = (not(list) and mechanism) or (list..", "..mechanism);
  14. -- end
  15. -- if not list then
  16. -- module:log("error", "No mechanisms");
  17. -- else
  18. -- module:log("error", "Mechanisms: %s", list);
  19. -- end
  20. --end
  21. local appId = module:get_option_string("app_id");
  22. local appSecret = module:get_option_string("app_secret");
  23. local tokenLifetime = module:get_option_number("token_lifetime");
  24. function provider.test_password(username, password)
  25. local result, msg = token_util.verify_password(password, appId, appSecret, tokenLifetime);
  26. if result == true then
  27. return true;
  28. else
  29. log("error", "Token auth failed for user %s, reason: %s",username, msg);
  30. return nil, msg;
  31. end
  32. end
  33. function provider.get_password(username)
  34. return nil;
  35. end
  36. function provider.set_password(username, password)
  37. return nil, "Set password not supported";
  38. end
  39. function provider.user_exists(username)
  40. return nil;
  41. end
  42. function provider.users()
  43. return next, hosts[module.host].sessions, nil;
  44. end
  45. function provider.create_user(username, password)
  46. return nil;
  47. end
  48. function provider.delete_user(username)
  49. return nil;
  50. end
  51. function provider.get_sasl_handler()
  52. local testpass_authentication_profile = {
  53. plain_test = function(sasl, username, password, realm)
  54. return usermanager.test_password(username, realm, password), true;
  55. end
  56. };
  57. return new_sasl(host, testpass_authentication_profile);
  58. end
  59. module:provides("auth", provider);