Skip to content

Using your local API in Momentum

GordiNoki edited this page Jul 13, 2024 · 7 revisions

As game code (including all interfacing with the backend) is closed-source, this guide is mainly applicable to licensed developers.

As of writing, the main branch is only compatible with an internal game branch (soon to be merged into feat/mom-0.10). If you're a licensee, use that branch. If you're not, ignore this guide!

With a database and backend spun up, optionally seeded with mock data (see Setup), you're able to point your game to the backend URL and see the backend interfacing with the game.

First, launch your game with -noencryptedtickets.

Due to the order of Momentum's initialization, the mom_auth_use_encrypted_app_tickets has been deprecated and replaced with the -noencryptedtickets launch parameter.

Then in console,

mom_api_url_base http://localhost:3000
mom_api_url_auth http://localhost:3000/auth
mom_auth_reauthenticate

mom_api_log_requests 1 and mom_api_log_requests_sensitive 1 are also useful for debugging.

If you're frequently switching between the development backend and our live instance, it's helpful to have two config files:

api_localhost.cfg
mom_api_url_base "http://localhost:3000"
mom_api_url_auth "http://localhost:3000/auth"
mom_api_log_requests 1
mom_api_log_requests_sensitive 1
api_default.cfg
mom_api_url_auth "https://auth.momentum-mod.org"
mom_api_url_base "https://api.momentum-mod.org"
mom_api_log_requests 0
mom_api_log_requests_sensitive 0

You could also use multiple launch scripts, one with -noencryptedtickets +exec api_localhost.cfg, another with +exec api_default.cfg.

What do these commands do? Are there any others I might need?

mom_api_log_requests

When developing you'll probably want to see the API requests your game client is making. This command shows that.

mom_api_url_auth

This URL is the 'base' URL that the game will use when trying to get a valid JWT or use a refresh token to get a new JWT. If you are testing/developing with the authentication being done by a separate instance of the API then this URL may be different to the mom_api_url_base, however that's probably not the case.

mom_api_url_base

This URL is what the game uses for all other API calls. Simply it will use what ever is typed here and append the endpoint it's looking for at on the end. (e.g. mom_api_url_base + "/api/v1/maps")

-noencryptedtickets

By default, the type of auth token requested from Steam to send to our backend uses a specific encryption that the backend can verify locally using a secret provided by Steam. That secret is only available to specific Momentum developers (simply put: just Gocnak!) and only ever used in production.

Without that secret, the backend must send a request to Steam to verify the ticket sent from the user.

mom_auth_reauthenticate

Sends a new authentication request to the backend and reruns most requests made on game startup on response.