import qualified Data.Text.Encoding as B
import qualified Data.ByteString as C


basicCredentials :: ByteString -> Either Text (Text, Text)
basicCredentials =
  dropPrefix >=> decodeBase64 >=> decodeText >=> splitText
  where
    dropPrefix =
      maybe (Left "Not a basic authorization") Right .
      C.stripPrefix "Basic "
    decodeBase64 =
      first adaptFailure .
      A.decode
      where