vigest_auth #
fn hash_method_from_str #
fn hash_method_from_str(withValue string) HashMethod
Retrurn a HashMethod enum value from a given string.
Example:
str_hash := "MD5-sess"
enum_hash := hash_method_from_str(str_hash)
fn new_digest_authentification #
fn new_digest_authentification(withUsername string, andPassword string, forFetchConfig http.FetchConfig) ?DigestAuthentification
Return a DigestAuthentification used to fetch from a digest auth protected endpoint Example:
mut config := http.FetchConfig{
url: 'https://httpbin.org/digest-auth/auth/user/pass/MD5'
method: .get
}
mut d_auth := new_digest_authentification('user', 'pass', config) or { return }
fn qop_from_str #
fn qop_from_str(withValue string) Qop
Retrurn a qop enum value from a given string.
Example:
str_qop := "auth"
enum_qop := qop_from_str(str_qop)
enum HashMethod #
enum HashMethod {
md5
md5_sess
sha256
sha256_sess
sha512
sha512_256_sess
unknown
}
Represent a hash method used in digest auth.
fn (HashMethod) str #
fn (h HashMethod) str() string
Return a string which represent a hash method from enum value.
Example:
enum_hash := HashMethod.md5
str_hash := enum_hash.str()
enum Qop #
enum Qop {
auth
auth_int
unknown
}
Respresent a quality of prodtection used in digest auth.
fn (Qop) str #
fn (q Qop) str() string
Return a string which represent a qop from enum value.
Example:
enum_qop := Qup.auth
str_qop := enum_qop.str()
struct DigestAuthentification #
struct DigestAuthentification {
pub mut:
username string
password string
request http.FetchConfig
request_url urllib.URL
qop Qop = .unknown
algorithm HashMethod = .md5
realm string
nonce string
stale bool
opaque string
nc int
cnonce string
}
Main struct which contains data for the requests.
fn (DigestAuthentification) fetch #
fn (mut d DigestAuthentification) fetch() ?http.Response
Fetch from an endpoint which require a digest auth.
Example:
mut config := http.FetchConfig{
url: 'https://httpbin.org/digest-auth/auth/user/pass/MD5'
method: .get
}
mut d_auth := new_digest_authentification('user', 'pass', config) or { return }
mut rsp := d_auth.fetch() or { panic('$err') }