メインコンテンツまでスキップ

デバイス ID でのログインを実装する

Last updated on November 1, 2024

Overview

You can use a device ID—such as computer's serial number, the International Mobile Equipment Identity (IMEI) of a mobile device, or another unique device identifier—to log into AccelByte Gaming Services (AGS) and gain access to its features. Device ID logins don't require account credentials, making them ideal for getting up and running quickly, and can be used for testing purposes or mobile games.

This guide will show you how to implement device ID logins into your game.

Warning

AccelByte recommends using more secure login methods for shipped games. Use caution if you intend to use this login method after your game is released.

Prerequisites

To complete this guide, you will need:

  • To have completed the previous Getting Started guides.
  • An Unreal or Unity project.

Configure a login method in the Admin Portal

You need to set up a login method in the AGS Admin Portal so you can connect it to your project.

  1. From the AGS Admin Portal dashboard under your project's game namespace, go to Game Setup > 3rd Party Configuration > Auth & Account Linking.

  2. On the Login Methods page, click on the + Add New button.

  3. From the list of login methods, select the Device.

  4. On the pop-up, fill in the Redirect URI field with http://127.0.0.1. This is the only field you need to fill in. Once done, click Create.

  5. On the Login Platform Configuration page, verify the Status is set to ACTIVE. If it's not, click Activate next to Integration, and confirm on the activation on the pop-up that appears.

Your login method has been configured in the AGS Admin Portal.

Implement device ID logins into your game

Paste the code below for your chosen engine wherever you intend to call your logins.

注記

Be sure to #include the following libraries wherever you integrate the device ID logins code:

  • #include "OnlineSubsystemAccelByte.h"
  • #include "OnlineSubsystemAccelByteTypes.h"
  • #include "OnlineIdentityInterfaceAccelByte.h"
IOnlineSubsystem* Subsystem = IOnlineSubsystem::Get(ACCELBYTE_SUBSYSTEM);
ensure(Subsystem != nullptr);

FOnlineIdentityAccelBytePtr IdentityInterface = nullptr;
ensure(FOnlineIdentityAccelByte::GetFromSubsystem(Subsystem, IdentityInterface));

int32 LocalUserNum = 0;
FOnlineAccountCredentialsAccelByte Credentials{ EAccelByteLoginType::DeviceId, TEXT(""), TEXT("") };
// Login
IdentityInterface->AddOnLoginCompleteDelegate_Handle(LocalUserNum
, FOnLoginCompleteDelegate::CreateLambda([](int32 LocalUserNum, bool bLoginWasSuccessful, const FUniqueNetId& UserId, const FString& LoginError)
{
if (bLoginWasSuccessful)
{
// Do something when player successfully logged in
}
else
{
// Do something when player failed to log in
}
})
);
IdentityInterface->Login(LocalUserNum, Credentials);

Test device ID login implementation

Write log messages in the code comments for success and failure, play your game, and test your login integration. If the log message for success appears, congratulations! You have implemented device ID logins and fully integrated AGS into your project!

You are now ready to explore and implement other AGS offerings into your game. Check out the Services section for detailed information on AGS features, or jump right in and start integrating more by following our step-by-step How-to guides.