Skip to content

Instantly share code, notes, and snippets.

@facsiaginsa
Last active June 1, 2023 23:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save facsiaginsa/843e4f45ba5d5bec6a737cfe266e49a1 to your computer and use it in GitHub Desktop.
Save facsiaginsa/843e4f45ba5d5bec6a737cfe266e49a1 to your computer and use it in GitHub Desktop.
This guide is to show you how to use mod_auth_custom_http in prosody.

How to use mod_auth_custom_http in Prosody

This guide is to show you how to use mod_auth_custom_http in prosody.

Download extension

You can download the latest version of the module here: https://hg.prosody.im/prosody-modules/file/32d7f05e062f/mod_auth_custom_http/mod_auth_custom_http.lua Place the module in /usr/lib/prosody/modules/

Edit Module

Change this one line (local postdata) on module mod_auth_custom_http.lua

local getpass_authentication_profile = {
	plain_test = function(sasl, username, password, realm)
		--local postdata = json.encode({ username = username, password = password });
		local postdata = "username="..username.."&password="..password;
		local result = http.request(post_url, postdata);
		return result == "true", true;
	end,
	};
        return new_sasl(module.host, getpass_authentication_profile);
end

This module is not sending application/json header, but application/x-www-form-urlencoded. So your api should be ready to handle that request. There are 2 parameter inside the api request that is 'username' & 'password'.

Edit Your Prosody Config FIle

nano /etc/prosody/conf.d/<domain>.cfg.lua

Add / Edit some line here:

consider_bosh_secure = true
consider_websocket_secure = true

VirtualHost "<your.domain.com>"
        authentication = "custom_http"
        auth_custom_http = { post_url = "http://<the api url>"; }

Important! This prosody module doesn't support https post_url.

Done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment