# Authentication Service (Player Accounts)

By default, the **CloudService** will automatically authenticate as a Guest User, unless you disable *Auto Login As Guest* option in the CoherenceBridge inspector.

If you disable the automatic login, you can handle Player authentication manually through the **CloudService.GameServices.AuthService** API.

In this example, you can see how you can manually login as a Guest:

```csharp
using Coherence.Cloud;
using Coherence.Toolkit;
using System.Collections;
using UnityEngine;
using Result = Coherence.Runtime.Result;

public class LoginAsGuestExample : MonoBehaviour
{
    public CoherenceBridge bridge;

    private CloudService cloudService;

    void Start()
    {
        cloudService = bridge.CloudService;

        StartCoroutine(CheckRefreshLogin());
    }

    private IEnumerator CheckRefreshLogin()
    {
        IAuthClient authService = cloudService.GameServices.AuthService;

        while (!cloudService.IsConnectedToCloud && authService.SessionTokenRefreshResult == null)
        {
            yield return null;
        }

        // If refresh failed, we have to login as a guest again
        if (authService.SessionTokenRefreshResult == Result.InvalidCredentials)
        {
            var task = authService.LoginAsGuest();

            while (!task.IsCompleted)
            {
                yield return null;
            }
        }

        // At this point, we are ready to fully utilize the Cloud Service
    }
}
```

You can also choose to allow your users to create their own Player accounts, you can use the Authentication Service API in a similar fashion to allow for manual authentication:

```csharp
using Coherence.Cloud;
using Coherence.Toolkit;
using System.Collections;
using UnityEngine;
using Result = Coherence.Runtime.Result;

public class LoginAsUserExample : MonoBehaviour
{
    public CoherenceBridge bridge;

    public string username;
    public string password;

    private CloudService cloudService;

    void Start()
    {
        cloudService = bridge.CloudService;

        StartCoroutine(LoginAsAUser());
    }

    private IEnumerator LoginAsAUser()
    {
        IAuthClient authService = cloudService.GameServices.AuthService;

        while (!cloudService.IsConnectedToCloud && authService.SessionTokenRefreshResult == null)
        {
            yield return null;
        }

        // If refresh failed, we have to login as a user with the given credentials again
        if (authService.SessionTokenRefreshResult == Result.InvalidCredentials)
        {
            var task = authService.LoginWithPassword(username, password, true);

            while (!task.IsCompleted)
            {
                yield return null;
            }
        }

        // At this point, we are ready to fully utilize the Cloud Service
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.coherence.io/1.0/coherence-cloud/using-coherence-cloud-in-unity/game-services/authentication-service-player-accounts.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
