# Poco::Net

# class HTTPDigestCredentials

Library: Net
Package: HTTP
Header: Poco/Net/HTTPDigestCredentials.h

## Description

This is a utility class for working with HTTP Digest Authentication in HTTPRequest objects.

Note: currently, no qop or qop=auth is supported only.

## Member Summary

Member Functions: authenticate, clear, createNonce, empty, getPassword, getUsername, isAlgorithmSupported, proxyAuthenticate, reset, setPassword, setUsername, updateAuthInfo, updateProxyAuthInfo, verifyAuthInfo, verifyAuthParams

## Constructors

### HTTPDigestCredentials

HTTPDigestCredentials();

Creates an empty HTTPDigestCredentials object.

### HTTPDigestCredentials

HTTPDigestCredentials(
const std::string & username,
const std::string & password
);

Creates a HTTPDigestCredentials object with the given username and password.

## Destructor

### ~HTTPDigestCredentials

~HTTPDigestCredentials();

Destroys the HTTPDigestCredentials.

## Member Functions

### authenticate

void authenticate(
HTTPRequest & request,
const HTTPResponse & response
);

Parses WWW-Authenticate header of the HTTPResponse, initializes internal state, and adds authentication information to the given HTTPRequest.

### authenticate

void authenticate(
HTTPRequest & request,
const HTTPAuthenticationParams & responseAuthParams
);

Initializes internal state according to information from the HTTPAuthenticationParams of the response, and adds authentication information to the given HTTPRequest.

Throws InvalidArgumentException if HTTPAuthenticationParams is invalid or some required parameter is missing. Throws NotImplementedException in case of unsupported digest algorithm or quality of protection method.

### clear

void clear();

Clears both username and password.

### createNonce

static std::string createNonce();

Creates a random nonce string.

### empty

bool empty() const;

Returns true if both username and password are empty, otherwise false.

### getPassword

const std::string & getPassword() const;

Returns the password.

### getUsername

const std::string & getUsername() const;

Returns the username.

### isAlgorithmSupported

bool isAlgorithmSupported(
const std::string & algorithm
) const;

Check if digest algorithm is supported

### proxyAuthenticate

void proxyAuthenticate(
HTTPRequest & request,
const HTTPResponse & response
);

Parses Proxy-Authenticate header of the HTTPResponse, initializes internal state, and adds proxy authentication information to the given HTTPRequest.

### proxyAuthenticate

void proxyAuthenticate(
HTTPRequest & request,
const HTTPAuthenticationParams & responseAuthParams
);

Initializes internal state according to information from the HTTPAuthenticationParams of the response, and adds proxy authentication information to the given HTTPRequest.

Throws InvalidArgumentException if HTTPAuthenticationParams is invalid or some required parameter is missing. Throws NotImplementedException in case of unsupported digest algorithm or quality of protection method.

### reset

void reset();

Resets the HTTPDigestCredentials object to a clean state. Does not clear username and password.

### setPassword

void setPassword(
const std::string & password
);

Sets the password.

### setUsername

void setUsername(
const std::string & username
);

Sets the username.

### updateAuthInfo

void updateAuthInfo(
HTTPRequest & request
);

Updates internal state and adds authentication information to the given HTTPRequest.

### updateProxyAuthInfo

void updateProxyAuthInfo(
HTTPRequest & request
);

Updates internal state and adds proxy authentication information to the given HTTPRequest.

### verifyAuthInfo

bool verifyAuthInfo(
const HTTPRequest & request
) const;

Verifies the digest authentication information in the given HTTPRequest by recomputing the response and comparing it with what's in the request.

Note: This method creates a HTTPAuthenticationParams object from the request and calls verifyAuthParams() with request and params.

### verifyAuthParams

bool verifyAuthParams(
const HTTPRequest & request,
const HTTPAuthenticationParams & params
) const;

Verifies the digest authentication information in the given HTTPRequest and HTTPAuthenticationParams by recomputing the response and comparing it with what's in the request.

## Variables

### SCHEME

static const std::string SCHEME;