# Use Remote Login In-Game

Remote login makes it easy to start LootLocker sessions on devices where it's hard to enter their credentials, like on console. It also enables games to easily implement 1st party provider authentication without having to spend a long time manually implementing it into their game client.

## Pre-requisites

* [A game created in the LootLocker web console](https://docs.lootlocker.com/the-basics/readme)
* [Game is configured to use UPA](https://docs.lootlocker.com/players/unified-player-accounts)

## The Remote Login Flow

The remote login flow consists of the following steps:

* Initiate the remote login process, which will return a URL and QR code the player can use to log in
* The player visits the URL and logs in using their preffered identity provider
* Game client polls the server to check if the player has logged in yet
* Once the player has logged in, the poll will return a success response with a LootLocker session and a refresh token
* The next time the player opens the game, the refresh token can be used to start a new session without the player having to go through the full flow again

## Starting a Remote Session

{% tabs %}
{% tab title="Unity" %}
As this function requires three separate callbacks, it is easier to manage them as following:

```csharp
public void RemoteLease()
{
    LootLockerSDKManager.StartRemoteSession(leaseAction, pollingAction, onComplete);
}

Action<LootLockerLeaseRemoteSessionResponse> leaseAction = (info) =>
{
    if (!info.success)
    {
        Debug.Log("Couldnt start Remote leasing");
        return;
    }
};
Action<LootLockerRemoteSessionStatusPollingResponse> pollingAction = (polling) =>
{
    if(!polling.success)
    {
        Debug.Log("Couldnt poll Remote leasing");
        return;
    }
};
Action<LootLockerStartRemoteSessionResponse> onComplete = (onComplete) =>
{
    if (!onComplete.success)
    {
        Debug.Log("Couldnt start Remote leasing");
        return;
    }
};
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-f5ad181f2f96193b298674b3cb03bec0cb95569e%2Fimage.png?alt=media" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/t40l99zu/">Blueprint for Starting a Remote Session</a></p></figcaption></figure>
{% endtab %}

{% tab title="REST" %}
First we call the endpoint to start the process

```bash
curl -X POST "https://api.lootlocker.io/game/session/remote/lease" \
  -H "LL-Version: 2021-03-01" \
  -H "Content-Type: application/json" \
  -d "{\"game_key\": \"your_game_key\", \"game_version\": \"1.0.0.0\" }"
```

To Poll for updates we can use the same endpoint, but include `lease_code` and `nonce` in the body

```bash
curl -X POST "https://api.lootlocker.io/game/session/remote" \
  -H "LL-Version: 2021-03-01" \
  -H "Content-Type: application/json" \
  -d "{\"game_key\": \"your_game_key\", \"game_version\": \"1.0.0.0\", \"lease_code\": \"R9SJMK2R\", \"nonce\": \"01HE2TM1JWRTPCWQFBYJ538XCE\" }"
```

{% endtab %}
{% endtabs %}

## Cancel the remote login process

If we for some reason want to cancel the process mid way, this is how we can do it.

{% tabs %}
{% tab title="Unity" %}
`LootLockerSDKManager.StartRemoteSession` returns a Guid which we can later use to cancel the remote session start process.

```csharp
public void RemoteLease()
{
    var leasedGuid =  LootLockerSDKManager.StartRemoteSession(leaseAction, pollingAction, onComplete);
    LootLockerSDKManager.CancelRemoteSessionProcess(leasedGuid);
}
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-7f0c25366c16e1b00098eace02a86a6749555053%2Fimage.png?alt=media" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/ibgd3_i8/">Blueprint on Cancelling a Remote Session Process</a></p></figcaption></figure>
{% endtab %}
{% endtabs %}

## Use the Refresh Token to Start a Session

In the response while creating our remote session we get a refresh token back. This token can be used to start a new session without the player having to go through the full flow again.

{% tabs %}
{% tab title="Unity" %}

```csharp
LootLockerSDKManager.RefreshRemoteSession((onComplete) =>
{
    if(!onComplete.success)
    {
        Debug.Log("Couldnt refresh remote session!");
        return;
    }
});
```

With manually stored refresh token:

```csharp
string refreshToken = "";
LootLockerSDKManager.RefreshRemoteSession(refreshToken, (onComplete) =>
{
    if(!onComplete.success)
    {
        Debug.Log("Couldnt refresh remote session!");
        return;
    }
});
```

{% endtab %}

{% tab title="Unreal" %}

<figure><img src="https://534367586-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MVu1MPzezO-NgvC98xh%2Fuploads%2Fgit-blob-75ddcf0e646be61d35f76d41fc89e206e8072fe2%2Fue-bp-refresh-remote-session-example.png?alt=media" alt=""><figcaption><p><a href="https://blueprintue.com/blueprint/5tb6ofw0/">Blueprint on Refreshing a Remote Session</a></p></figcaption></figure>
{% endtab %}

{% tab title="REST" %}

```bash
curl -X POST "https://api.lootlocker.io/game/session/remote" \
  -H "LL-Version: 2021-03-01" \
  -H "Content-Type: application/json" \
  -d "{\"game_key\": \"your_game_key\", \"game_version\": \"1.0.0.0\", \"refresh_token\": \"v4.public.eyJ.....\" }"
```

{% endtab %}
{% endtabs %}

## Conclusion

In this how-to we've shown how to start and manage remote sessions from your game. If you want to learn more about UPA you can read about [Connected Accounts](https://docs.lootlocker.com/players/unified-player-accounts/how-to/connect-provider-to-player) or the general [Unified Player Account](https://docs.lootlocker.com/players/unified-player-accounts) page.
