View Source ApiAuth (api_auth v0.4.0)
This is the ApiAuth module.
It provides an HMAC authentication system for APIs.
Summary
Functions
Takes a request header and arguments necessary for validating the Authorization header and returns true if the request is authentic and false otherwise
Takes a keyword list of headers and pulls the client id from the Authorization header returns the {:ok, client_id} or {:error}
Takes a keyword list of headers and arguments necessary for generating the Authorization header and returns an updated keyword list of headers.
Functions
authentic?(request_headers, uri, client_id, secret_key, opts \\ [])
View SourceTakes a request header and arguments necessary for validating the Authorization header and returns true if the request is authentic and false otherwise
Examples
iex> headers = ApiAuth.headers([], "/path", "client_id", "secret_key")
...> ApiAuth.authentic?(headers, "/path", "client_id", "secret_key")
true
iex> headers = ApiAuth.headers([], "/path", "client_id", "secret_key")
...> ApiAuth.authentic?(headers, "/path", "client_id", "hacker")
false
Takes a keyword list of headers and pulls the client id from the Authorization header returns the {:ok, client_id} or {:error}
Examples
iex> headers = [Authorization: "APIAuth-HMAC-SHA256 client_id:v5+Ooq88txd0cFyfSXYn03EFK/NQW9Gepk5YIdkZ4qM="]
...> ApiAuth.client_id(headers)
{:ok, "client_id"}
iex> headers = []
...> ApiAuth.client_id(headers)
:error
Takes a keyword list of headers and arguments necessary for generating the Authorization header and returns an updated keyword list of headers.
Examples
iex> [DATE: "Sat, 01 Jan 2000 00:00:00 GMT", "Content-Type": "application/json"]
...> |> ApiAuth.headers("/path", "client_id", "secret_key",
...> method: "PUT", content: "{\"foo\": \"bar\"}")
[Authorization: "APIAuth-HMAC-SHA256 client_id:v5+Ooq88txd0cFyfSXYn03EFK/NQW9Gepk5YIdkZ4qM=",
"X-APIAuth-Content-Hash": "Qm/ATwS/j9tYMdw3u7bc9w9jo34FpoxupfY+ha5Xk3Y=",
DATE: "Sat, 01 Jan 2000 00:00:00 GMT",
"Content-Type": "application/json"]