util/sasl/external.lua
author Kim Alvefur <zash@zash.se>
Fri, 17 Mar 2023 16:23:16 +0100
changeset 12979 d10957394a3c
parent 8558 4f0f5b49bb03
permissions -rw-r--r--
util: Prefix module imports with prosody namespace

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

local _ENV = nil;
-- luacheck: std none

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;
}