Authentication

Add user authentication endpoint to authenticate your API.

Overview

When creating an application, there is always a problem of implementing login and registration. With SlashApi, you get them out of the box.

Getting Started

After you create an account and log in to the dashboard, choose Authentication API on the collections page. You just need fill the name of your Authentication source in the creation form.

After you create the Authentication API, select the API that you want to add authentication with this data source and choose the "Secure Endpoint" icon.

Secure your endpoint

API Endpoints

Register

To register a user you just need to send the data to the register endpoint.

POST
<team>/auth/<identifier>/register

Request Body

{
    "data": {
        "email": "test@domain.com",
        "password": "12345678",
        "permissions": ["*"],
        "custom_attributes": {
            "internal_id": 1
        }
    }
}

Example Response

Success Response
{
    "data": {
        "email": "test@domain.com",
        "permissions": [
            "*"
        ],
        "custom_attributes": {
            "internal_id": 1
        },
        "created_at": "2021-07-30T17:17:51.000000Z",
        "updated_at": "2021-07-30T17:17:51.000000Z"
    }
}
Validation Error
{
    "message": "The given data was invalid.",
    "errors": {
        "data.email": [
            "The data.email must be a valid email address."
        ]
    }
}

Available Permissions

You can also assign specific permissions to limit which areas of your API that a user may be used to access. See the list of available permissions that you can assign to your user.

Login

Login a user

POST
<team>/auth/<identifier>/login

Response Body

{
    "email": "test@domain.com",
    "password": "12345678"
}

Example Response

Success Response
{
    "data": {
        "email": "test@domain.com",
        "custom_attributes": null,
        "created_at": "2021-07-29T17:32:12.000000Z",
        "token": "13|rg7NO74HJJX1RboQTVHZvHsuyehvYawTUqELcVff"
    }
}
Validation Error
{
    "message": "The given data was invalid.",
    "errors": {
        "email": [
            "The provided credentials are incorrect."
        ]
    }
}

Logout

By default the token generated from the Login endpoint will never expired, to revoke the token you need to call the Logout endpoint.

To send request to the Logout endpoint, you must include Authorization header with Beared followed with generated token from the Login endpoint.

POST
<team>/auth/<identifier>/login

Example Response

Success Response
{
    "message": "User logged out"
}
Invalid Token Error
{
    "message": "Invalid token"
}

Update User

Update user data.

PATCH
<team>/auth/<identifier>/<id>

Request Body

{
    "data": {
        "email": "test@domain.com",
        "password": "12345678",
        "permissions": ["*"],
        "custom_attributes": {
            "internal_id": 1
        }
    }
}

Example Response

Success Response
{
    "data": {
        "email": "test@domain.com",
        "permissions": [
            "*"
        ],
        "custom_attributes": {
            "internal_id": 1
        },
        "created_at": "2021-07-30T17:17:51.000000Z",
        "updated_at": "2021-07-30T17:18:51.000000Z"
    }
}
Validation Error
{
    "message": "The given data was invalid.",
    "errors": {
        "data.email": [
            "The data.email must be a valid email address."
        ]
    }
}

Delete User

Delete user.

DELETE
<team>/auth/<identifier>/<id>

Example Response

Success Response
{
    "message": "User deleted"
}
Validation Error
{
    "message": "You don't have permission to access this data."
}