<commit_before>.. _proxyauth:

Enabling authentication for the Hoverfly proxy and API
======================================================

If you are running Hoverfly on a remote host (see :ref:`remotehoverfly`), you may wish to 
enable authentication on the Hoverfly proxy and API.


Setting Hoverfly authentication credentials
-------------------------------------------

In this example, we assume that the steps in the :ref:`remotehoverfly` tutorial have been followed, 
and that the Hoverfly binary is installed **but not running** on a remote host.

On the **remote host**, run the following command to start Hoverfly with authentication credentials, 
and the default admin and proxy ports overridden.

.. literalinclude:: hoverfly-start-proxy-auth.sh
   :language: sh 

Configuring hoverctl
--------------------

On your **local machine**, edit your ``~/.hoverfly/config.yml`` so it looks like this:

.. literalinclude:: config.yml
   :language: none

The ``config.yml`` file will now tell hoverctl the location of the remote Hoverfly instance,
and provide the credentials required to authenticate.

Run the following commands **on your local machine** to capture and simulate a URL using the 
remote Hoverfly:

.. literalinclude:: curl-proxy-basic-auth.sh
   :language: sh

.. note::
   The ``hoverfly.username`` and ``hoverfly.password`` values in the ``config.yml`` file 
   allow hoverctl to authenticate against the admin API of a remote Hoverfly instance. 
   
   The proxy authentication credentials must **also be provided to the application making the request**,
   in this case, cURL.
<commit_msg>Mentioned basic HTTP auth<commit_after>.. _proxyauth:

Enabling authentication for the Hoverfly proxy and API
======================================================

If you are running Hoverfly on a remote host (see :ref:`remotehoverfly`), you may wish to 
enable authentication on the Hoverfly proxy and API.


Setting Hoverfly authentication credentials
-------------------------------------------

In this example, we assume that the steps in the :ref:`remotehoverfly` tutorial have been followed, 
and that the Hoverfly binary is installed **but not running** on a remote host.

On the **remote host**, run the following command to start Hoverfly with authentication credentials, 
and the default admin and proxy ports overridden.

.. literalinclude:: hoverfly-start-proxy-auth.sh
   :language: sh 

Configuring hoverctl
--------------------

On your **local machine**, edit your ``~/.hoverfly/config.yml`` so it looks like this:

.. literalinclude:: config.yml
   :language: none

The ``config.yml`` file will now tell hoverctl the location of the remote Hoverfly instance,
and provide the credentials required to authenticate.

Run the following commands **on your local machine** to capture and simulate a URL using the 
remote Hoverfly:

.. literalinclude:: curl-proxy-basic-auth.sh
   :language: sh

.. note::
   The ``hoverfly.username`` and ``hoverfly.password`` values in the ``config.yml`` file 
   allow hoverctl to authenticate against the admin API of a remote Hoverfly instance. 
   
   When using authentication, the Hoverfly proxy port is also authenticated using basic HTTP authentication. This means that any application using Hoverfly must include the authentication credentials as part of the proxy URL. 
{'fraction_non_alphanumeric': 0.13636363636363635, 'fraction_numerical': 0.0, 'mean_word_length': 3.764957264957265, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1786288', 'n_tokens_mistral': 834, 'n_tokens_neox': 802, 'n_words': 405}