View Source Auth0.Common.Util (Auth0Api v2.5.1)
Documentation for Util.
Summary
Functions
append query to endpoint.
Build a request path by filling the {name} placeholders of an endpoint.
Convert to form body from map. Nil value is removed.
Convert to query from map. Nil value is removed.
Build the optional auth0-custom-domain request header from request options.
Decode json using atom key.
Decode json or String.
Percent-encode a value that is placed into a path segment of an endpoint.
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
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"
Build a request path by filling the {name} placeholders of an endpoint.
Each value is encoded with encode_path_param/1 and the placeholders are
replaced in the order the parameters are given. The keys are the placeholder
names exactly as they appear in the endpoint (e.g. versionId: for
{versionId}).
Examples
iex> Auth0.Common.Util.build_path("/api/v2/users/{id}", id: "auth0|123")
"/api/v2/users/auth0%7C123"
iex> Auth0.Common.Util.build_path("/api/v2/users/{id}/roles/{role_id}", id: "a/b", role_id: "rol_1")
"/api/v2/users/a%2Fb/roles/rol_1"
iex> Auth0.Common.Util.build_path("/api/v2/actions/modules/{id}/versions/{versionId}", id: "mod 1", versionId: "v|1")
"/api/v2/actions/modules/mod%201/versions/v%7C1"
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"]}
Convert to query from map. Nil value is removed.
A list value is sent as repeated keys (OpenAPI style: form, explode: true),
which is how the Auth0 Management API expects array query parameters.
nil elements inside a list are removed as well.
Examples
iex> Auth0.Common.Util.convert_to_query(%{a: 1, b: nil, c: 3, d: "erin the black"})
"a=1&c=3&d=erin%20the%20black"
iex> Auth0.Common.Util.convert_to_query(%{strategy: ["auth0", "google-oauth2"]})
"strategy=auth0&strategy=google-oauth2"
Build the optional auth0-custom-domain request header from request options.
Auth0 uses the header to pick the custom domain for links in emails and tickets. Only a host name (optionally with a port) is accepted, so a value can never inject further headers.
Examples
iex> Auth0.Common.Util.custom_domain_headers([])
%{}
iex> Auth0.Common.Util.custom_domain_headers(custom_domain: "login.example.com")
%{"auth0-custom-domain" => "login.example.com"}
Decode json using atom key.
Decode json or String.
Percent-encode a value that is placed into a path segment of an endpoint.
Every character except the RFC 3986 unreserved characters
(A-Z a-z 0-9 - . _ ~) is encoded, so a value can never add path segments,
a query string or a fragment to the request. The dot segments . and ..
are encoded as well so that they cannot be normalized away.
Examples
iex> Auth0.Common.Util.encode_path_param("auth0|123")
"auth0%7C123"
iex> Auth0.Common.Util.encode_path_param("a/b?c#d")
"a%2Fb%3Fc%23d"
iex> Auth0.Common.Util.encode_path_param("..")
"%2E%2E"
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>>
Encode to Base 16 value with lower case.
Examples
iex> Auth0.Common.Util.hex_encode("erin")
"6572696e"
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>>
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}
Convert struct to map recursively.
Convert map to struct and string keys are considered.
@spec uuid() :: String.t()
Generate UUID4 value.