> For the complete documentation index, see [llms.txt](https://ronaldaug.gitbook.io/sim-rest/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ronaldaug.gitbook.io/sim-rest/authentication.md).

# Authentication

## Admin Users

Add admin users in `/database/config.php`&#x20;

> token will be auto generated

```javascript
{
    "admins": [
        {
            "username": "admin1",
            "password": "admin1",
            "token": ""
        },
        {
            "username": "admin2",
            "password": "admin2",
            "token": ""
        }
}
```

## Declare route for Authentication

Add /**auth** route in `index.php`

```php
/**
 * Authentication Route
 */
$router->post('/auth',function($payload){
    echo Auth::login($payload);
});
```

> Make sure to import **Auth** Class&#x20;
>
> `use Auth;`

## Get Admin User Token

<mark style="color:green;">`POST`</mark> `-/auth`

#### Request Body

| Name     | Type   | Description       |
| -------- | ------ | ----------------- |
| username | string | username of admin |
| password | string | password of admin |

{% tabs %}
{% tab title="200 " %}

```javascript
{
    "status": 200,
    "message": "Token generated.",
    "data": {
        "token": "NDFjMjhkMjZkYmRiZGJiMTE4NDZiYTZkODQ4NDcwMzI1NzdiYzJjNjI5Y2Q3MmNmYmYxNGE0YWUyOWU1Njg1ZjU4ZWYzNWM3OWY3NTE0N2FmYzQ0MjM4MGZkNTE0NjRjNzlkNzJiODFhM2RkMjBjMzBhMWM4MWVhNWIxY2U5OWRmMDYxNmIwODdhZDI1Y2EzYTM0N2ExYTAzNzBlNGJlNzBiMTMyMDNjMjZiNTljNGNhNDQwOTBiNDAzMTg0YzU3N2I3MDIzZDg="
    }
}
```

{% endtab %}
{% endtabs %}
