Getting "Session Timeout" after calling UserService.GetUserRoles() when logged in as a guest

Backendless Version (3.x / 5.x, Online / Managed / Pro )

Online

Client SDK (REST / Android / Objective-C / Swift / JS )

REST

Application ID

BB06653B-4C8B-B7B2-FF32-B59686641800

Expected Behavior

  1. Log in as a guest using rest api which returns a valid guest user
  2. Call Backendless.UserService.GetUserRoles();
  3. Examine user roles

Actual Behavior

  1. Log in as a guest using rest api which returns a valid guest user
  2. Call Backendless.UserService.GetUserRoles();
  3. Get error response “Session timeout. Url: http://leaguelinkapp.com/api/BB06653B-4C8B-B7B2-FF32-B59686641800/5619D30B-4B20-461E-A0DA-A0BA32782D89/page/session_expiration/index.html

Hello @Sevren_Brewer

Please help me reproduce your problem.

This is how I tried to reproduce:

  1. Log in as a guest using rest api which returns a valid guest user

Guest Login
Request:
POST - https://api.backendless.com/application-id/REST-api-key/users/register/guest
Answer:

{
    "userStatus": "GUEST",
    "user-token": "7BE1EA05-C4C2-45E7-8D4E-955858D29DCB",
    "objectId": "E38D0386-0EDA-4476-BAC5-55B186D7EF6D"
}
  1. Call Backendless.UserService.GetUserRoles ();

From your example, I assumed that you are making this call from Android SDK
Security and User Roles
List roles = Backendless.UserService.getUserRoles ();

  1. Examine user roles

roles = [AndroidUser, NotAuthenticatedUser]

Perhaps point number 2 should have been like this:
Backendless REST API Documentation Security and User Roles
GET - https://api.backendless.com/application-id/REST-api-key/users/userroles
Request Headers
user-token: value-of-the-user-token-header-from-login

I’m sorry, I didn’t mention my environment in the post at all. This is a Xamarin application so step 1 is using REST and step 2 is the .NET API. But I like your mention of getting user roles via the REST api. I try and avoid the .NET api as much as possible, for me it does not work well. I was getting lots of hangups and timeouts so I transitioned to REST.

Do you do anything with the user token value received from step 1? Because if you do not, the second step will have no identity established in step 1.

I do store the token of the guest user for use in the header of later rest calls but that happens after I call for user roles. Here is the entirety of the code path.

    private async Task LoginWithCode()
    {
        try
        {
            UserDialogs.Instance.ShowLoading("Logging in...");

            await SecureStorage.SetAsync("SignInCode", SignInCode);

            if (string.IsNullOrEmpty(SignInCode))
            {
                UserDialogs.Instance.HideLoading();
                UserDialogs.Instance.Alert($"Login in code required");
                return;
            }

            var (error, guest) = await _webService.LoginAsGuest<GuestWebDataModel>();
            if (error.DidFault == false)
            {
                var userRoles = Backendless.UserService.GetUserRoles();

                foreach (var role in userRoles)
                {
                    System.Diagnostics.Debug.WriteLine($"User roles guest - {role}");
                }
                await SecureStorage.SetAsync("guest-user-token", guest.UserToken);
            }
            else
            {
                UserDialogs.Instance.Alert(error.Message, "Error");
                return;
            }

            var player = await _webService.Count<PlayerWebDataModel>($"{nameof(PlayerWebDataModel.SignInCode)} = '{SignInCode}'", BackendlessWebService.TokenOption.Guest);
            if (player.count == 1)
            {
                Analytics.TrackEvent("Player login");
                await SecureStorage.SetAsync("SignInCode", SignInCode);
                UserDialogs.Instance.HideLoading();
                await Shell.Current.GoToAsync($"//../{nameof(PlayersViewPage)}");

                return;
            }

            var coach = await _webService.Count<CoachWebDataModel>($"{nameof(CoachWebDataModel.SignInCode)} = '{SignInCode}'", BackendlessWebService.TokenOption.Guest);
            if (coach.count == 1)
            {
                Analytics.TrackEvent("Coach login");
                await SecureStorage.SetAsync("SignInCode", SignInCode);
                UserDialogs.Instance.HideLoading();
                await Shell.Current.GoToAsync($"//../{nameof(PlayersViewPage)}");

                return;
            }

            UserDialogs.Instance.Alert("No user found for this sign in code. Please contact your admin.", "Error");
        }
        catch (Exception ex)
        {
            UserDialogs.Instance.HideLoading();
            Backendless.Logging.GetLogger("exception_logger").Error("LoginWithCode", ex);
            UserDialogs.Instance.Alert(ex.Message, "Error");
        }
    }


    public async Task<(BackendlessError error, T guest)> LoginAsGuest<T>()
    {
        if (CheckConnection() == false)
        {
            return (BackendlessError.NoInternet(), default);
        }

        using (var client = new HttpClient())
        {
            await ConfigureClient(client, TokenOption.None);

            string response = "";
            try
            {
                HttpResponseMessage responseMessage = await client.PostAsync($"{ApiBaseAddress}/users/register/guest", null).ConfigureAwait(false);
                response = await responseMessage.Content.ReadAsStringAsync();
                try
                {
                    var errorResult = JsonConvert.DeserializeObject<IDictionary<string, object>>(response);

                    return (BackendlessError.New(errorResult["code"].ToString(), message: errorResult["message"].ToString(), true), Activator.CreateInstance<T>());
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Expected error on api fault:" + ex);
                }

                var result = JsonConvert.DeserializeObject<T>(response, GetJsonSettings());

                return (BackendlessError.Empty(), result);
            }
            catch (Exception ex)
            {
                _crashManager.Track(ex);
                return (BackendlessError.Empty(), Activator.CreateInstance<T>());
            }
        }
    }

Hello @Sevren_Brewer!

I have been unable to reproduce your error using the .NETSDK.

  1. I called the Backendless.UserService.LoginAsGuest () method.
  2. the following: Backendless.UserService.GetUserRoles ();
  3. Received information without errors.

Give me more information to reproduce this error.

Regards, Nikita.