aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Bracco <href@random.sh>2021-09-03 18:07:09 +0200
committerJordan Bracco <href@random.sh>2021-09-03 18:07:09 +0200
commita808f89428daa2e90ceb7a9876a317e4e85fe5bf (patch)
tree7d1c143488180f7ae4d2eae3a0ad2aa92a5adfbf
parentMove `assets/` to `apps/styx_web/assets` (diff)
various small fixes
-rw-r--r--apps/ory/src/ory_hydra.erl6
-rw-r--r--apps/ory/src/ory_kratos.erl2
-rw-r--r--apps/styx_web/src/styx_web.erl2
-rw-r--r--apps/styx_web/src/styx_web_error.erl3
-rw-r--r--apps/styx_web/src/styx_web_kratos_flow.erl2
-rw-r--r--apps/styx_web/src/styx_web_oauth2_consent.erl18
-rw-r--r--apps/styx_web/src/styx_web_oauth2_login.erl6
7 files changed, 19 insertions, 20 deletions
diff --git a/apps/ory/src/ory_hydra.erl b/apps/ory/src/ory_hydra.erl
index e667487..8902c98 100644
--- a/apps/ory/src/ory_hydra.erl
+++ b/apps/ory/src/ory_hydra.erl
@@ -4,7 +4,7 @@
login_request(Challenge) ->
Url = [admin_url(), "/oauth2/auth/requests/login?login_challenge=", Challenge],
Headers = [{"accept", "application/json"}],
- api_response(hackney:request(get, Url, [], <<>>, [])).
+ api_response(hackney:request(get, Url, Headers, <<>>, [])).
accept_login_request(Challenge, Data) ->
Url = [admin_url(), "/oauth2/auth/requests/login/accept?login_challenge=", Challenge],
@@ -15,7 +15,7 @@ accept_login_request(Challenge, Data) ->
consent_request(Challenge) ->
Url = [admin_url(), "/oauth2/auth/requests/consent?consent_challenge=", Challenge],
Headers = [{"accept", "application/json"}],
- api_response(hackney:request(get, Url, [], <<>>, [])).
+ api_response(hackney:request(get, Url, Headers, <<>>, [])).
accept_consent_request(Challenge, Data) ->
Url = [admin_url(), "/oauth2/auth/requests/consent/accept?consent_challenge=", Challenge],
@@ -44,7 +44,7 @@ api_response(Error = {error, Error}) ->
api_response({ok, 200, _, Client}) ->
{ok, Body} = hackney:body(Client),
{ok, jsone:decode(Body)};
-api_response({ok, Code, _, Client}) ->
+api_response({ok, _Code, _, Client}) ->
{ok, Body} = hackney:body(Client),
JSON = #{<<"error">> := Error} = jsone:decode(Body),
logger:debug("hydra error: ~p", [JSON]),
diff --git a/apps/ory/src/ory_kratos.erl b/apps/ory/src/ory_kratos.erl
index 14afa82..02a85a0 100644
--- a/apps/ory/src/ory_kratos.erl
+++ b/apps/ory/src/ory_kratos.erl
@@ -69,7 +69,7 @@ api_response(Error = {error, Error}) ->
api_response({ok, 200, _, Client}) ->
{ok, Body} = hackney:body(Client),
{ok, jsone:decode(Body)};
-api_response({ok, Code, _, Client}) ->
+api_response({ok, _Code, _, Client}) ->
{ok, Body} = hackney:body(Client),
JSON = #{<<"error">> := Error} = jsone:decode(Body),
logger:debug("hydra error: ~p", [JSON]),
diff --git a/apps/styx_web/src/styx_web.erl b/apps/styx_web/src/styx_web.erl
index cf565bd..123dc7b 100644
--- a/apps/styx_web/src/styx_web.erl
+++ b/apps/styx_web/src/styx_web.erl
@@ -52,7 +52,7 @@ req_param(Req, Param) ->
{error, {missing_param, Param}}
end.
-render_node([#{<<"attributes">> := Attrs = #{<<"name">> := AttrName, <<"type">> := AttrType}, <<"type">> := <<"input">>, <<"messages">> := Msgs, <<"meta">> := Meta} | Rest], Acc) ->
+render_node([#{<<"attributes">> := Attrs = #{<<"name">> := AttrName, <<"type">> := AttrType}, <<"type">> := <<"input">>, <<"messages">> := _Msgs, <<"meta">> := Meta} | Rest], Acc) ->
Assigns0 = [{"input_name", AttrName},
{"input_type", AttrType},
{"input_value", maps:get(<<"value">>, Attrs, undefined)},
diff --git a/apps/styx_web/src/styx_web_error.erl b/apps/styx_web/src/styx_web_error.erl
index 262bedc..1ef0be0 100644
--- a/apps/styx_web/src/styx_web_error.erl
+++ b/apps/styx_web/src/styx_web_error.erl
@@ -9,9 +9,8 @@ init(Req, State = #{code := Code, status := Status}) ->
init(Req, oauth2) ->
{ok, ErrorDescription} = styx_web:req_param(Req, <<"error_description">>),
reply(Req, 500, <<"Error">>, ErrorDescription);
-init(Req = #{method := <<"GET">>}, State) ->
+init(Req = #{method := <<"GET">>}, _) ->
{ok, ErrorId} = styx_web:req_param(Req, <<"id">>),
- {ok, Error} = ory_kratos:error(ErrorId),
{ok, #{<<"error">> := #{<<"status">> := Status, <<"code">> := Code, <<"message">> := Msg}}} = ory_kratos:error(ErrorId),
reply(Req, Code, Status, Msg).
diff --git a/apps/styx_web/src/styx_web_kratos_flow.erl b/apps/styx_web/src/styx_web_kratos_flow.erl
index c889794..edcf421 100644
--- a/apps/styx_web/src/styx_web_kratos_flow.erl
+++ b/apps/styx_web/src/styx_web_kratos_flow.erl
@@ -21,5 +21,5 @@ get_(Req0, State = #{page_title := PageTitle, template := Template}, {ok, Flow =
Html = styx_web:render(Req0, Template, Assigns),
Req = styx_web:reply_html(Req0, 200, Html),
{ok, Req, State};
-get_(Req, State, {error, Error = #{<<"code">> := Code, <<"status">> := Status, <<"message">> := Msg}}) ->
+get_(Req, _State, {error, Error = #{<<"code">> := Code, <<"status">> := Status, <<"message">> := Msg}}) ->
styx_web_error:init(Req, #{code => Code, status => Status, message => maps:get(<<"reason">>, Error, Msg)}).
diff --git a/apps/styx_web/src/styx_web_oauth2_consent.erl b/apps/styx_web/src/styx_web_oauth2_consent.erl
index c9f57be..26da05a 100644
--- a/apps/styx_web/src/styx_web_oauth2_consent.erl
+++ b/apps/styx_web/src/styx_web_oauth2_consent.erl
@@ -18,19 +18,19 @@ init_(Req, _, {error, {missing_param, _}}) ->
authentication(Req0, State, Challenge, {ok, Session = #{<<"active">> := true}}) ->
do(Req0, State, Session, ory_hydra:consent_request(Challenge));
-authentication(Req0, State, _, Error) ->
- error(Req0, State, Error).
+authentication(Req0, State, _Challenge, Error) ->
+ render_error(Req0, State, Error).
-do(Req0 = #{method := <<"GET">>}, State, Session, {ok, Flow = #{<<"skip">> := true, <<"requested_scope">> := Scopes}}) ->
+do(Req0 = #{method := <<"GET">>}, State, _Session, {ok, #{<<"challenge">> := Challenge, <<"skip">> := true, <<"requested_scope">> := Scopes}}) ->
ConsentData = #{<<"grant_scope">> => Scopes},
case ory_hydra:accept_consent_request(Challenge, ConsentData) of
{ok, #{<<"redirect_to">> := Url}} ->
Req = styx_web:temporary_redirect(Req0, Url),
{ok, Req, State};
Error ->
- error(Req0, State, Error)
+ render_error(Req0, State, Error)
end;
-do(Req0 = #{method := <<"GET">>}, State, Session, {ok, Flow = #{<<"client">> := Client}}) ->
+do(Req0 = #{method := <<"GET">>}, State, _Session, {ok, Flow = #{<<"client">> := Client}}) ->
%% FIXME client_name can be blank, not just undefined.
logger:debug("oAuth request ~p", [Flow]),
AppName = maps:get(<<"client_name">>, Client, maps:get(<<"client_id">>, Client, <<"Unnamed App">>)),
@@ -62,18 +62,18 @@ consent(Req0, State, _Session, #{<<"challenge">> := Challenge}, Data, true) ->
Req = styx_web:temporary_redirect(Req0, Url),
{ok, Req, State};
Error ->
- error(Req0, State, Error)
+ render_error(Req0, State, Error)
end;
-consent(Req0, State, _Session, #{<<"challenge">> := Challenge}, _, false) ->
+consent(Req0, State, _Session, #{<<"challenge">> := Challenge}, _Data, false) ->
Data = #{<<"error">> => <<"User denied access.">>, <<"status_code">> => 403},
case ory_hydra:reject_consent_request(Challenge, Data) of
{ok, #{<<"redirect_to">> := Url}} ->
Req = styx_web:temporary_redirect(Req0, Url),
{ok, Req, State};
Error ->
- error(Req0, State, Error)
+ render_error(Req0, State, Error)
end.
-error(Req, State, {error, Error = #{<<"code">> := Code, <<"status">> := Status, <<"message">> := Msg}}) ->
+render_error(Req, _State, {error, #{<<"code">> := Code, <<"status">> := Status, <<"message">> := Msg}}) ->
styx_web_error:init(Req, #{code => Code, status => Status, message => Msg}).
diff --git a/apps/styx_web/src/styx_web_oauth2_login.erl b/apps/styx_web/src/styx_web_oauth2_login.erl
index 2413f2d..ef6ea20 100644
--- a/apps/styx_web/src/styx_web_oauth2_login.erl
+++ b/apps/styx_web/src/styx_web_oauth2_login.erl
@@ -28,9 +28,9 @@ get(Req0, State, {ok, Challenge}) ->
logger:debug("Got challenge for auth req ~p", [Request]),
authenticate(Req, State, Request);
{error, Error = #{<<"code">> := Code, <<"status">> := Status, <<"message">> := Msg}} ->
- styx_web_error:init(Req0, #{code => Code, status => status, message => maps:get(<<"reason">>, Error, Msg)})
+ styx_web_error:init(Req0, #{code => Code, status => Status, message => maps:get(<<"reason">>, Error, Msg)})
end;
-get(Req, State, {error, {missing_param, _}}) ->
+get(Req, _State, {error, {missing_param, _}}) ->
styx_web_error:init(Req, not_found).
authenticate(Req, State, Request) ->
@@ -50,7 +50,7 @@ challenge(Req0, State, #{<<"challenge">> := Challenge}, undefined) ->
{ok, Req, State};
%% XXX: What's the point of loggin in the user again?
%%challenge(Req, State, Request = #{<<"skip">> := false}, Session) ->
-challenge(Req0, State, Request = #{<<"challenge">> := Challenge}, Session = #{<<"active">> := true, <<"identity">> := #{<<"id">> := Id, <<"traits">> := Traits}}) ->
+challenge(Req0, State, #{<<"challenge">> := Challenge}, #{<<"active">> := true, <<"identity">> := #{<<"id">> := Id, <<"traits">> := Traits}}) ->
Data = #{<<"subject">> => Id, <<"remember">> => true, <<"remember_for">> => ?REMEMBER_MAX_AGE, <<"context">> => Traits},
case ory_hydra:accept_login_request(Challenge, Data) of
{ok, #{<<"redirect_to">> := Redirect}} ->