Android Authentication

For any user to interact with GameSpark's platform they must be authenticated. There are three ways to authenticate to GameSparks:

Username/Password Authentication

Users can register to your game using a username and password. A user registers using the RegistrationRequest and passing in string values for DisplayName, UserName, and Password:

    GSAndroidPlatform.gs().getRequestBuilder().createRegistrationRequest()
    .setUserName(string)
    .setDisplayName(string)
    .setPassword(string)
    .send(new GSEventConsumer<GSResponseBuilder.RegistrationResponse>() {
         @Override
         public void onEvent(GSResponseBuilder.RegistrationResponse registrationResponse) {
                if(!registrationResponse.hasErrors()){
                     //Do something
                   }
                  else{
                     //If there's an error
                     //Do something
                   }
                   }
          });

After a player is registered on the platform, they can use the AuthenticationRequest to login using the UserName and Password:


    //Authentication request through the GS request builder
    //The input is coming from editText widgets
    GSAndroidPlatform.gs().getRequestBuilder().createAuthenticationRequest()
    .setUserName(usernameTxt.getText().toString())
    .setPassword(passwordTxt.getText().toString())
    .send(new GSEventConsumer<GSResponseBuilder.AuthenticationResponse>()() {
            @Override
            public void onEvent(AuthenticationResponse authenticationResponse) {
                //Is the response error free?
                if(!authenticationResponse.hasErrors()){
                    //Do something
                }
                else{
                   //If there's an error
                   //Do something
                }
            }
            });

Device Authentication

You can automatically authenticate devices by simply passing in a unique string device Id and string device OS. You can use this in combination with social authentication to keep track of your players:


GSAndroidPlatform.gs().getRequestBuilder().createDeviceAuthenticationRequest()
                    .setDeviceId(string).setDeviceOS(string).send(new GSEventConsumer<GSResponseBuilder.AuthenticationResponse>() {
                @Override
                public void onEvent(AuthenticationResponse authenticationResponse) {

                }
            });

Social Authentication

Players can use their social accounts from a number of 3rd-party providers to create an account on the GameSparks platform. For details of the 3rd-party providers we support, see here

All social authentication requests follow a similar method of forwarding an authentication token to our platform. Here's an example of the Google Plus authentication request:

    GSAndroidPlatform.gs().getRequestBuilder().createGooglePlusConnectRequest()
                    .setAccessToken(String).setDoNotLinkToCurrentPlayer(Bool).send(new GSEventConsumer<GSResponseBuilder.AuthenticationResponse>() {
                @Override
                public void onEvent(AuthenticationResponse authenticationResponse) {

                }
            });

You can check out our API documentation site for the full list of requests, here.

Did this page help you? Please enter your feedback below. For questions about using this part of the platform, please contact support here