Photon Pun Unity - Bad Request

Goodmorning/evening,

I am currently using Photon Pun for implementing Facebook and Epic external authentication, but i am encountering some problem related to Photon Server Response. It seems that Photon connect to server but it responds with a bad request error:

"Error authenticating to Photon using Facebook: The remote server returned an error: (400) Bad Request."

"OperationResponse 230: ReturnCode: 32755 (The remote server returned an error: (400) Bad Request.). Parameters: {} Server: NameServer Address: ns.photonengine.io:5058"

For the sake of simplicity, i have only worked with facebook and it seems that appId is fine, Access Token is fine, client token is fine and also the client secret. I can't understand what's going on, so i'll paste the entire authentication code here. I apology for the mess, it is still a workd in progress:

using System.Collections;

using Epic.OnlineServices;

using Epic.OnlineServices.Auth;

using Epic.OnlineServices.Logging;

using Epic.OnlineServices.Platform;

using System.Collections.Generic;

using System;

using System.Runtime.InteropServices;

using UnityEngine;

using UnityEngine.UI;

using Photon.Pun;

using Photon.Realtime;

using TMPro;

using Facebook.Unity; //import facebook sdk

public class AuthenticationManager : MonoBehaviourPunCallbacks

{

    #region EPIC ONLINE SERVICE VARIABLES

    public string m_ProductName = "MyUnityApplication";

    public string m_ProductVersion = "1.0";

    public string m_ProductId = "";

    public string m_SandboxId = "";

    public string m_DeploymentId = "";

    public string m_ClientId = "";

    public string m_ClientSecret = "";

    public LoginCredentialType m_LoginCredentialType = LoginCredentialType.AccountPortal;

    // These fields correspond to \<see cref="Credentials.Id" /> and \<see cref="Credentials.Token" />,

    // and their use differs based on the login type. For more information, see \<see cref="Credentials" />

    // and the Auth Interface documentation.

    public string m_LoginCredentialId = null;

    public string m_LoginCredentialToken = null;


    private static PlatformInterface s_PlatformInterface;

    private const float c_PlatformTickInterval = 0.1f;

    private float m_PlatformTickTimer = 0f;

    private bool showConnectionStatus = false;



    InitializeOptions initializeOptions;

    Result initializeResult;

    Options options;

    LoginOptions loginOptions;

    #endregion


    [Header("Profile Interface Objects")]

    public GameObject profilePicture_obj;

    public GameObject profileNickname_obj;

    public GameObject profileEmail_obj;


    [Header("UI interfaces")]

    public GameObject uI_Profile;

    public GameObject uI_connectionStatus;

    public GameObject uI_Authentication;

    public GameObject anonAuth_Panel;

    public GameObject profileBackgroundIcon_obj;

    public TMP_InputField playerNameInputField;

    private static Sprite defaultProfileIcon;

    public TMP_Text connectionStatusText;

    void Start()

    {

        defaultProfileIcon = profileBackgroundIcon_obj.GetComponent<Sprite>();

        initializeOptions = new InitializeOptions()

        {

            ProductName = m_ProductName,

            ProductVersion = m_ProductVersion

        };


        initializeResult = PlatformInterface.Initialize(ref initializeOptions);

        if (initializeResult != Result.Success)

        {

            #if UNITY_EDITOR

            Debug.Log("Failed to initialize platform: " + initializeResult);

            #else

            throw new Exception("Failed to initialize platform: " + initializeResult);

            #endif

        }


        // The SDK outputs lots of information that is useful for debugging.

        // Make sure to set up the logging interface as early as possible: after initializing.

        LoggingInterface.SetLogLevel(LogCategory.AllCategories, LogLevel.VeryVerbose);

        LoggingInterface.SetCallback((ref LogMessage logMessage) => Debug.Log(logMessage.Message));


        options = new Options()

        {

            ProductId = m_ProductId,

            SandboxId = m_SandboxId,

            DeploymentId = m_DeploymentId,

            ClientCredentials = new ClientCredentials()

            {

                ClientId = m_ClientId,

                ClientSecret = m_ClientSecret

            }

        };      

    }

     

    public static void logOutFromAuth()

    {

        if(FB.IsLoggedIn)

        {

            FB.LogOut();

            PhotonNetwork.Disconnect();

            //GameObject.Find("Profile_Icon").GetComponent<Image>().sprite = defaultProfileIcon;

        }

    }


    private void Update()

    {

        if (s_PlatformInterface != null)

        {

            m_PlatformTickTimer += Time.deltaTime;


            if (m_PlatformTickTimer >= c_PlatformTickInterval)

            {

                m_PlatformTickTimer = 0;

                s_PlatformInterface.Tick();

            }

        }

        if(showConnectionStatus)

        {

            connectionStatusText.text = "CONNECTION STATUS: " + PhotonNetwork.NetworkClientState;

        }

    }


    private void Awake()    

    {

         if (!FB.IsInitialized)

        {

            Debug.Log("FB is initializing");

            // Initialize the Facebook SDK

            FB.Init();

        }

    }


    #region "UI manager"

    public void OnFacebookAuthButtonClicked()

    {

        if (FB.IsLoggedIn)

        {

            OnFacebookLoggedIn();

        }

        else

        {

            var perms = new List<string>(){"public_profile", "email"};

            FB.LogInWithReadPermissions(perms, FBAuthCallback);

        }

    }


    public void OnEpicAuthButtonClicked()

    {

        if (!PhotonNetwork.IsConnected)

        {

            EpicLogin();

        }

    }


    public void OnAnonymousAuthButtonClicked()

