Authentication via Secret Code
A way to save progress even on platforms without authorization.
Not all platforms have authorization, but no one wants to lose their progress. Within our service, all progress is already stored in the cloud. You just need to suggest to the user to write down the secret code.
Advantages:
- Anonymous authorization
- No need to enter name / email / phone and other personal data
- Cookies are not used
- Works in incognito mode
- Quick login method, no need to fill in anything except a short code
- A way to continue the game on any device
- For developers
- No need to implement authorization logic, work with forms or UI
- No additional provider in the authorization chain
- An additional way to retain players on platforms without authorization
Concept
A secret code is assigned to each player when created within the project and platform.
For support from your side, you need to:
- Check if Authentication via secret code is available on the platform;
- Render the profile window:
- Display the player's secret code, preferably with an explanation and a copy button for convenience;
- Login / account switch button;
- When clicked, call the login method
gp.player.login()
- Upon successful login, the event of successful authorization
gp.player.on('login')
will trigger - Redraw the interface / scene, updating player data
- When clicked, call the login method
Methods
You can check if Authentication via secret code is available on the platform using the method FREE:
- JavaScript
- Unity
gp.platform.isSecretCodeAuthAvailable; // boolean
GP_Platform.IsSecretCodeAuthAvailable(); // bool
To retrieve the secret code to display it in the game, you can use the method FREE:
- JavaScript
- Unity
gp.player.get('secretCode');
GP_Player.GetString("secretCode");
You can open the authorization window using the method +0-1 Request:
- JavaScript
- Unity
gp.player.login();
GP_Player.Login();
You can wait for the authorization event by subscribing to the event FREE:
- JavaScript
- Unity
gp.player.on('login', (success) => {});
// Event subscription
private void OnEnable()
{
GP_Player.OnLoginComplete += OnLoginComplete;
GP_Player.OnLoginError += OnLoginError;
}
// Unsubscribe from events
private void OnDisable()
{
GP_Player.OnLoginComplete -= OnLoginComplete;
GP_Player.OnLoginError -= OnLoginError;
}
// Event handling
private void OnLoginComplete()
{
Debug.Log("LoginComplete");
}
// Event handling
private void OnLoginError()
{
Debug.Log("LoginError");
}
Examples
Example of working with a secret code with support for Authentication via the platform:
- JavaScript
- Unity
// Example of a profile modal window controller
const profileModal = {
// Field for visually displaying the player's secret code
secretCodeTextField: {
setText(secretCode) {
// Set the text in the field under the secret code
},
},
// Button for logging in via the secret code
buttonSecretCodeAuth: {
show() {
// Show the button in the player's profile
},
onClick() {
// Show the login window
gp.player.login();
},
},
open() {
// Open the modal window
// Display the button for logging in with the secret code inside the window
this.buttonSecretCodeAuth.show();
// Show the player's secret code
this.secretCodeTextField.setText(gp.player.get('secretCode'));
},
close() {
// Close the modal window
},
};
// Example of a BUTTON controller for logging in via the integrated platform authentication
const buttonNativeAuth = {
show() {
// Show the button in the game
},
onClick() {
// Show the login window
gp.player.login();
},
};
// Example of a BUTTON controller for showing the player's profile modal window
const buttonOpenProfileModal = {
show() {
// Show the button in the game
},
onClick() {
// Open the player's profile modal window
profileModal.open();
},
};
// The game is launched
function onGameStart() {
// Wait for the login event
gp.player.on('login', (success) => {
if (success) {
// Close the player's profile window
profileModal.close();
// Update the interface with player data
game.reloadUserUI();
} else {
// No need to handle errors, they are handled in our UI or platform UI
// The only reason for failure may be the player closing the authorization window
}
});
// Check if the platform supports authorization
if (gp.platform.hasIntegratedAuth) {
// Show the button for logging in via platform authentication
buttonNativeAuth.show();
// Check if Authentication via secret code is available on the platform
} else if (gp.platform.isSecretCodeAuthAvailable) {
// Show the button to open the profile
buttonOpenProfileModal.show();
}
}
// Example coming soon
Stay in Touch
Other documents of this chapter available Here. To get started, welcome to the Tutorials chapter.
GamePush Community Telegram
: @gs_community.
For your suggestions e-mail
: [email protected]
We Wish you Success!