Skip to content

Instantly share code, notes, and snippets.

@rpip
Last active August 29, 2015 13:59
Show Gist options
  • Save rpip/10604477 to your computer and use it in GitHub Desktop.
Save rpip/10604477 to your computer and use it in GitHub Desktop.
Expose Zotonic authentication via a REST API service. This example is built for use with phpBB authentication as documented here: https://wiki.phpbb.com/Authentication_plugins
-module(service_phpbb_auth).
-svc_title("External Zotonic Authentication service").
%% You can change this to restrict access
-svc_needauth(false).
-export([process_get/2]).
-include_lib("zotonic.hrl").
process_get(_ReqData, Ctx) ->
Username = z_context:get_q("username",Context),
Password = z_context:get_q("password",Context),
Response = case z_auth:logon_pw(Username, Password, Ctx) of
{context, _Ctx1} ->
{success, true};
{false, _Ctx2} ->
{success, false}
end,
z_convert:to_json(Response).
@rpip
Copy link
Author

rpip commented Apr 13, 2014

Place this script in the services folder in the module or site and access it at http://localhost:8000/api/phpbb/auth

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