Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
updated readme and implemented custom_auth hook
Browse files Browse the repository at this point in the history
  • Loading branch information
BuckarooBanzay authored and BuckarooBanzay committed Jan 6, 2020
1 parent c9f71ce commit ea867c1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
1 change: 0 additions & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
unused_args = false
allow_defined_top = true

globals = {
Expand Down
7 changes: 6 additions & 1 deletion auth.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ local function auth_handler(auth)
local banned = false
local message = ""

local custom_auth_success, custom_msg = auth_proxy.custom_handler(auth.name)
if not custom_auth_success and custom_msg then
message = custom_msg
end

if auth_proxy.disallow_banned_players and has_xban2_mod then
-- check xban db
local xbanentry = xban.find_entry(auth.name)
Expand All @@ -23,7 +28,7 @@ local function auth_handler(auth)
end
end

if not banned then
if not banned and custom_auth_success then
-- check tan
local tan = auth_proxy.tan[auth.name]
if tan ~= nil then
Expand Down
5 changes: 4 additions & 1 deletion init.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
auth_proxy = {
disallow_banned_players = true,
url = minetest.settings:get("auth_proxy.url"),
tan = {}
tan = {},
custom_handler = function()
return true
end
}


Expand Down
26 changes: 24 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Authorization mod for minetest
=================


To be used with https://github.com/thomasrudin-mt/auth_proxy_app
To be used with https://github.com/minetest-auth-proxy/auth_proxy_app

# Overview

Expand All @@ -12,7 +12,29 @@ Lets third-party apps query username and password of ingame players
# Installing

* Copy/Clone the files into the `worldmods` folder
* Install and start https://github.com/thomasrudin-mt/auth_proxy_app
* Install and start https://github.com/minetest-auth-proxy/auth_proxy_app

# compatibility

If `xban2` is available, the `banned` flag on the xban-database is additionally
checked on login

# API

## Custom auth handler

Additional checks besides the user/password can be implemented with a custom handler function

**Example**: require a priv to login:
```lua
auth_proxy.custom_handler = function(name)
if minetest.check_player_privs(name, "mypriv") then
return true
else
return false, "Missing priv: 'mypriv'"
end
end
```

## minetest.conf

Expand Down
2 changes: 1 addition & 1 deletion util/channel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ local function Channel(http, url, cfg)
extra_headers = post_headers,
timeout = timeout,
post_data = minetest.write_json(data)
}, function(res)
}, function()
-- TODO: error-handling
end)
end
Expand Down

0 comments on commit ea867c1

Please sign in to comment.