Skip to content

Commit

Permalink
Test student saml config
Browse files Browse the repository at this point in the history
  • Loading branch information
chownces committed May 10, 2024
1 parent 82bfbfa commit bbd9923
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/cadet/auth/providers/simplesaml.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,22 @@ defmodule Cadet.Auth.Providers.SimpleSAML do
def authorise(config, conn, _client_id, _redirect_uri) do
# Logger.debug("test")
assertion = Samly.get_active_assertion(conn)
IO.inspect(assertion)
IO.inspect(assertion.attributes)
# Logger.debug("assertion: #{inspect(assertion)}")
expected_id = config.idp_id

case get_assertion_idp_id(assertion) do
nil ->
{:error, :invalid_credentials, "Missing SAML assertion"}
{:error, :invalid_credentials, "Missing SAML assertion!"}

^expected_id ->
{:ok, %{token: "testtoken", username: "testuser"}}
# TODO: Add a assertion extractor to get the different fields
{:ok,
%{
token: Map.get(assertion.attributes, "displayname"),
username: Map.get(assertion.attributes, "samaccountname")
}}

_ ->
{:error, :bad_request, "Invalid authentication provider"}
Expand All @@ -39,12 +46,12 @@ defmodule Cadet.Auth.Providers.SimpleSAML do

@spec get_name(any(), Provider.token()) ::
{:ok, String.t()} | {:error, Provider.error(), String.t()}
def get_name(_config, _token) do
def get_name(_config, token_as_name) do
# case Enum.find(config, nil, fn %{token: this_token} -> token == this_token end) do
# %{name: name} -> {:ok, name}
# _ -> {:error, :invalid_credentials, "Invalid token"}
# end
{:ok, "testuser"}
{:ok, token_as_name}
end

defp get_assertion_idp_id(%Assertion{idp_id: idp_id}), do: idp_id
Expand Down

0 comments on commit bbd9923

Please sign in to comment.