# Authenticator

<a id="authenticator"></a>

# Authenticator

```cpp
#include <icy/http/authenticator.h>

class Authenticator
```

[Defined in src/http/include/icy/http/authenticator.h:32](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/authenticator.h#L32)

Maintains HTTP Basic or Digest authentication state for outbound requests.

Note: Do not forget to read the entire response stream from the 401 response before sending the authenticated request, otherwise there may be problems if a persistent connection is used.

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`Authenticator`](#authenticator-1)  | Creates an empty authenticator. |
|  | [`Authenticator`](#authenticator-2)  | Creates an authenticator with the given username and password. |
|  | [`~Authenticator`](#authenticator-3)  | Destroys the authenticator. |
| `void` | [`fromUserInfo`](#fromuserinfo)  | Parses username:password std::string and sets username and password of the credentials object. Throws SyntaxException on invalid user information. |
| `void` | [`fromURI`](#fromuri)  | Extracts username and password from the given URI and sets username and password of the credentials object. Does nothing if URI has no user info part. |
| `void` | [`setUsername`](#setusername)  | Sets the username. |
| `const std::string &` | [`username`](#username) `const` | Returns the username. |
| `void` | [`setPassword`](#setpassword)  | Sets the password. |
| `const std::string &` | [`password`](#password) `const` | Returns the password. |
| `void` | [`authenticate`](#authenticate)  | Inspects WWW-Authenticate header of the response, initializes the internal state (in case of digest authentication) and adds required information to the given http::Request. |
| `void` | [`updateAuthInfo`](#updateauthinfo)  | Updates internal state (in case of digest authentication) and replaces authentication information in the request accordingly. |
| `void` | [`proxyAuthenticate`](#proxyauthenticate)  | Inspects Proxy-Authenticate header of the response, initializes the internal state (in case of digest authentication) and adds required information to the given http::Request. |
| `void` | [`updateProxyAuthInfo`](#updateproxyauthinfo)  | Updates internal state (in case of digest authentication) and replaces proxy authentication information in the request accordingly. |

---

<a id="authenticator-1"></a>

### Authenticator

```cpp
Authenticator()
```

[Defined in src/http/include/icy/http/authenticator.h:36](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/authenticator.h#L36)

Creates an empty authenticator.

---

<a id="authenticator-2"></a>

### Authenticator

```cpp
Authenticator(const std::string & username, const std::string & password)
```

[Defined in src/http/include/icy/http/authenticator.h:39](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/authenticator.h#L39)

Creates an authenticator with the given username and password.

---

<a id="authenticator-3"></a>

### ~Authenticator

```cpp
~Authenticator()
```

[Defined in src/http/include/icy/http/authenticator.h:42](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/authenticator.h#L42)

Destroys the authenticator.

---

<a id="fromuserinfo"></a>

### fromUserInfo

```cpp
void fromUserInfo(std::string_view userInfo)
```

[Defined in src/http/include/icy/http/authenticator.h:47](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/authenticator.h#L47)

Parses username:password std::string and sets username and password of the credentials object. Throws SyntaxException on invalid user information.

---

<a id="fromuri"></a>

### fromURI

```cpp
void fromURI(const http::URL & uri)
```

[Defined in src/http/include/icy/http/authenticator.h:52](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/authenticator.h#L52)

Extracts username and password from the given URI and sets username and password of the credentials object. Does nothing if URI has no user info part.

---

<a id="setusername"></a>

### setUsername

```cpp
void setUsername(const std::string & username)
```

[Defined in src/http/include/icy/http/authenticator.h:55](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/authenticator.h#L55)

Sets the username.

---

<a id="username"></a>

### username

`const`

```cpp
const std::string & username() const
```

[Defined in src/http/include/icy/http/authenticator.h:58](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/authenticator.h#L58)

Returns the username.

---

<a id="setpassword"></a>

### setPassword

```cpp
void setPassword(const std::string & password)
```

[Defined in src/http/include/icy/http/authenticator.h:61](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/authenticator.h#L61)

Sets the password.

---

<a id="password"></a>

### password

`const`

```cpp
const std::string & password() const
```

[Defined in src/http/include/icy/http/authenticator.h:64](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/authenticator.h#L64)

Returns the password.

---

<a id="authenticate"></a>

### authenticate

```cpp
void authenticate(http::Request & request, const http::Response & response)
```

[Defined in src/http/include/icy/http/authenticator.h:69](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/authenticator.h#L69)

Inspects WWW-Authenticate header of the response, initializes the internal state (in case of digest authentication) and adds required information to the given http::Request.

---

<a id="updateauthinfo"></a>

### updateAuthInfo

```cpp
void updateAuthInfo(http::Request & request)
```

[Defined in src/http/include/icy/http/authenticator.h:73](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/authenticator.h#L73)

Updates internal state (in case of digest authentication) and replaces authentication information in the request accordingly.

---

<a id="proxyauthenticate"></a>

### proxyAuthenticate

```cpp
void proxyAuthenticate(http::Request & request, const http::Response & response)
```

[Defined in src/http/include/icy/http/authenticator.h:78](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/authenticator.h#L78)

Inspects Proxy-Authenticate header of the response, initializes the internal state (in case of digest authentication) and adds required information to the given http::Request.

---

<a id="updateproxyauthinfo"></a>

### updateProxyAuthInfo

```cpp
void updateProxyAuthInfo(http::Request & request)
```

[Defined in src/http/include/icy/http/authenticator.h:83](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/authenticator.h#L83)

Updates internal state (in case of digest authentication) and replaces proxy authentication information in the request accordingly.

## Private Attributes

| Return | Name | Description |
|--------|------|-------------|
| `std::string` | [`_username`](#_username)  |  |
| `std::string` | [`_password`](#_password)  |  |

---

<a id="_username"></a>

### _username

```cpp
std::string _username
```

[Defined in src/http/include/icy/http/authenticator.h:89](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/authenticator.h#L89)

---

<a id="_password"></a>

### _password

```cpp
std::string _password
```

[Defined in src/http/include/icy/http/authenticator.h:90](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/authenticator.h#L90)

## Private Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`Authenticator`](#authenticator-4)  | Deleted constructor. |
| [`Authenticator`](#authenticator) & | [`operator=`](#operator-199)  | Deleted assignment operator. |

---

<a id="authenticator-4"></a>

### Authenticator

```cpp
Authenticator(const Authenticator &) = delete
```

[Defined in src/http/include/icy/http/authenticator.h:86](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/authenticator.h#L86)

Deleted constructor.

---

<a id="operator-199"></a>

### operator=

```cpp
Authenticator & operator=(const Authenticator &) = delete
```

[Defined in src/http/include/icy/http/authenticator.h:87](https://github.com/auscaster/icey/blob/main/src/http/include/icy/http/authenticator.h#L87)

Deleted assignment operator.