    {

        if(!PhotonNetwork.IsConnected)

        {

            photonAnonymousLogin();

        }

    }

    #endregion


    #region "FACEBOOK callbacks"

    private void FBAuthCallback(ILoginResult result)

    {

        if (FB.IsLoggedIn)

        {

            OnFacebookLoggedIn();

        }

        else

        {

            Debug.LogErrorFormat("Error in Facebook login {0}", result.Error);

        }

    }


    private void OnFacebookLoggedIn()

    {

        // AccessToken class will have session details

        string aToken = AccessToken.CurrentAccessToken.TokenString;

        Debug.Log("ACCESS TOKEN FB: "+aToken );

        string facebookId = AccessToken.CurrentAccessToken.UserId;;

        PhotonNetwork.AuthValues = new AuthenticationValues();

        //use auth "Facebook" becaus the app permission asked are for fb application

        PhotonNetwork.AuthValues.AuthType = CustomAuthenticationType.Facebook;

        PhotonNetwork.AuthValues.UserId = facebookId; // alternatively set by server

        PhotonNetwork.AuthValues.AddAuthParameter("token", aToken);

        PhotonNetwork.ConnectUsingSettings();

        OnConnectedToMaster();

    }

    #endregion


    #region Epic Games Callback

    private void EpicLogin()

    {  

        s_PlatformInterface = PlatformInterface.Create(ref options);

        if (s_PlatformInterface == null)

        {

            throw new Exception("Failed to create platform");

        }

        loginOptions = new LoginOptions()

        {

            Credentials = new Credentials()

            {

                Type = m_LoginCredentialType,

                Id = m_LoginCredentialId,

                Token = m_LoginCredentialToken

            }

        };  

       

        // Ensure platform tick is called on an interval, or this will not callback.

        s_PlatformInterface.GetAuthInterface().Login(ref loginOptions, null, (ref LoginCallbackInfo loginCallbackInfo) =>

        {

            if (loginCallbackInfo.ResultCode == Result.Success)

            {

                Debug.Log("Login succeeded");                

                PhotonNetwork.AuthValues = new AuthenticationValues();

                //use auth "Epic" becaus the app permission asked are for epic games

                PhotonNetwork.AuthValues.AuthType = CustomAuthenticationType.Epic;

                PhotonNetwork.AuthValues.UserId = loginCallbackInfo.SelectedAccountId.ToString(); // alternatively set by server

                Debug.Log("EPIC ACCESS TOKEN: "+loginCallbackInfo);

                PhotonNetwork.AuthValues.AddAuthParameter("token", loginOptions.Credentials.Value.Token);

                PhotonNetwork.ConnectUsingSettings();

                OnConnectedToMaster();


            }

            else if (Common.IsOperationComplete(loginCallbackInfo.ResultCode))

            {

                Debug.Log("Login failed: " + loginCallbackInfo.ResultCode);

            }

        });        

    }

    #endregion


    #region Photon LogIn Anonymously

    private void photonAnonymousLogin()

    {

        string playerName = playerNameInputField.text;

        if(!string.IsNullOrEmpty(playerName))

        {

           

            showConnectionStatus = true;

            uI_connectionStatus.SetActive(true);

            PhotonNetwork.LocalPlayer.NickName = playerName;

            PhotonNetwork.ConnectUsingSettings();

        }

        else

        {

            Debug.Log("Player name is invalid or empty! "+ playerName);

        }

    }


    #endregion


    #region "PRIVATE methods"

    private void setAuthFieldsForProfileInterface()

    {

        if(FB.IsLoggedIn)

        {

            profilePicture_obj.GetComponent<Image>().sprite = profileBackgroundIcon_obj.GetComponent<Image>().sprite;

        }

    }


    private void GetFBPicture(IGraphResult result)

    {

        if (result.Error == null)

        {          

            Image img = profileBackgroundIcon_obj.GetComponent<Image>();

            img.sprite = Sprite.Create(result.Texture, new Rect(0,0, 700, 700), new Vector2());        

        }

        else

        {  

            Debug.Log("fb picture error: " + result.Error);

        }


    }

    private void GetFBFields(IGraphResult result)    

    {

        if (result.Error == null)

        {  

            Text txtEmail = profileEmail_obj.GetComponent<Text>();          

            Text txtName = profileNickname_obj.GetComponent<Text>();

            string name;


            if( result.ResultDictionary.TryGetValue("name", out name))

            {

                txtName.text = name;

                Debug.Log("username: "+name);

            }                  

        }

        else

        {

            Debug.LogError(result.Error);

        }

    }


    //close epic interface

    private void OnApplicationQuit()

    {

        if (s_PlatformInterface != null)

        {

            s_PlatformInterface.Release();

            s_PlatformInterface = null;

            PlatformInterface.Shutdown();

        }


    }

    #endregion


    #region OnConnection done methods

    public override void OnConnectedToMaster()

    {

        Debug.Log("Successfully connected to Photon!");

        showConnectionStatus = false;

        uI_connectionStatus.SetActive(false);

       

        uI_Authentication.SetActive(false);

        uI_Profile.SetActive(true);

    }


    public override void OnCustomAuthenticationFailed(string debugMessage)

    {

        Debug.LogErrorFormat("Error authenticating to Photon using "+PhotonNetwork.AuthValues.AuthType+": {0}", debugMessage);

    }

    #endregion

}

If you need other details, feel free to ask. Thanks in advance!

Best Regards,

A

Comments

  • You asked this somewhere else, correct? I know this is annoying but please don't cross post. It means we have to reply in several places (in best case).

    When you edit posts, select the code and use the formatting buttons on the left side of the input area.