Auth

Auth

The API token:

Log Harvestor API utilizes JSON Web Tokens (JWT) for authentication. Both users and forwarders utilize these tokens for sending requests. The users use the tokens to access their own data, while forwarders use the tokens to send data to Log harvestor.

Obtaining an API token:

  • Users can obtain an API token by signing in with their credentials. See the sign-in endpoint.
  • Forwarders tokens can be generated within the app, or via the API. See the forwarder generate-token endpoint.
  • Token usage:

  • Both users and forwarders must embed their token in the Authorization header of their requests.
  • The token must be prefixed with the string "Bearer <token>".
  • Example: { Authorization: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...." }
  • Token permissions:

  • Users tokens can perform almost all the actions that can be performed via the application.
  • Users cannot send logs to Log Harvestor.
  • Forwarders can only send data. They cannot access any data.
  • Important:

  • Log Harvestor has restricted irreversible actions to the application only. So even if someone obtains your token, they cannot delete your account, or forwarders, or data.
  • Howerver, API tokens can do a lot of damage if they fall into the wrong hands. If someone obtains your token, they can access your data, make serious changes, or even add false data.
  • Ensure that you are keeping your tokens secure. NEVER share your tokens in a public forum, a public repository, or any place where someone nefarious could access them.
  • Sign in

    Description


    This endpoint generates a user token returns a token that can be used to access the API.

    Parameters


    body

    email

    string

    Required

    Description:

    Example:

    "ljack21@logharvestor.com"

    password

    string

    Required

    Description:

    Example:

    "password"

    Responses


    Type:

    UserAuthRes object


    Example:

    1
    2
    3
    4
    5
    6
    {
        _id: "0f9c0b0b4f0c6b0017f0e3b1",
        token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9",
        role: "demo",
        email: "ljack21@logharvestor.com"
    }

    Type:

    Error object


    Example:

    1
    2
    3
    4
    5
    {
        name: "Invalid Credentials",
        message: "Invalid email or password",
        status: 401
    }

    Type:

    Error object


    Example:

    1
    2
    3
    4
    5
    {
        name: "Internal Server Error",
        message: "Internal Server Error",
        status: 500
    }

    post

    /auth/signin

    Request

    1
    2
    3
    4
    5
    curl https://logharvestor.com/api/v1/auth/signin \
        -X POST \
         \
        -H 'Content-Type: application/json' \
    	--data-raw '{"email":"\"ljack21@logharvestor.com\"","password":"\"password\""}'

    Response

    1
    2
    3
    4
    5
    6
    {
        _id: "0f9c0b0b4f0c6b0017f0e3b1",
        token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9",
        role: "demo",
        email: "ljack21@logharvestor.com"
    }

    Refresh token

    Description


    This endpoint generates a new user token from a valid, non-expired users token.

    Once a users token is expired, it can no longer be refreshed and instead, a new token must be generated via the sign-in endpoint.

    A refresh token returns a new users token that will replace the old one. The old token will no longer be valid.

    The new token is utilized in the same way the previous token is utilized.

    Parameters


    headers

    Authorization

    string

    Required

    Description:

    Bearer token - JWT

    Example:

    "Bearer <token>"

    Responses


    Type:

    UserAuthRes object


    Example:

    1
    2
    3
    4
    5
    6
    {
        _id: "0f9c0b0b4f0c6b0017f0e3b1",
        token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9",
        role: "demo",
        email: "ljack21@logharvestor.com"
    }

    Type:

    Error object


    Example:

    1
    2
    3
    4
    5
    {
        name: "Invalid Token",
        message: "Invalid Authorization token",
        status: 401
    }

    Type:

    Error object


    Example:

    1
    2
    3
    4
    5
    {
        name: "Internal Server Error",
        message: "Internal Server Error",
        status: 500
    }

    post

    /auth/token/refresh

    Request

    1
    2
    3
    4
    curl https://logharvestor.com/api/v1/auth/token/refresh \
        -X POST \
        -H 'Authorization: Bearer <token>' \
        

    Response

    1
    2
    3
    4
    5
    6
    {
        _id: "0f9c0b0b4f0c6b0017f0e3b1",
        token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9",
        role: "demo",
        email: "ljack21@logharvestor.com"
    }

    Validate token

    Description


    This endpoint validates a usertoken.

    A valid token must meet the following criteria:

  • The token must be signed and originated by Log Harvestor.
  • The token must not be expired.
  • The token must not be revoked.
  • The token must not be blacklisted.
  • The token must not be malformed.
  • The token must not be tampered with.
  • Parameters


    headers

    Authorization

    string

    Required

    Description:

    Bearer token - JWT

    Example:

    "Bearer <token>"

    Responses


    Type:

    Boolean object


    Example:

    1
    "true"

    Type:

    Error object


    Example:

    1
    2
    3
    4
    5
    {
        name: "Invalid Token",
        message: "Invalid Authorization token",
        status: 401
    }

    Type:

    Error object


    Example:

    1
    2
    3
    4
    5
    {
        name: "Internal Server Error",
        message: "Internal Server Error",
        status: 500
    }

    post

    /auth/token/validate

    Request

    1
    2
    3
    4
    curl https://logharvestor.com/api/v1/auth/token/validate \
        -X POST \
        -H 'Authorization: Bearer <token>' \
        

    Response

    1
    "true"

    Log_Harvestor_Icon

    Join our newsletter

    support@logharvestor.com

    Copyright © Log Harvestor 2023TermsPrivacy