Authenticating Players with Unity

Authenticating Players with Unity #

When you are first starting out with LootLocker, the service’s feature set might seem a bit daunting at first. This page hopes to serve as a guide on how to get started, and help you understand how API calls are made and handled.

Player Verification #

Depending on the platforms your game will run on, we might require that the players verify their identity before you can register a session with LootLocker.

We currently require “Player Verification” on Steam and PSN. Verifying a Player requires that you get a token from the First Party Platform, that is then sent to LootLocker for verification with that First Party Platform. This lets LootLocker know to expect a new Session Registration request from this user.

Verifying a Player with Steam #

To verify a Player for Authentication with Steam, you first need to obtain an Auth Session Ticket from the Steam SDK by issuing a call to SteamUser.GetAuthSessionTicket(). See Steam’s documentation for more information on Session Tickets.

Here’s a small snippet that should help you achieve that:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
    uint ticketSize;
    m_Ticket = new byte[1024];
    m_HAuthTicket = SteamUser.GetAuthSessionTicket(m_Ticket, 1024, out ticketSize);
    
    Array.Resize(ref m_Ticket, (int)ticketSize);
    StringBuilder sb = new StringBuilder();
    for(int i=0; i < ticketSize; i++)
    {
    	sb.AppendFormat("{0:x2}", m_Ticket[i]);
    }
    
    var steamSessionTicket =  sb.ToString();

Once you have that ticket, and it’s turned into a string of hexadecimal numbers, the next step is to call the VerifyID function on the LootLocker SDK

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
    LootLockerSDKManager.VerifyID(steamSessionTicket, (response) =>
    {
        if (response.success)
        {
            Debug.Log("Successful");
        }
        else
        {
            Debug.Log("failed: " + response.Error);
        }
    });

Once you have successfully verified your Session Ticket, you are ready to register the players session with LootLocker. You do not need to store the result of this call anywhere. LootLocker knows to expect a Game Session call in the next 5 minutes.

Authenticating with LootLocker #

Now that we have successfully verified the Session Ticket with LootLocker, we are ready to register a Game Session. This call will return a lot of data that you can use to display to the Player or make more calls to LootLocker during this session.

You have 5 minutes to register a Game Session after a successful Player Verification response before you need to start over with a new Player Verification.

The SteamId64 is obtained by calling SteamUser.GetSteamID();.

This snippet will start a Game Session with LootLocker

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
    string labelText,steamId64;
    
    LootLockerSDKManager.StartSession(steamId64, (response) =>
    {
        if (response.success)
        {
            Debug.Log("Successful");
        }
        else
        {
            Debug.Log("failed: " + response.Error);
        }
    });

Besides the success boolean used in the snippet above, we also return a host of other data, such as the player’s ID, if they’ve been seen before etc. If you want to dive deeper into this SessionResponse, you can find the code for the SDK on GitHub.

What Now? #

Next up, we suggest you look at our feature set, and decide which ones you want to use.

If you want to store your players inventories with LootLocker (this allows us to enable a lot more features, such as granting assets to players on level up, when completing a mission, etc) a great next step is to read up on the Asset Manager.