# BasicAuthenticator

<a id="basicauthenticator"></a>

# BasicAuthenticator

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

class BasicAuthenticator
```

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

Encodes and decodes HTTP Basic authentication credentials.

## Public Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`BasicAuthenticator`](#basicauthenticator-1)  | Creates an empty basic authenticator. |
|  | [`BasicAuthenticator`](#basicauthenticator-2)  | Creates a basic authenticator with the given username and password. |
|  | [`BasicAuthenticator`](#basicauthenticator-3) `explicit` | Extracts basic authentication credentials from the given request. |
|  | [`BasicAuthenticator`](#basicauthenticator-4) `explicit` | Parses a raw Basic authentication payload string. The value can be extracted from a request via [`Request::getCredentials()`](https://auscaster.com/icey/docs/api-reference/icy-http-Request.md#getcredentials). |
|  | [`~BasicAuthenticator`](#basicauthenticator-5)  | Destroys the basic authenticator. |
| `void` | [`setUsername`](#setusername-1)  | Sets the username. |
| `const std::string &` | [`username`](#username-1) `const` | Returns the username. |
| `void` | [`setPassword`](#setpassword-1)  | Sets the password. |
| `const std::string &` | [`password`](#password-1) `const` | Returns the password. |
| `void` | [`authenticate`](#authenticate-1) `const` | Adds authentication information to the given http::Request. |
| `void` | [`proxyAuthenticate`](#proxyauthenticate-1) `const` | Adds proxy authentication information to the given http::Request. |

---

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

### BasicAuthenticator

```cpp
BasicAuthenticator()
```

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

Creates an empty basic authenticator.

---

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

### BasicAuthenticator

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

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

Creates a basic authenticator with the given username and password.

---

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

### BasicAuthenticator

`explicit`

```cpp
explicit BasicAuthenticator(const http::Request & request)
```

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

Extracts basic authentication credentials from the given request.

Throws a NotAuthenticatedException if the request does not contain basic authentication information.

---

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

### BasicAuthenticator

`explicit`

```cpp
explicit BasicAuthenticator(const std::string & authInfo)
```

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

Parses a raw Basic authentication payload string. The value can be extracted from a request via [`Request::getCredentials()`](https://auscaster.com/icey/docs/api-reference/icy-http-Request.md#getcredentials).

---

<a id="basicauthenticator-5"></a>

### ~BasicAuthenticator

```cpp
~BasicAuthenticator()
```

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

Destroys the basic authenticator.

---

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

### setUsername

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

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

Sets the username.

---

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

### username

`const`

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

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

Returns the username.

---

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

### setPassword

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

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

Sets the password.

---

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

### password

`const`

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

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

Returns the password.

---

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

### authenticate

`const`

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

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

Adds authentication information to the given http::Request.

---

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

### proxyAuthenticate

`const`

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

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

Adds proxy authentication information to the given http::Request.

## Protected Methods

| Return | Name | Description |
|--------|------|-------------|
| `void` | [`parseAuthInfo`](#parseauthinfo)  | Extracts username and password from Basic authentication info by base64-decoding authInfo and splitting the resulting std::string at the ':' delimiter. |

---

<a id="parseauthinfo"></a>

### parseAuthInfo

```cpp
void parseAuthInfo(std::string_view authInfo)
```

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

Extracts username and password from Basic authentication info by base64-decoding authInfo and splitting the resulting std::string at the ':' delimiter.

## Private Attributes

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

---

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

### _username

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

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

---

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

### _password

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

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

## Private Methods

| Return | Name | Description |
|--------|------|-------------|
|  | [`BasicAuthenticator`](#basicauthenticator-6)  | Deleted constructor. |
| [`BasicAuthenticator`](#basicauthenticator) & | [`operator=`](#operator-200)  | Deleted assignment operator. |

---

<a id="basicauthenticator-6"></a>

### BasicAuthenticator

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

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

Deleted constructor.

---

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

### operator=

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

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

Deleted assignment operator.
