Lather.Auth.Basic (lather v1.0.42)
View SourceHTTP Basic authentication for SOAP services.
This module provides utilities for HTTP Basic authentication, which can be used in HTTP headers for SOAP requests.
Summary
Functions
Decodes an HTTP Basic authentication header.
Creates an HTTP Basic authentication header.
Creates an HTTP Basic authentication header value only.
Validates Basic authentication credentials against a validation function.
Functions
Decodes an HTTP Basic authentication header.
Parameters
header_value- The Basic authentication header value
Examples
iex> Lather.Auth.Basic.decode("Basic YWRtaW46cGFzc3dvcmQ=")
{:ok, {"admin", "password"}}
iex> Lather.Auth.Basic.decode("Invalid")
{:error, :invalid_format}
Creates an HTTP Basic authentication header.
Parameters
username- The username for authenticationpassword- The password for authentication
Examples
iex> Lather.Auth.Basic.header("admin", "password")
{"Authorization", "Basic YWRtaW46cGFzc3dvcmQ="}
Creates an HTTP Basic authentication header value only.
Parameters
username- The username for authenticationpassword- The password for authentication
Examples
iex> Lather.Auth.Basic.header_value("admin", "password")
"Basic YWRtaW46cGFzc3dvcmQ="
@spec validate(String.t(), (String.t(), String.t() -> boolean())) :: {:ok, {String.t(), String.t()}} | {:error, atom()}
Validates Basic authentication credentials against a validation function.
Parameters
header_value- The Basic authentication header valuevalidator- A function that takes username and password and returns boolean
Examples
iex> validator = fn "admin", "password" -> true; _, _ -> false end
iex> Lather.Auth.Basic.validate("Basic YWRtaW46cGFzc3dvcmQ=", validator)
{:ok, {"admin", "password"}}
iex> Lather.Auth.Basic.validate("Basic d3Jvbmc6d3Jvbmc=", validator)
{:error, :invalid_credentials}