#Error 403 while executing cloud code function

1 messages · Page 1 of 1 (latest)

red flame
#

Hi, I am trying to integrate cloud code functions but getting error 403 while doing so, I have already authenticated the user

Error:
HttpException: (403) HTTP/1.1 403 Forbidden
Unity.Services.CloudCode.Internal.Http.ResponseHandler.HandleAsyncResponse (Unity.Services.CloudCode.Internal.Http.HttpClientResponse response, System.Collections.Generic.Dictionary2[TKey,TValue] statusCodeToTypeMap) (at ./Library/PackageCache/com.unity.services.cloudcode@49bc6c02e205/Runtime/com.unity.services.cloudcode.internal/Http/ResponseHandler.cs:120) Unity.Services.CloudCode.Internal.Http.ResponseHandler.HandleAsyncResponse[T] (Unity.Services.CloudCode.Internal.Http.HttpClientResponse response, System.Collections.Generic.Dictionary2[TKey,TValue] statusCodeToTypeMap) (at ./Library/PackageCache/com.unity.services.cloudcode@49bc6c02e205/Runtime/com.unity.services.cloudcode.internal/Http/ResponseHandler.cs:226)
Unity.Services.CloudCode.Internal.Apis.CloudCode.CloudCodeApiClient.RunModuleAsync (Unity.Services.CloudCode.Internal.CloudCode.RunModuleRequest request, Unity.Services.CloudCode.Internal.Configuration operationConfiguration) (at ./Library/PackageCache/com.unity.services.cloudcode@49bc6c02e205/Runtime/com.unity.services.cloudcode.internal/Apis/CloudCodeApi.cs:138)
Unity.Services.CloudCode.CloudCodeInternal.GetModuleResponseAsync (System.String module, System.String function, System.Collections.Generic.Dictionary`2[TKey,TValue] args) (at

#

./Library/PackageCache/com.unity.services.cloudcode@49bc6c02e205/Runtime/CloudCode.cs:243)
Unity.Services.CloudCode.CloudCodeInternal.GetRunModuleScriptResponse (System.String module, System.String function, System.Collections.Generic.Dictionary2[TKey,TValue] args) (at ./Library/PackageCache/com.unity.services.cloudcode@49bc6c02e205/Runtime/CloudCode.cs:137) Rethrow as CloudCodeException: Unknown HTTP/1.1 403 Forbidden Unity.Services.CloudCode.CloudCodeInternal.GetRunModuleScriptResponse (System.String module, System.String function, System.Collections.Generic.Dictionary2[TKey,TValue] args) (at ./Library/PackageCache/com.unity.services.cloudcode@49bc6c02e205/Runtime/CloudCode.cs:153)
Unity.Services.CloudCode.CloudCodeInternal.CallModuleEndpointAsync[TResult] (System.String module, System.String function, System.Collections.Generic.Dictionary`2[TKey,TValue] args) (at ./Library/PackageCache/com.unity.services.cloudcode@49bc6c02e205/Runtime/CloudCode.cs:60)
Unity.Services.CloudCode.GeneratedBindings.ELUserDetailsModuleBindings.GetUserData () (at Assets/CloudCode/GeneratedModuleBindings/ElebendCloud/ELUserDetailsModuleBindings.cs:39)
Elebend.Managers.ELCloudDataManager.Refresh () (at Assets/Elebend/Scripts/Managers/ELCloudDataManager.cs:20)
Elebend.UI.Screen.ELTitleScreen.<InitializeUgs>g__PlayerSignedIn|12_0 (System.Boolean success, System.String message) (at Assets/Elebend/Scripts/UI/Screen/ELTitleScreen.cs:86)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) (at <1eb9db207454431c84a47bcd81e79c37>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <07c12a9d8ce247d18a35c5e3e7bb065f>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <07c12a9d8ce247d18a35c5e3e7bb065f>:0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <07c12a9d8ce247d18a35c5e3e7bb065f>:0)

worn root
#

What is the code that results in this?

red flame
#

Client code

using System.Collections.Generic;
using System.Threading.Tasks;
using Elebend.Utility.Log;
using Unity.Services.CloudCode;
using Unity.Services.CloudCode.GeneratedBindings;
using Unity.Services.CloudCode.GeneratedBindings.ElebendShared;
using Unity.Services.CloudSave;

namespace Elebend.Managers
{
    public class ELCloudDataManager : ELSingletonMonoBehavior<ELCloudDataManager>
    {
        public ELUserData UserData { get; private set; }
        
        private ELUserDetailsModuleBindings _userDetailsBindings;

        public async Task Refresh()
        {
            _userDetailsBindings = new ELUserDetailsModuleBindings(CloudCodeService.Instance);
            UserData = await _userDetailsBindings.GetUserData();
        }

        public async Task ChangeUserName(string newUserName)
        {
            await _userDetailsBindings.ChangeUserName(newUserName);
            await Refresh();
        }
        
        private async Task<T> RetrieveSpecificData<T>(string key)
        {
            try
            {
                var results = await CloudSaveService.Instance.Data.Player.LoadAsync(
                    new HashSet<string> { key }
                );

                if (results.TryGetValue(key, out var item))
                {
                    return item.Value.GetAs<T>();
                }

                ELLog.Log(ELLogCategory.Cloud, $"There is no such key as {key}!");
            }
            catch (CloudSaveValidationException e)
            {
                ELLog.LogError(ELLogCategory.Cloud, e);
            }
            catch (CloudSaveRateLimitedException e)
            {
                ELLog.LogError(ELLogCategory.Cloud, e);
            }
            catch (CloudSaveException e)
            {
                ELLog.LogError(ELLogCategory.Cloud, e);
            }

            return default;
        }
    }
}
red flame
viral mason
#

403 is a permissions error. Is Refresh() being run on the clients?

red flame
#

I am also new to UGS itself so any basic mistake can also be there

red flame
viral mason
#

Dont bother with gpt. You'll need to make sure that Cloud Code services is enabled on the project Cloud Dashboard. Then make sure the project is linked in the editor Project Settings.

red flame
red flame
viral mason
#

Do the other cloud functions give the same error? or is it just Refresh()?

red flame
#

the other client function is also giving the same error but the function that is called by server itself is working

#

also I was using cloud save directly before it was also giving me same 403 forbidden

viral mason
#

double check AuthenticationService.Instance.IsAuthorized before you call the cloud functions

red flame
#

I checked and the user is authorized as well

viral mason
red flame
#

I have raised the ticket to unity will have to see their response