util/sasl/external.lua
author Kim Alvefur <zash@zash.se>
Sat, 21 Feb 2015 10:36:37 +0100
changeset 6780 5de6b93d0190
parent 5687 e879b53e9df8
child 8558 4f0f5b49bb03
permissions -rw-r--r--
util.*: Remove use of module() function, make all module functions local and return them in a table at the end

local saslprep = require "util.encodings".stringprep.saslprep;

local _ENV = nil;

local function external(self, message)
	message = saslprep(message);
	local state
	self.username, state = self.profile.external(message);

	if state == false then
		return "failure", "account-disabled";
	elseif state == nil  then
		return "failure", "not-authorized";
	elseif state == "expired" then
		return "false", "credentials-expired";
	end

	return "success";
end

local function init(registerMechanism)
	registerMechanism("EXTERNAL", {"external"}, external);
end

return {
	init = init;
}