Skip to content

Repository files navigation

ofapi

ofapi is an API server that provides RESTful web APIs to enhance OpenFusion server instances.

ofapi groups available APIs into modules. Each module has a corresponding table in the config file (config.toml) and can be deactivated by commenting out the table (with the exception of the core and game modules, which are required).

Some modules are "secure", meaning their APIs must be accessed by the TLS port bound to by the application. TLS can be applied at the application level by compiling with the tlsfeature or by a proxy server such as nginx. Please verify that secure APIs are only accessible through TLS before deploying ofapi on a publicly accessible network.

ofapi requires an OpenFusion sqlite database of version 6 or higher.

Developing

Edit config.toml to your liking and then

cargo run

Production

cargo build --release
./target/release/ofapi

Modules & APIs

ModuleRequiredSecureDescription
coreYesNoCore functionality of the API server
tlsNo*N/ATLS configuration for secure APIs
emailNoN/ASMTP configuration for sending emails
gameYesNoGame version and login address info
monitorNoNoReal-time game data
moderationNoYesGame moderation tools, such as name requests
rankinfoNo*NoInfected Zone race ranking info
accountNoYesUser account management APIs
authNo*YesAuthentication and authorization APIs
cookieNo*YesSecure game login
legacyNoNoCompatibility with legacy, file-based clients
staticN/ANoStatic resource serving

*Module highly recommended

Module APIs

ModuleEndpointsMethodAuthedDescription
core/GETNoBasic info about ofapi and OpenFusion configuration
monitor/statusGETNoReal-time game data (e.g. player count)
moderation/namereqGETYesGet a list of pending player name requests
POSTYesApprove or deny a player name request
rankinfo/getranksPOSTNoRank info for an Infected Zone (game format)
account/accountGETYesBasic user account info
/account/registerPOSTNoRegister a user account
/account/verifyGETNoVerify an email address for an account
/account/update/passwordPOSTYesUpdate the password for an account
/account/update/emailPOSTYesUpdate the email for an account
auth/authPOSTNoObtain a refresh token for an account
/auth/sessionPOSTYes*Obtain a session token for an account
cookie/cookiePOSTYesObtain an OpenFusion login cookie for an account
legacy/index.htmlGETNoGet an index.html file for legacy client use
/assetInfo.phpGETNoGet an assetInfo.php file for legacy client use
/loginInfo.phpGETNoGet a loginInfo.php file for legacy client use
static/*GETNoSee statics.csv

*Auth by refresh token instead of session token

Technical documentation on each API is WIP and will be on the GitHub wiki.

Static Resources

Static files and directories can be easily served by mapping them to an endpoint in the statics.csv file. These are accessible from both HTTP and HTTPS. Some common mappings are included as defaults.

Authentication

ofapi uses capability-based JSON Web Tokens ("jwt") for authentication. A secret key is generated on first startup (see the config for the auth module) and is used for token signing. All tokens can be invalidated by deleting and regenerating the secret file. Do not share this file with anyone.

Refresh Tokens

Refresh tokens are used to generate new session tokens. They should be long-lived and cached by clients, and are invalidated upon password changes. Refresh tokens have a single capability: acquiring a session token.

Session Tokens

Session tokens are multi-capable and can access most authed module APIs, with the exception of those requiring extra capabilities (such as the moderation APIs). They should be very short-lived and reacquired using a refresh token.

Service Tokens

Service tokens are special tokens that are manually created using the gen_token binary in the Cargo project. The lifespan and capabilities of service tokens are completely customizable and are meant to be used by external services such as Discord bots.

Generation

You can run gen_token with Cargo like so:

cargo run --bin=gen_token

An interactive prompt will guide you through the token creation process.

About

OpenFusion API server

Resources

Stars

3 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages