API Auth

Usage with JavaScript

Installation

The source code is available on GitHub and the package can be installed with npm:

npm install azuriom-auth

Example

import { AuthClient } from 'azuriom-auth'

async function login(email, password) {
    const client = new AuthClient('https://rplands.royolands.com/ru-ru/home')

    let result = await client.login(email, password)

    if (result.status === 'pending' && result.requires2fa) {
        const twoFactorCode = '' // IMPORTANT: Replace with the 2FA user temporary code

        result = await client.login(email, password, twoFactorCode)
    }

    if (result.status !== 'success') {
        throw 'Unexpected result: ' + JSON.stringify(result)
    }

    return result
}

Endpoints

Authentification

POST /authenticate

Authenticate a user with their website credentials

Request

Field
Description

email

Username or e-mail address

password

Password

code

2FA code, should be included only if the response status is pending and the reason is 2fa

Response

Returns the user with his various information, and the unique token which can be used to verify the connection or to disconnect.

{
    "id": 1,
    "username": "Username",
    "uuid": "00000000-0000-0000-0000-000000000000",
    "email_verified": true,
    "money": 100.0,
    "role": {
        "name": "Member",
        "color": "#e10d11"
    },
    "banned": false,
    "created_at": "2020-06-29T17:39:12+00:00",
    "access_token": "xxxxxxxx"
}

Verification

POST /verify

Request

Field
Description

access_token

Unique access token

Réponse

Returns the user with his various information, and the unique token which can be used to verify the connection or to disconnect.

Success response example (HTTP 2xx):

{
    "id": 1,
    "username": "Username",
    "uuid": "00000000-0000-0000-0000-000000000000",
    "email_verified": true,
    "money": 100.0,
    "role": {
        "name": "Member",
        "color": "#e10d11"
    },
    "banned": false,
    "created_at": "2020-06-29T17:39:12+00:00",
    "access_token": "xxxxxxxx"
}

Error response example (HTTP 4xx):

{
    "status": "error",
    "reason": "invalid_credentials",
    "message": "Invalid credentials"
}

Logout

POST /logout

Logout the user and invalidates the access token.

Request

Field
Description

access_token

Unique access token

Response

Empty response, with 2xx status code.

Last updated