Authentication Plugin Functions
Authentication is a top-level service based on Users and Devices tables that provide the ability to authenticate and authorize users and generate tokens for them. In the following, we will review the functions of authentication service in plugins:
Login with email
This function will login a player with pair of email and password, and return the token as result.
- Unity3D
- API
- TypeScript
ServiceHub.Authentication.LoginWithEmail(LoginWithEmailParams input);
curl --location 'https://link.dynamicpixels.dev/game/[CLIENT_ID]/api/auth/email/login' \
--header 'Content-Type: application/json' \
--data-raw '{
"email": "",
"password": "",
"device_info": {
"device_id": "[UNIQUE IDENTIFIER FOR USER]",
"first_login": null,
"last_login": null,
"package_name": null,
"sdk_version": "",
"version_name": null,
"version_code": null,
"os_api_lavel": null,
"device": null,
"from": null,
"model": null,
"product": null,
"carrier_name": null,
"manufacturer": null,
"other_tags": null,
"screen_width": null,
"screen_height": null,
"sdcard_state": null,
"game_orientation": null,
"network_type": "",
"mac_address": null,
"ip_address": null,
"device_name": "",
"device_model": "",
"device_type": "",
"operating_system": "",
"processor_type": "",
"processor_count": "",
"processor_frequency": "",
"graphic_device_name": "",
"graphic_device_vendor": "",
"graphic_memory_size": ""
}
}'
DynamicPixels.Auth.LoginWithEmail(input: LoginWithEmailParams): Promise<LoginResponse>;
Register with email
This function will register a new user and then login him in and return the token.
- Unity3D
- API
- TypeScript
ServiceHub.Authentication.RegisterWithEmail(RegisterWithEmailParams input);
curl --location 'https://link.dynamicpixels.dev/game/[CLIENT_ID]/api/auth/email/register' \
--header 'Content-Type: application/json' \
--data-raw '{
"version": 1,
"client_id": "[CLIENT_ID]",
"client_secret": "[CLIENT_SECRET]",
"name": "",
"email": "",
"password": ""
}'
DynamicPixels.Auth.RegisterWithEmail(input: RegisterWithEmailParams): Promise<LoginResponse>;
Login with Google
With this function, you can login user with Google Auth.
- Unity3D
- API
- TypeScript
ServiceHub.Authentication.LoginWithGoogle(LoginWithGoogleParams input);
curl --location 'https://link.dynamicpixels.dev/game/[CLIENT_ID]/api/auth/oauth/google' \
--header 'Content-Type: application/json' \
--data '{
"device_info": {
"device_id": "[UNIQUE IDENTIFIER FOR USER]",
"first_login": null,
"last_login": null,
"package_name": null,
"sdk_version": "",
"version_name": null,
"version_code": null,
"os_api_lavel": null,
"device": null,
"from": null,
"model": null,
"product": null,
"carrier_name": null,
"manufacturer": null,
"other_tags": null,
"screen_width": null,
"screen_height": null,
"sdcard_state": null,
"game_orientation": null,
"network_type": "",
"mac_address": null,
"ip_address": null,
"device_name": "",
"device_model": "",
"device_type": "",
"operating_system": "",
"processor_type": "",
"processor_count": "",
"processor_frequency": "",
"graphic_device_name": "",
"graphic_device_vendor": "",
"graphic_memory_size": ""
},
"access_token":"[TOKEN_FROM_GOOGLE_RESPONSE]"
}
'
DynamicPixels.Auth.LoginWithGoogle(input: LoginWithGoogleParams): Promise<LoginResponse>;
Login as guest
If you want to login users easily and don't show any form, guest login is for you! This function will login users with a unique id and mark the user as a guest. also, you can edit the user and add additional information in the future.
- Unity3D
- API
- TypeScript
ServiceHub.Authentication.LoginAsGuest(LoginAsGuestParams input);
curl --location 'https://link.dynamicpixels.dev/game/[CLIENT_ID]/api/auth/oauth/google' \
--header 'Content-Type: application/json' \
--data '{
"device_info": {
"device_id": "[UNIQUE IDENTIFIER FOR USER]",
"first_login": null,
"last_login": null,
"package_name": null,
"sdk_version": "",
"version_name": null,
"version_code": null,
"os_api_lavel": null,
"device": null,
"from": null,
"model": null,
"product": null,
"carrier_name": null,
"manufacturer": null,
"other_tags": null,
"screen_width": null,
"screen_height": null,
"sdcard_state": null,
"game_orientation": null,
"network_type": "",
"mac_address": null,
"ip_address": null,
"device_name": "",
"device_model": "",
"device_type": "",
"operating_system": "",
"processor_type": "",
"processor_count": "",
"processor_frequency": "",
"graphic_device_name": "",
"graphic_device_vendor": "",
"graphic_memory_size": ""
},
}
'
DynamicPixels.Auth.LoginAsGuest(input: LoginAsGuestParams): Promise<LoginResponse>;
Login with token
When you login with any function, a token will return that will be used in requests to the server to identify the user. you should save this token in a safe place and load it on every game startup. to prevent login in every game session, you should call this function and pass the saved token.
- Unity3D
- API
- TypeScript
ServiceHub.Authentication.LoginWithToken(LoginWithTokenParams input);
curl --location 'https://link.dynamicpixels.dev/game/[CLIENT_ID]/api/auth/login' \
--header 'Content-Type: application/json' \
--data '{
"token": "[USER_TOKEN]"
}'
DynamicPixels.Auth.LoginWithToken(input: LoginWithTokenParams): Promise<LoginResponse>;
Check OTA is ready
Check if OTA is available and developer can use it. you can fall back to other login ways if it's not available.
- Unity3D
- API
- TypeScript
ServiceHub.Authentication.IsOtaReady(new IsOtaReadyParams());
DynamicPixels.Auth.IsOtaReady(input: IsOtaReadyParams): Promise<boolean>;
Send OTA token
If OTA is ready, this function will generate a random key and send it as SMS to specified phone number. this key is valid for few minutes to verify.
- Unity3D
- API
- TypeScript
ServiceHub.Authentication.SendOtaToken(SendOtaTokenParams input);
curl --location 'https://link.dynamicpixels.dev/game/[CLIENT_ID]/api/auth/ota' \
--header 'Content-Type: application/json' \
--data '{
"phone_number": "+[USER PHONE NUMBER]"
}'
DynamicPixels.Auth.SendOtaToken(input: SendOtaTokenParams): Promise<boolean>;
Verify OTA token
After sending OTA key, you should get it by a form and verify it with this function. after that, login process will be done.
- Unity3D
- API
- TypeScript
ServiceHub.Authentication.VerifyOtaToken(VerifyOtaTokenParams input);
curl --location '' \
--header 'Content-Type: application/json' \
--data '{
"phone_number": "+[USER PHONE NUMBER]"
"name": "",
"token":"[SENT CODE]",
"device_info": {
"device_id": "[UNIQUE IDENTIFIER FOR USER]",
"first_login": null,
"last_login": null,
"package_name": null,
"sdk_version": "",
"version_name": null,
"version_code": null,
"os_api_lavel": null,
"device": null,
"from": null,
"model": null,
"product": null,
"carrier_name": null,
"manufacturer": null,
"other_tags": null,
"screen_width": null,
"screen_height": null,
"sdcard_state": null,
"game_orientation": null,
"network_type": "",
"mac_address": null,
"ip_address": null,
"device_name": "",
"device_model": "",
"device_type": "",
"operating_system": "",
"processor_type": "",
"processor_count": "",
"processor_frequency": "",
"graphic_device_name": "",
"graphic_device_vendor": "",
"graphic_memory_size": ""
},
}'
DynamicPixels.Auth.VerifyOtaToken(input: VerifyOtaTokenParams): Promise<LoginResponse>;
Is logged in
This function return status of user athenticating.
- Unity3D
- TypeScript
ServiceHub.Authentication.IsLoggenIn();
DynamicPixels.Auth.IsLoggedIn():boolean
Logout
This function closes all connections and forgets the user's token. then you can login another user.
- Unity3D
- TypeScript
ServiceHub.Authentication.Logout();
DynamicPixels.Auth.Logout():void