# Custom Authentication

<figure><img src="/files/9OnxWlVkCV7vjizwTkEt" alt=""><figcaption><p>To activate the custom authentication, toggle this button on.</p></figcaption></figure>

<figure><img src="/files/g8H4jWtVPpmLn9nNmz0q" alt=""><figcaption></figcaption></figure>

* After subscribing to this feature, you can find it in Workspace Settings -> Workspace Information -> Enable required login for chat user. There will be some fields that you need to know:&#x20;
* **Authentication URL:** This is the endpoint we will call to your server to retrieve user information from there to create a chat user on CX Genie side.
* **Select identity method:** The main field to identify whether that chat user already exists in our system. For example, if you currently select the phone number, after retrieving the user information from your side, CX Genie will check if this phone number has a corresponding chat user. If it does, CX Genie will update the info; if not, we will create a new one.
* **Header token:** The token to be included in the request when our server calls your server.
* To use this feature, when embedding the chat or installing the package on mobile, you will need to pass in the user token. Example when embedding bubble chat:&#x20;

{% code overflow="wrap" fullWidth="false" %}

```
<script src="https..://widget.cxgenie.ai/widget.js" data-aid="227b289e-bb0b-49cc-a9c8-fd9bcafddf18" data-token="%USER_TOKEN%" data-lang="en"></script>
```

{% endcode %}

* Example: when using URL: <http://www.testing.com>
  * Header token: HEADER\_TOKEN
  * User Token: USER\_TOKEN
  * CX Genie will request:&#x20;

{% code overflow="wrap" fullWidth="true" %}

```
curl --request POST \
  --url https://testing.com/ \
  --header 'Authorization: HEADER_TOKEN Bearer' \
  --header 'Content-Type: application/json' \
  --data '{
    "access_token": "USER_TOKEN"
}'
```

{% endcode %}

* Expected response from your server:

```
{
    "status": true,
    "message": "Successfully!",
    "data": {
        "name": "Sample User",
        "phone_number": "090XXXXXXX",
        "country_code": "+84",
        "email": "sample@gmail.com",
        "avatar": "https://...",
        "label": "Your custom label for chat user"
    }
}
```


---

# Agent Instructions: 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://documents.cxgenie.ai/marketplace/custom-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.
