Skip to content

Instantly share code, notes, and snippets.

@iancharters
Created June 2, 2019 04:14
Show Gist options
  • Save iancharters/86014993824f1352bf9381f54e966718 to your computer and use it in GitHub Desktop.
Save iancharters/86014993824f1352bf9381f54e966718 to your computer and use it in GitHub Desktop.
def verify_state_input(fields) do
required_fields = [:client_id, :provider, :redirect_uri, :sub]
# Determine which keys are missing from the state input and add it to our
# errors so that we can return exactly what we're missing to the client
field_errors =
required_fields
|> Enum.reduce(%{}, fn required_key, acc ->
has_key? =
Enum.any?(fields, fn {input_key, _v} ->
required_key == input_key
end)
if has_key?, do: acc, else: Map.put(acc, required_key, "Required field.")
end)
{:error,
%MalformedInputError{
fields: field_errors,
message:
"Invalid state parameters. You must provide `client_id`, `provider`, `redirect_uri` and `sub`"
}}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment