feat(api): optional auth for public search and studio week. Refs EventHub/EventHubFront#58
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
-export([
|
||||
auth_admin/1,
|
||||
auth_user/1,
|
||||
auth_user_optional/1,
|
||||
send_json/3,
|
||||
send_json/4,
|
||||
send_error/3,
|
||||
@@ -75,6 +76,17 @@ is_superadmin(Req) ->
|
||||
auth_user(Req) ->
|
||||
handler_auth:authenticate(Req).
|
||||
|
||||
%% @doc Как auth_user/1, но без заголовка Authorization — гость (`<<>>`).
|
||||
%% Невалидный Bearer по-прежнему 401.
|
||||
-spec auth_user_optional(cowboy_req:req()) ->
|
||||
{ok, binary(), cowboy_req:req()} | {error, integer(), binary(), cowboy_req:req()}.
|
||||
auth_user_optional(Req) ->
|
||||
case cowboy_req:header(<<"authorization">>, Req) of
|
||||
undefined -> {ok, <<>>, Req};
|
||||
<<>> -> {ok, <<>>, Req};
|
||||
_ -> auth_user(Req)
|
||||
end.
|
||||
|
||||
%%%===================================================================
|
||||
%%% HTTP‑ответы
|
||||
%%%===================================================================
|
||||
|
||||
Reference in New Issue
Block a user