External Services
Game servers can make web requests to external API's using the built-in HttpManager. Each request is signed and can be validated by the service you are calling, see Verifying GameServer HTTP Requests below.
Overview
// Web Requests can only be made on the gameservers. Requests made on the client will fail.
if (!Game.IsServer()) return;
let getResult = HttpManager.GetAsync("https://jsonplaceholder.typicode.com/todos/1");
print(getResult.statusCode, getResult.data);
let postResult = HttpManager.PostAsync("https://jsonplaceholder.typicode.com/posts", json.encode({
title: 'foo',
body: 'bar',
}));
print(postResult.statusCode, postResult.data);
Supported Methods
GetAsync(url: string, headers: string): HttpResponse;
GetAsync(url: string): HttpResponse;
PatchAsync(url: string, data: string): HttpResponse;
PatchAsync(url: string, data: string, headers: string): HttpResponse;
PostAsync(url: string, data: string): HttpResponse;
PostAsync(url: string, data: string, headers: string): HttpResponse;
PutAsync(url: string, data: string): HttpResponse;
PutAsync(url: string, data: string, headers: string): HttpResponse;
PutAsync(options: RequestHelper, headers: string): HttpResponse;
DeleteAsync(url: string): HttpResponse;
DeleteAsync(url: string, headers: string): HttpResponse;Verifying GameServer HTTP Requests
Requests originating from a GameServer will include an additional header called: x-airship-signature containing a JWT with request details including:
Each JWT is signed with a specific public key that can be identified in the header using kid:
Using the kid you can validate the JWT against Airship public keys using our JWKS endpoint: https://airship.gg/.well-known/jwks.json
Read more here: https://stytch.com/blog/understanding-jwks/
Examples verifying a JWT using JWKS can be found here: https://github.com/panva/jose/blob/main/docs/jwks/remote/functions/createRemoteJWKSet.md
When validating the token, ensure the JWT is signed by an Airship public key and ensure the hostname / path matches your API url.
Last updated