This is an alternative site for discovering Elm packages. You may be looking for the official Elm package site instead.
README

BasicAuth

A helper library for Elm that provides building basic authentication token and header.

Http header

buildAuthorizationHeader : String -> String -> Http.Header

Builds an authorization header based on provided username and password. This can be put directly into the Http.request headers array.

loadAuthenticated : Int -> Cmd Msg
loadAuthenticated id =
    let
        url =
            "https://reqres.in/api/users/" ++ (toString id)

        request =
            Http.request
                { method = "GET"
                , headers =
                    [ buildAuthorizationHeader "username" "password" ]
                , url = url
                , body = Http.emptyBody
                , expect = Http.expectJson userDecoder
                , timeout = Nothing
                , withCredentials = False
                }
    in
        Http.send UserResult request

Just the string token

buildAuthorizationToken : String -> String -> String

Builds just the authorization token based on provided username and password. Use this if you need just the token for some reason. Use buildAuthorizationHeader if you need the header anyway.

module BasicAuth
    exposing
        ( buildAuthorizationHeader
        , buildAuthorizationToken
        )

{-| A helper library for Elm that provides building basic authentication token and header.

# Http header
@docs buildAuthorizationHeader

# Just the string token
@docs buildAuthorizationToken
-}

import Http
import Base64


{-| Builds an authorization header based on provided username and password.
This can be put directly into the Http.request headers array.

    loadAuthenticated : Int -> Cmd Msg
    loadAuthenticated id =
        let
            url =
                "https://reqres.in/api/users/" ++ (toString id)

            request =
                Http.request
                    { method = "GET"
                    , headers =
                        [ buildAuthorizationHeader "username" "password" ]
                    , url = url
                    , body = Http.emptyBody
                    , expect = Http.expectJson userDecoder
                    , timeout = Nothing
                    , withCredentials = False
                    }
        in
            Http.send UserResult request
-}
buildAuthorizationHeader : String -> String -> Http.Header
buildAuthorizationHeader username password =
    Http.header "Authorization" ("Basic " ++ (buildAuthorizationToken username password))


{-| Builds just the authorization token based on provided username and password.
Use this if you need just the token for some reason.
Use buildAuthorizationHeader if you need the header anyway.
-}
buildAuthorizationToken : String -> String -> String
buildAuthorizationToken username password =
    let
        result =
            Base64.encode (username ++ ":" ++ password)
    in
        case result of
            Ok value ->
                value

            Err error ->
                "error: " ++ error