diff mod_auth_token/mod_auth_token.lua @ 3693:0fb12a4b6106

auth_token: Various updates, see below. * Defer to usermanager when testing the password * Because of this, don't assume the realm is available when verifying the token * Fix linting errors By using the `usermanager`, other modules can now ask the user manager to verify token credentials.
author JC Brand <jc@opkode.com>
date Thu, 03 Oct 2019 12:13:44 +0200
parents d0ca211e1b0e
children
line wrap: on
line diff
--- a/mod_auth_token/mod_auth_token.lua	Mon Sep 30 00:51:05 2019 +0200
+++ b/mod_auth_token/mod_auth_token.lua	Thu Oct 03 12:13:44 2019 +0200
@@ -6,17 +6,17 @@
 local host = module.host;
 local log = module._log;
 local new_sasl = require "util.sasl".new;
+local usermanager = require "core.usermanager";
 local verify_token = module:require "token_auth_utils".verify_token;
 
 local provider = {};
 
 
-function provider.test_password(username, password, realm)
+function provider.test_password(username, password)
 	log("debug", "Testing signed OTP for user %s at host %s", username, host);
 	return verify_token(
 		username,
 		password,
-		realm,
 		module:get_option_string("otp_seed"),
 		module:get_option_string("token_secret"),
 		log
@@ -50,7 +50,7 @@
 	supported_mechanisms["X-TOKEN"] = true;
 	return new_sasl(host, {
 		token = function(sasl, username, password, realm)
-			return provider.test_password(username, password, realm), true;
+			return usermanager.test_password(username, realm, password), true;
 		end,
         mechanisms = supported_mechanisms
 	});