> For the complete documentation index, see [llms.txt](https://rezi-1.gitbook.io/rms-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://rezi-1.gitbook.io/rms-guide/rezi-rms-features/login-customization/custom-token-implementation.md).

# Custom Token Implementation

### Get your Private Token API key.

Please contact your account manager to get your [Private Token API](/rms-guide/rezi-api/private-token-api.md). You will find more information in the [Private Token API section](/rms-guide/rezi-api/private-token-api.md).

{% hint style="danger" %}
You are responsible for keeping the key **secure and private.**. \
**Never use the** **Private** **Token** **key** **in** **Front-end code or pushed in a public repository.**&#x20;
{% endhint %}

### **Get a user token to auto-connect them.**

Call the Rezi API below with the information required. The private key will be sent to the API; call the API only from your back-end or micro-service. Calling this API directly from Front-end will publicly reveal your private key.&#x20;

The user token is valid for less than 1 hour. After you get the User Token, [auto-connect your user](/rms-guide/rezi-rms-features/login-customization/custom-token-implementation.md#auto-connect-with-the-user-token).

## Get a User Token

<mark style="color:green;">`POST`</mark> `https://open-api.rezi.ai/v1/user/token`

This endpoint allows you to get a token to auto-connect your user by sharing user credential.

#### Headers

| Name                                             | Type   | Description                                                                                                                                                   |
| ------------------------------------------------ | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Content-type<mark style="color:red;">\*</mark>   | string | "application/json"                                                                                                                                            |
| Authentication<mark style="color:red;">\*</mark> | string | <p>"Bearer PRIVATE\_TOKEN\_API\_KEY" <br>Authentication token to secure and track down your usage. Use this specific format with your Private API key<br></p> |

#### Request Body

| Name                                    | Type   | Description                                                                                             |
| --------------------------------------- | ------ | ------------------------------------------------------------------------------------------------------- |
| uid<mark style="color:red;">\*</mark>   | string | <p>Password of the user your want to connect.<br>You can hash from your side before sending to API.</p> |
| email<mark style="color:red;">\*</mark> | string | Email of the user your want to connect.                                                                 |

{% tabs %}
{% tab title="200 User successfully retrieve." %}

```
{    
    "status": "success",
    "userID": "abcdefg",
    "token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJodHRwczovL2lkZW50aXR5dG9vbGtpdC5nb29nbGVhcGlzLmNvbS9nb29nbGUuaWRlbnRpdHkuaWRlbnRpdHl0b29sa2l0LnYxLklkZW50aXR5VG9vbGtpdCIsImlhdCI6MTYyOTM2MTU5MywiZXhwIjoxNjI5MzY1MTkzLCJpc3MiOiJmaXJlYmFzZS1hZG1pbnNkay1wNmFyekByZXppLWRldmVsb3AuaWFtLmdzZXJ2aWNlYWNjb3VudC5jb20iLCJzdWIiOiJmaXJlYmFzZS1hZG1pbnNkay1wNmFyekByZXppLWRldmVsb3AuaWFtLmdzZXJ2aWNlYWNjb3VudC5jb20iLCJ1aWQiOiJ5ZGtzU1hEVTFQWjVoaHVOZENWbCJ9.TtMwURv2p_c2wm0MTVA1EmJQs_eXcg3KjINWs3SgGQHian2jp7zVSlN16fhf5IbyD9VWhujyG4738IjfjDnqW7EXrKRatm4QWGstCx6t1G2u86YObuJIaqzt09-IC_gVKLN4t4wJ5AHbACC1HjOf9t_Htd4ce8U7tdFqUtA_taR1BH6VQ0gISba8LICwXk6EC1vvwS3qPB202GCr4KAlyLnHLOmI6Xh93BghBtab2Do-_tpMVeu2NlCBlw0KCgsP2llpvqAALrqKyReyNb3ESPUGqsrNBS8Zi6gQnOuq-5VlVP08E9_YfswNPDRNHhKXYNn4IrRND62WWRchjys2AQ"
}
```

{% endtab %}

{% tab title="500: Internal Server Error Server error" %}

```javascript
{
    // Response
}
```

{% endtab %}

{% tab title="401: Unauthorized Private token authentication error" %}

```javascript
{
    "status": "error",
    "errorCode": "token-01",
    "errorMessage": "unauthorized token"
}
```

{% endtab %}

{% tab title="400: Bad Request bad request, missing information" %}

```javascript
{
    "status": "bad request",
    "message": "missing information to connect user"
}
```

{% endtab %}

{% tab title="401: Unauthorized token expired" %}

```javascript
{
    "code": 401,
    "message": "Jwt is expired"
}
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
If first time for this user to connect, creation of user can take around 2 seconds.
{% endhint %}

{% hint style="danger" %}
UID associated to email should be all time the same. Password hashed as UID is a secure way to connect your user to our system. &#x20;
{% endhint %}

### Signup/Login with the user token

#### 1/ You will need to get a Private Token Key check the [Private Token API section](/rms-guide/rezi-api/private-token-api.md).

#### 2/ Call the Open api [Post /user/token](/rms-guide/rezi-api/user/token.md) to receive a USER\_TOKEN to connect your user

## Get a User Token

<mark style="color:green;">`POST`</mark> `https://open-api.rezi.ai/v1/user/token`

This endpoint allows you to get a token to auto-connect your user by sharing user credential.

#### Headers

| Name                                             | Type   | Description                                                                                                                                                   |
| ------------------------------------------------ | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Content-type<mark style="color:red;">\*</mark>   | string | "application/json"                                                                                                                                            |
| Authentication<mark style="color:red;">\*</mark> | string | <p>"Bearer PRIVATE\_TOKEN\_API\_KEY" <br>Authentication token to secure and track down your usage. Use this specific format with your Private API key<br></p> |

#### Request Body

| Name                                    | Type   | Description                                                                                             |
| --------------------------------------- | ------ | ------------------------------------------------------------------------------------------------------- |
| uid<mark style="color:red;">\*</mark>   | string | <p>Password of the user your want to connect.<br>You can hash from your side before sending to API.</p> |
| email<mark style="color:red;">\*</mark> | string | Email of the user your want to connect.                                                                 |

{% tabs %}
{% tab title="200 User successfully retrieve." %}

```
{    
    "status": "success",
    "userID": "abcdefg",
    "token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJodHRwczovL2lkZW50aXR5dG9vbGtpdC5nb29nbGVhcGlzLmNvbS9nb29nbGUuaWRlbnRpdHkuaWRlbnRpdHl0b29sa2l0LnYxLklkZW50aXR5VG9vbGtpdCIsImlhdCI6MTYyOTM2MTU5MywiZXhwIjoxNjI5MzY1MTkzLCJpc3MiOiJmaXJlYmFzZS1hZG1pbnNkay1wNmFyekByZXppLWRldmVsb3AuaWFtLmdzZXJ2aWNlYWNjb3VudC5jb20iLCJzdWIiOiJmaXJlYmFzZS1hZG1pbnNkay1wNmFyekByZXppLWRldmVsb3AuaWFtLmdzZXJ2aWNlYWNjb3VudC5jb20iLCJ1aWQiOiJ5ZGtzU1hEVTFQWjVoaHVOZENWbCJ9.TtMwURv2p_c2wm0MTVA1EmJQs_eXcg3KjINWs3SgGQHian2jp7zVSlN16fhf5IbyD9VWhujyG4738IjfjDnqW7EXrKRatm4QWGstCx6t1G2u86YObuJIaqzt09-IC_gVKLN4t4wJ5AHbACC1HjOf9t_Htd4ce8U7tdFqUtA_taR1BH6VQ0gISba8LICwXk6EC1vvwS3qPB202GCr4KAlyLnHLOmI6Xh93BghBtab2Do-_tpMVeu2NlCBlw0KCgsP2llpvqAALrqKyReyNb3ESPUGqsrNBS8Zi6gQnOuq-5VlVP08E9_YfswNPDRNHhKXYNn4IrRND62WWRchjys2AQ}
```

{% endtab %}

{% tab title="500: Internal Server Error Server error" %}

```javascript
{
    // Response
}
```

{% endtab %}

{% tab title="401: Unauthorized Private token authentication error" %}

```javascript
{
    "status": "error",
    "errorCode": "token-01",
    "errorMessage": "unauthorized token"
}
```

{% endtab %}

{% tab title="400: Bad Request bad request, missing information" %}

```javascript
{
    "status": "bad request",
    "message": "missing information to connect user"
}
```

{% endtab %}

{% tab title="401: Unauthorized token expired" %}

```javascript
{
    "code": 401,
    "message": "Jwt is expired"
}
```

{% endtab %}
{% endtabs %}

Call example:

```shell
curl --location --request POST 'https://open-api.rezi.ai/v1/user/token'
--header 'Content-Type: application/json'
--header 'Authorization: Bearer PRIVATE_TOKEN_API'
--data-raw '{ "email": "user_email@gmail.com", "uid": "12345678910" }' 
```

Response example:

```json
{
    "status": "success",
    "token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJodHRwczovL2lkZW50aXR5dG9vbGtpdC5nb29nbGVhcGlzLmNvbS9nb29nbGUuaWRlbnRpdHkuaWRlbnRpdHl0b29sa2l0LnYxLklkZW50aXR5VG9vbGtpdCIsImlhdCI6MTY2MTgzOTk2OCwiZXhwIjoxNjYxODQzNTY4LCJpc3MiOiJyZXppLTNmMjY4QGFwcHNwb3QuZ3NlcnZpY2VhY2NvdW50LmNvbSIsInN1YiI6InJlemktM2YyNjhAYXBwc3BvdC5nc2VydmljZWFjY291bnQuY29tIiwidWlkIjoib0xYNFFCdm9PZTA0RE1uTzFGUUQifQ.VPCY_bjo8kNj8x1IOdMbHSvRuGB4yjfJjDudQ9m1A2AIoIRmFqFpl4P6ZCFaFqmYRx08jw2NH3JAMrlLmsc1XNjkWzOupgYqOYYU71f9ulalHL-h4Enb6RLm72iIQA8WbOhBNAiMi6khCHX-102wRhY0fS0vLVYUfrkUH3u2V3TP42lE1HpusxUlWs0FDp7pVqI7XmQydFFTI3CXOBUXftM1rPsqanqJw2U6SVCLz_iv9U8QhDmJMiel1PQO6a8Qt1nomwSMNpjRR2_63kouUQGeAw5vzoJwe85aYa7LsrsKu_nxh8vmos_XoR5R3Dr848rXnc5BNyX_UIXUh7CkZw"
}
```

#### 3/ You can connect your user to your RMS by passing, the user token (USER\_TOKEN ) directly in the URL.

<https://app.myAwesomeRms.com/**login/?token=**_**USER\\_TOKEN>\*\*\_

{% embed url="<https://www.youtube.com/watch?v=AMD-k08oNAM&ab_channel=Rezi>" %}

### The options list for the login URL

Each option can be added from the base URL <https://app.myAwesomeRms.com/**login/?key=value\\&key2=value2\\&key3=value3>\*\*

{% hint style="info" %}
**The first parameter needs "?" in front, other will be separated by an "&"**
{% endhint %}

| Key                     | Value                                                        | Required |
| ----------------------- | ------------------------------------------------------------ | -------- |
| token                   | ***USER\_TOKEN***                                            | Required |
| openOnboarding          | true or false, by default onboardin is not openning          | Optional |
| closeOnboardingRedirect | <p>an internal link for example:<br>/dashboard/education</p> | Optional |
|                         |                                                              |          |

A full example will be:

<https://app.myAwesomeRms.com/**login/?**&#x74;oke&#x6E;**=**_**USER\\_TOKEN**_**&**&#x6F;penOnboardin&#x67;**=true&**&#x63;loseOnboardingRedirec&#x74;**=/dashboard/education>\*\*

In this example, the user will be login, the onboarding will open right away and if the user decides to close the onboarding, it will be redirected to the best practices page.
