> For the complete documentation index, see [llms.txt](https://docs.hiveauth.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hiveauth.com/developer-documentation/protocol-description/authentication.md).

# Authentication

The initiator is the first peer who requests a connection, usually the **APP** reacting to a login request made by the **User**. The **APP** needs to authenticate the account that the **User** wants to log in with. The **User** has just to provide a Hive account name. No password or private key is required.

![](https://i.imgur.com/SIZf71O.png)

1. The **APP** sends an `auth_req` command to the **HAS**.
2. The **HAS** provides the **APP** with a request identifier (`uuid`) and a request expiration time (`auth_req_expire`)
3. The **APP** builds an authentication payload (`auth_payload`) which contains the received `uuid`, the account `name`, a session encryption key (`auth_key`) and the URL of the HAS `host` it is connected to.&#x20;

   The `auth_payload` will be shared with the **PKSA** offline using a QR code or deep linking.\
   The **APP** asks the **User** to start its **PKSA** and scan the QR Code or it triggers the **PKSA** using deep linking when on mobile.
4. The **User** starts the **PKSA**.&#x20;

   **Note:** the PKSA can be started before or after the user starts the authentication process. It doesn't matter.
5. The **User** scans the QR code using the **PKSA**.

   ***Note:** This step is optional when the **APP** is a mobile application. The **PKSA** can retrieve the* `auth_payload` *from the deep link that triggered it.*
6. The **PKSA** asks the **HAS** for its public encryption key to securely register the account (`name`) found in the `auth_req_payload`.
7. The **HAS** provides its public key to the **PKSA** (`key_server)`
8. The **PKSA** asks the **HAS** to register the account in order to receive account-related pending requests.
9. The **HAS** validates against the blockchain that the account exists and that the **PKSA** stores a valid private key from the account

   **Note:** The key ownership validation can be performed with any key. We recommend performing this process using the one that has the least permissions among those available.
10. Upon successful account validation, the **HAS** will forward the pending `auth_req` to the **PKSA**.&#x20;

    **Note:** The **PKSA** must match the `auth_payload.uuid` with the `auth_req.uuid` it receives to ensure it is processing the correct request.
11. The **PKSA** asks the **User** to approve or reject the authentication request.
12. The **User** approves or rejects the authentication request.
13. Depending on the user reaction:
    1. if the **User** approves the authentication request, the **PKSA**:
       * creates an `auth_expire and stores it`
       * encrypts the `uuid` with the key (`key_app`) found in the `auth_payload`
       * creates an `auth_ack_payload` with the above data (`auth_expire` and encrypted `uuid`) and sends it with an authentication request approval message (`auth_ack`) to the **HAS**.
    2. If the user rejects the authentication request, the **PKSA** sends an authentication refusal (`auth_nack`) to the HAS.

       ***Note:** This operation is not depicted in the above diagram for clarity.*
14. The **HAS** forwards the authentication approval and its payload (`auth_ack`) or the authentication refusal (`auth_nack`) to the **APP**.

The encryption performed at step 13.1 ensures that a malicious actor operating a **HAS** cannot bypass the **PKSA** to approve an authentication request by itself.

Remember that the **HAS** doesn't have access to `key_app`. Therefore, by matching the decrypted `auth_ack_payload.uuid` using its encryption key (`key_app`) with the pending request `uuid` it received from the **HAS** with the `sign_wait` event, the **APP** has 100% certainty that the encryption process was made by the **PKSA**.

{% hint style="warning" %}
**Note:** The default **maximum delay** to approve an authentication request is **60 seconds**. The **HAS** will discard any pending request with a longer timeout.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hiveauth.com/developer-documentation/protocol-description/authentication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
