Net.HTTP.Credentials

lib/Net/HTTP/Credentials.gob

What an Authorization header carries (RFC 9110 ยง11.4): a scheme, and the scheme's own data.

field(Authorization, Option.expect(Credentials.bearer(token), "a token68"))

Credentials never show: show gives <credentials> and debug gives <Credentials>, so a request that is printed or logged does not leak them, and the header value they are written as is marked sensitive.

type Credentials

scheme is lowercase, since schemes are case-insensitive. data is the rest of the field after the space that ends the scheme: a token68 or a list of parameters, as the scheme defines.

fun bearer : fun(String) -> Option Credentials

Returns bearer credentials (RFC 6750) for token, which must be a token68: letters, digits and -._~+/, then perhaps some =.

fun basic : fun(String, String) -> Option Credentials

Returns basic credentials (RFC 7617) for a user and password, encoded as UTF-8 and then base64. Returns None if user holds a colon, which would end it early, or either holds a control byte.

fun parse : fun(String) -> Option Credentials

credentials = auth-scheme [ 1*SP ( token68 / #auth-param ) ]

The data after the scheme is checked to be a field value, and is kept as it is; reading it is the scheme's business, as bearerToken and basicPair do.

fun toString : fun(Credentials) -> String

Returns the credentials as they are written in the header.

fun scheme : fun(Credentials) -> String
fun bearerToken : fun(Credentials) -> Option String
fun basicPair : fun(Credentials) -> Option (String, String)

Returns the user and password of basic credentials.

instance Show Credentials