Created
June 2, 2019 04:14
-
-
Save iancharters/86014993824f1352bf9381f54e966718 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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