Construct 2 Authentication

There are three ways to authenticate using GameSparks:

In this tutorial we'll only cover GameSparks and Device authentication because Social authentication is different for every 3rd-party provider and covering authentication for each of these is beyond the scope of this tutorial.

GameSparks Authentication

With the Construct SDK, sending a plain request into the GameSparks platform is not feasible - you'll get a response back but you won't be able to interpret the response. Each request to the GameSparks platform should be paired with an event listener that will trigger on response.

Before authenticating on the platform, you must first register with a UserName and Password. This creates a “player” on GameSparks that can be used to log in. Here's an example of registering a player once a button has been pressed:


You can use onInit to run additional events once the initialization to GameSparks has completed. In the example below, we make an AuthenticationRequest once the platform has been initialized:


Sending the request will result in the game receiving a response from GameSparks, so we need a way of reacting to the response when it comes in and to perform some sort of action. The GameSparks object has various event listeners that perform this, such as “onAuthenticationResponse”, and which can be used in this respect. With this setup we can do a variety of different things. For example, set the Text of what comes back in the response, set an instance or global variables, or call additional functions:


Device Authentication

Device authentication doesn't need registration and relies on the Device ID (which must be unique) and the Device OS. However, the Device OS is not restricted to designating operating systems and for this example we mark the OS as Construct2: