2024-11-25 13:07:42 +01:00
|
|
|
defmodule Ejabberd.Auth.Example do
|
|
|
|
|
2024-11-22 08:30:55 +01:00
|
|
|
@moduledoc """
|
2024-11-25 13:07:42 +01:00
|
|
|
Example ejabberd auth method written in Elixir.
|
2024-11-22 08:30:55 +01:00
|
|
|
|
2024-11-25 13:07:42 +01:00
|
|
|
This is an example to demonstrate the usage of Elixir to
|
|
|
|
create ejabberd auth methods.
|
2024-11-22 08:30:55 +01:00
|
|
|
|
2024-11-25 13:07:42 +01:00
|
|
|
Example configuration:
|
|
|
|
auth_method: 'Ejabberd.Auth.Example'
|
2024-11-22 08:30:55 +01:00
|
|
|
"""
|
2024-11-25 13:07:42 +01:00
|
|
|
|
2024-11-22 08:30:55 +01:00
|
|
|
@behaviour :ejabberd_auth
|
2024-11-25 13:07:42 +01:00
|
|
|
import Ejabberd.Logger
|
2024-11-22 08:30:55 +01:00
|
|
|
|
|
|
|
@impl true
|
|
|
|
def start(host) do
|
2024-11-25 13:07:42 +01:00
|
|
|
info("Starting Ejabberd.Auth.Example to authenticate '#{host}' users")
|
2024-11-22 08:30:55 +01:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def stop(host) do
|
2024-11-25 13:07:42 +01:00
|
|
|
info("Stopping Ejabberd.Auth.Example to authenticate '#{host}' users")
|
2024-11-22 08:30:55 +01:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def check_password("alice", _authz_id, _host, "secret"), do: {:nocache, true}
|
|
|
|
def check_password(_username, _authz_id, _host, _secret), do: {:nocache, false}
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def user_exists("alice", _host), do: {:nocache, true}
|
|
|
|
def user_exists(_username, _host), do: {:nocache, false}
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def plain_password_required(_binary), do: true
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def store_type(_host), do: :external
|
|
|
|
|
|
|
|
@impl true
|
|
|
|
def use_cache(_host), do: false
|
|
|
|
end
|