This document outlines the endpoints and specifications for creating a new version of the outdated server API currently in use.
To be PR'd into the original as a replacement at a later date
API Namespace: /api/v1/*
The following sections documents all implemented endpoints and their inputs and outputs.
The following endpoints may be used by anyone, without any authorization, even if they are not a user of the server.
They are meant to expose information for display on the frontends.
Future modifications may make these endpoints only accessible by any user with a VALID API key instead of just any user.
Response:
- (200) Should always be ok unless the server is unreachable
Related Convenience Endpoint:
GET /users/status - List all user data WITH their latest sessions attached. Intended for the list of users signed in.
Responses: User objects with asessionkey in each containing their latest session (See/userand/session/latest)
Authentication is handled using generated API keys.
Each user has a password which has the sole purpose of being exchanged for an active API key.
A user can have multiple functional API keys and each key has the ability to revoke any and all API keys in exchange for a new one to invalidate all other sessions.
You may store this API key on the device instead of a password.
Warning Changing a password does not implicitly revoke all API keys. Changing a password will not affect the API keys and revoking or regenerating API keys will not affect the password.
POST /user/auth/exchange - Given a password, returns a randomly generated, valid api key that does not expire for the user
Input: Send password in body in the
passwordkey
Response:
- (200) API key is provided in the
api_keyfieldErrors:
- (401)
invalid_passwordNo user with this password exists
Errors:
- (401)
not_authedwhen no auth header is provided- (404)
user_not_foundwhen no user with a matching auth header is foundResponse:
- (200) Successfully revoked API key. Returns new key under the
new_api_keykey
These endpoints handle viewing and modifying information about a single user (normally the person signed in).
Response:
- (200) User object is returned. Not in a
userkeyErrors:
- (404)
user_not_foundwhen the user with the corresponding auth header does not exist
Is an optional feature provided for convenience Response:
- (204) No content is returned. Success
Errors:
- (422)
invalid_passwordPassword is invalid. Other errors may be more specific in the future
Response:
- (200) List of sessions in the
sessionskeyErrors:
- (401)
not_authedwhen no auth header is provided- (404)
user_not_foundwhen no user with a matching auth header is found
Response:
- (200) Returns the latest session
Warnings:
- (204)
NO_SESSIONSNo session is foundErrors:
- (401)
not_authedwhen no auth header is provided- (404)
user_not_foundwhen no user with a matching auth header is found
Input: Use
methodkey forsign_inorsign_out
Response:
- (200) Success. Returns the updated session even if no changes were made
Errors:
- (401)
not_authedwhen no auth header is provided- (404)
user_not_foundwhen no user with a matching auth header is found
These endpoints are intended for people with the admin password only and have a lot more power.
Note that server admins also have the ability to look up anyone's API key to use any of the User Methods as well.
The ability to impersonate normal users has not been added for normal Admin users yet.
Input: New user object in body
Response:
- (200) New user object is returned (Same form as
/user)Errors:
- (401)
not_authedwhen no admin header is provided- (401)
invalid_admin_authwhen admin header is invalid- (409)
user_already_existswhen a user with the same password exists
Input: New user object in body
Response:
- (200) New user object is returned (Same form as
/user)Errors:
- (401)
not_authedwhen no admin header is provided- (401)
invalid_admin_authwhen admin header is invalid- (404)
user_not_foundwhen no user with the provided auth header exists
Response:
- (204) No content is returned
Warnings:
- (204)
user_already_deletedUser has already been deleted. No content is returnedErrors:
- (401)
not_authedwhen no admin header is provided- (401)
invalid_admin_authwhen admin header is invalid
Response:
- (200) All sessions from all users in
[user id]: [sessions]formatErrors:
- (401)
not_authedwhen no admin auth header is provided- (401)
invalid_admin_authwhen an invalid admin auth header is provided
Input: A complete session object under the
sessionkey and the target user's identifier asuser_id
Response:
- (200) New session is returned
Errors:
- (401)
not_authedwhen no auth header is provided- (401)
invalid_admin_authwhen an invalid admin auth header is provided- (404)
user_not_foundwhen no user with a matching auth header is found- (422)
user_not_specifiedwhen no target user to add the session to is specified
Response:
- (204) No content returned. Successfully deleted
Errors:
- (401)
not_authedwhen no admin auth header is provided- (401)
invalid_admin_authwhen an invalid admin auth header is provided
The following endpoints are planned but not implemented. Their functionalities may change.
WS /ws/users/status - Websocket invoked each time any user has their status change (Provides the new user's status)
Response:
- (200) Contains the changed user in the
userkey andmessage_idandnext_message_idto detect missed messages
POST /users/status/sync - To signal the server to sync data to external sources like Google Sheets or a file on-demand
Response:
- (200) Successful sync
Errors:
- (500)
sync_failed- Generic failure code. More specific codes added as needed
As a side effect of revoke, all auth-related endpoints can also fail with error: "already_revoked"
After consuming/checking the status of the request, you may delete the keys ok, warning, and error to leave a standard response for the endpoint that you can store in a variable or state
{
"ok": "true/false",
"warning": "UNKNOWN_WARNING",
"error": "UNKNOWN_ERROR",
"other data": {
"...stuff": "etc"
}
}Since not being able to find the user is also indicates an invalid API key, the code returned could be unauthorized instead.
For the admin side of things, an identifier still has to be chosen. It will likely be the SQL row id
To differentiate an admin key from a user key, admin keys and user keys will be prefixed differently. Likely A- for admins and U- for users.
Admin API key exchange may be worth adding at a later date to avoid leaking the credentials with physical device access
Logging can be added silently to any endpoint, provided it fails silently in most cases.
There are no GETs or other methods for /user/session/:session-id