Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove use of http_uri:encode #6

Merged
merged 1 commit into from
Jan 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/esaml_binding.erl
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,20 @@ decode_response(_, SAMLResponse) ->
encode_http_redirect(IdpTarget, SignedXml, Username, RelayState) ->
Type = xml_payload_type(SignedXml),
Req = lists:flatten(xmerl:export([SignedXml], xmerl_xml)),
% TODO: unsure how to manage Param since no uri_string function can perform the required percent-encoding
Param = http_uri:encode(base64:encode_to_string(zlib:zip(Req))),
RelayStateEsc = uri_string:normalize(binary_to_list(RelayState)),

QueryList = [
{"SAMLEncoding", ?deflate},
{Type, uri_string:quote(base64:encode_to_string(zlib:zip(Req)))},
{"RelayState", uri_string:normalize(binary_to_list(RelayState))}
],
QueryParamStr = uri_string:compose_query(QueryList),
FirstParamDelimiter = case lists:member($?, IdpTarget) of true -> "&"; false -> "?" end,
Username_Part = redirect_username_part(Username),
iolist_to_binary([IdpTarget, FirstParamDelimiter, "SAMLEncoding=", ?deflate, "&", Type, "=", Param, "&RelayState=", RelayStateEsc | Username_Part]).

iolist_to_binary([IdpTarget, FirstParamDelimiter, QueryParamStr | Username_Part]).

redirect_username_part(Username) when is_binary(Username), size(Username) > 0 ->
["&username=", uri_string:normalize(binary_to_list(Username))];
["&", uri_string:compose_query([{"username", uri_string:normalize(binary_to_list(Username))}])];
redirect_username_part(_Other) -> [].

%% @doc Encode a SAMLRequest (or SAMLResponse) as an HTTP-POST binding
Expand Down