Lather.Auth.Basic (lather v1.0.42)

View Source

HTTP 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

decode(arg1)

@spec decode(String.t()) :: {:ok, {String.t(), String.t()}} | {:error, atom()}

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}

header(username, password)

@spec header(String.t(), String.t()) :: {String.t(), String.t()}

Creates an HTTP Basic authentication header.

Parameters

  • username - The username for authentication
  • password - The password for authentication

Examples

iex> Lather.Auth.Basic.header("admin", "password")
{"Authorization", "Basic YWRtaW46cGFzc3dvcmQ="}

header_value(username, password)

@spec header_value(String.t(), String.t()) :: String.t()

Creates an HTTP Basic authentication header value only.

Parameters

  • username - The username for authentication
  • password - The password for authentication

Examples

iex> Lather.Auth.Basic.header_value("admin", "password")
"Basic YWRtaW46cGFzc3dvcmQ="

validate(header_value, validator)

@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 value
  • validator - 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}