Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

mod_auth_token.lua 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. function provider.test_password(username, password)
  24. local result, msg = token_util.verify_password(password, appId, appSecret, nil);
  25. if result == true then
  26. return true;
  27. else
  28. log("error", "Token auth failed for user %s, reason: %s",username, msg);
  29. return nil, msg;
  30. end
  31. end
  32. function provider.get_password(username)
  33. return nil;
  34. end
  35. function provider.set_password(username, password)
  36. return nil, "Set password not supported";
  37. end
  38. function provider.user_exists(username)
  39. return nil;
  40. end
  41. function provider.users()
  42. return next, hosts[module.host].sessions, nil;
  43. end
  44. function provider.create_user(username, password)
  45. return nil;
  46. end
  47. function provider.delete_user(username)
  48. return nil;
  49. end
  50. function provider.get_sasl_handler()
  51. local testpass_authentication_profile = {
  52. plain_test = function(sasl, username, password, realm)
  53. return usermanager.test_password(username, realm, password), true;
  54. end
  55. };
  56. return new_sasl(host, testpass_authentication_profile);
  57. end
  58. module:provides("auth", provider);