View Source Auth0.Common.Util (Auth0Api v2.2.0)

Documentation for Util.

Summary

Functions

append query to endpoint.

Convert to form body from map. Nil value is removed.

Convert to query from map. Nil value is removed.

Decode json using atom key.

Decode json or String.

Generate SHA256 hash value.

Encode to Base 16 value with lower case.

Generate HMAC-SHA256 hash value.

Remove nil value from map recursively.

Convert struct to map recursively.

Convert map to struct and string keys are considered.

Generate UUID4 value.

Functions

Link to this function

append_query(query, endpoint)

View Source
@spec append_query(String.t(), String.t()) :: String.t()

append query to endpoint.

Examples

iex> Auth0.Common.Util.append_query("a=1&c=3&d=erin%20the%20black", "/hoge/fuga")
"/hoge/fuga?a=1&c=3&d=erin%20the%20black"
Link to this function

convert_to_form_body(map)

View Source
@spec convert_to_form_body(map()) :: {:form, keyword()}

Convert to form body from map. Nil value is removed.

Examples

iex> Auth0.Common.Util.encode_form_body(%{a: 1, b: nil, c: 3, d: "erin the black"})
{:form, [a: 1, b: nil, c: 3, d: "erin the black"]}
@spec convert_to_query(map()) :: String.t()

Convert to query from map. Nil value is removed.

Examples

iex> Auth0.Common.Util.encode_query(%{a: 1, b: nil, c: 3, d: "erin the black"})
"a=1&c=3&d=erin%20the%20black"
@spec decode_json!(String.t()) :: map() | list()

Decode json using atom key.

Link to this function

decode_json_or_string!(value)

View Source
@spec decode_json_or_string!(String.t()) :: map() | String.t()

Decode json or String.

@spec hash(String.t()) :: binary()

Generate SHA256 hash value.

Examples

iex> Auth0.Common.Util.hash("erin")
<<124, 188, 203, 12, 76, 170, 223, 159, 205, 181, 30, 228, 87, 168, 40, 204,
  114, 164, 88, 121, 131, 27, 91, 151, 138, 226, 226, 206, 252, 68, 151, 5>>
@spec hex_encode(String.t()) :: String.t()

Encode to Base 16 value with lower case.

Examples

iex> Auth0.Common.Util.hex_encode("erin")
"6572696e"
@spec hmac(String.t(), String.t()) :: binary()

Generate HMAC-SHA256 hash value.

Examples

iex> Auth0.Common.Util.hmac("secret", "erin")
<<66, 116, 70, 47, 123, 250, 150, 31, 51, 11, 16, 118, 149, 254, 106, 254, 89,
  65, 153, 52, 185, 191, 44, 50, 250, 254, 55, 172, 101, 31, 249, 250>>
@spec remove_nil(map()) :: map()

Remove nil value from map recursively.

Examples

iex> Auth0.Common.Util.remove_nil(%{a: 1, b: nil, c: 3})
%{a: 1, c: 3}

iex> Auth0.Common.Util.remove_nil(%{:a => 1, :b => nil, :c => 3, "d" => nil, "f" => 5})
%{:a => 1, :c => 3, "f" => 5}
@spec to_map(struct()) :: map()

Convert struct to map recursively.

@spec to_struct(map(), module()) :: struct()

Convert map to struct and string keys are considered.

@spec uuid() :: String.t()

Generate UUID4 value.