Photon Secret Key is visible in Error Log?

Options
2»

Answers

  • AllFatherGray
    Options
    @JohnTube

    Thanks, I was missing the JSON option.
    Now I've correctly received a response (200 OK) from Postman.

    What are the next steps to get this behaviour in Unity?

    The CustomAuth fails when I attempt to connect via:
    PhotonNetwork.ConnectUsingSettings();
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options

    what is the error message in OnCustomAuthenticationFailed?
    also share the client code and what you expect from the CloudScript.

  • AllFatherGray
    AllFatherGray ✭✭
    edited October 2020
    Options
    @JohnTube

    EDIT:
    I was using this as a guide:
    https://docs.microsoft.com/en-us/gaming/playfab/sdks/photon/quickstart


    I get this before the error occurs.
    PlayFab + Photon Example: Photon token acquired: qc4ukeqedcmgxdqutwibq8ie8mr4ipntne7bc64nte7tbocdp1  Authentication complete.
    

    Then, I get the error below when I try to connect.
    END EDIT

    This is the error message I get.
    OperationResponse 230: ReturnCode: 32755 (Custom authentication got empty response string.). Parameters: {} Server: NameServer Address: ns.exitgames.com:5058
    UnityEngine.Debug:LogError(Object)
    Photon.Realtime.LoadBalancingClient:DebugReturn(DebugLevel, String) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2393)
    Photon.Realtime.LoadBalancingClient:OnOperationResponse(OperationResponse) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2467)
    ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(StreamBuffer)
    ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
    ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
    Photon.Pun.PhotonHandler:Dispatch() (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:208)
    Photon.Pun.PhotonHandler:FixedUpdate() (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:142)
    

    In the cloudscript I am doing this as a quick test:
     return { ResultCode: 1, AuthCookie:  { secret: "secret" } };
    


    This is the code in the client:
    LogMessage("Photon token acquired: " + obj.PhotonCustomAuthenticationToken + "  Authentication complete.");
    
            //We set AuthType to custom, meaning we bring our own, PlayFab authentication procedure.
            var customAuth = new AuthenticationValues();
            customAuth.AuthType = CustomAuthenticationType.Custom;
            //We add "username" parameter. Do not let it confuse you: PlayFab is expecting this parameter to contain player PlayFab ID (!) and not username.
            customAuth.AddAuthParameter("username", _playFabPlayerIdCache);    // expected by PlayFab custom auth service
            customAuth.AddAuthParameter("UserId", _playFabPlayerIdCache);
    
            //We add "token" parameter. PlayFab expects it to contain Photon Authentication Token issues to your during previous step.
            customAuth.AddAuthParameter("Token", obj.PhotonCustomAuthenticationToken);
    
            string ticket = PlayFabSettings.staticPlayer.ClientSessionTicket;
            customAuth.AddAuthParameter("Ticket", ticket);
    
            customAuth.AddAuthParameter("AppVersion", PhotonNetwork.PhotonServerSettings.AppSettings.AppVersion);
            customAuth.AddAuthParameter("AppId", PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime);
            //We finally tell Photon to use this authentication parameters throughout the entire application.
            PhotonNetwork.AuthValues = customAuth;
    

    Later, I try to join photon using:
    PhotonNetwork.PhotonServerSettings.AppSettings.AppVersion = "1.0";
    PhotonNetwork.PhotonServerSettings.AppSettings.FixedRegion =  "us";
    PhotonNetwork.ConnectUsingSettings();
    


    The call to Postman works. I get the response from cloudscript.
    And if I change the URL on the PhotonDashboard back to the old version (https://{title}.playfabapi.com/photon/authenticate) , it works as expected.

    So only this new URL in Photon Unity gives me the error.

    Versions of software:

    Unity : 2019.4.12f1
    PUN : 2.22
    Photon lib : 4.1.4.5
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited October 2020
    Options
    sorry my bad
    we should send POST custom auth request.
    so we should set a payload.

    I went back to the project I used to test this and found out how I did it back then (it's PUN Classic as PUN 2 did not exist back then but it works in the same way, this is irrelevant here):
             /*
        * Step 2
        * We request Photon authentication token from PlayFab.
        * This is a crucial step, because Photon uses different authentication tokens
        * than PlayFab. Thus, you cannot directly use PlayFab SessionTicket and
        * you need to explicitely request a token. This API call requires you to 
        * pass Photon App ID. App ID may be hardcoded, but, in this example,
        * We are accessing it using convenient static field on PhotonNetwork class
        * We pass in AuthenticateWithPhoton as a callback to be our next step, if 
        * we have acquired token succesfully
        */
        private void RequestPhotonToken(LoginResult obj)
        {
            LogMessage("PlayFab authenticated. Requesting photon token...");
    
            //We can player PlayFabId. This will come in handy during next step
            _playFabPlayerIdCache = obj.PlayFabId;
            _playFabSessionTokenCache = obj.SessionTicket;
    
            PlayFabClientAPI.GetPhotonAuthenticationToken(new GetPhotonAuthenticationTokenRequest()
            {
                PhotonApplicationId = PhotonNetwork.PhotonServerSettings.AppID
            }, AuthenticateWithPhoton, OnPlayFabError);
        }
    
         /*
         * Step 3
         * This is the final and the simplest step. We create new AuthenticationValues instance.
         * This class describes how to authenticate a players inside Photon environment.
         */
        private void AuthenticateWithPhoton(GetPhotonAuthenticationTokenResult obj)
        {
            LogMessage("Photon token acquired: " + obj.PhotonCustomAuthenticationToken + "  Authentication complete.");
    
            //We set AuthType to custom, meaning we bring our own, PlayFab authentication procedure.
            var customAuth = new AuthenticationValues { AuthType = CustomAuthenticationType.Custom };
    
            ////We add "username" parameter. Do not let it confuse you: PlayFab is expecting this parameter to contain player PlayFab ID (!) and not username.
            //customAuth.AddAuthParameter("username", _playFabPlayerIdCache);    // expected by PlayFab custom auth service
    
            ////We add "token" parameter. PlayFab expects it to contain Photon Authentication Token issues to your during previous step.
            //customAuth.AddAuthParameter("token", obj.PhotonCustomAuthenticationToken);
    
            Dictionary<string, object> data = new Dictionary<string, object>(5);
            data["UserId"] = _playFabPlayerIdCache;
            data["AppId"] = PhotonNetwork.PhotonServerSettings.AppID;
            data["AppVersion"] = string.Format("{0}_{1}", this.appVersion, PhotonNetwork.versionPUN); //PhotonNetwork.networkingPeer.AppVersion;
            data["Ticket"] = _playFabSessionTokenCache;// + "x";
            data["Token"] = obj.PhotonCustomAuthenticationToken;
            customAuth.SetAuthPostData(data);
    
            //We finally tell Photon to use this authentication parameters throughout the entire application.
            PhotonNetwork.AuthValues = customAuth;
            PhotonNetwork.ConnectUsingSettings(appVersion);
        }
    

    replace the dictionary key values with your own.
  • AllFatherGray
    Options
    @JohnTube

    I still have an issue but your advice to switch to POST did the trick, I had to change:
    data["AppVersion"] = string.Format("{0}_{1}", this.appVersion, PhotonNetwork.versionPUN);
    

    because it was throwing errors. versionPUN didn't exist.

    I changed it to:
    data["AppVersion"] = string.Format("{0}_{1}", PhotonNetwork.PhotonServerSettings.AppSettings.AppVersion, PhotonNetwork.PunVersion);
    

    And I get a successful response when I return code == 1 in the CustomAuth.

    However, when I add the rest of the code in the git, I receive errors:
    OperationResponse 230: ReturnCode: 32755 (undefined: undefined). Parameters: {} Server: NameServer Address: ns.exitgames.com:5058
    

    I have debug messages before and after:
            let appId = args.AppId;
            let userId = args.UserId;
            let appVersion = args.AppVersion;
    

    But the error seems to occur before the assignments above are finished. Any ideas?
  • AllFatherGray
    AllFatherGray ✭✭
    edited October 2020
    Options
    @JohnTube

    Found the issues!

    First, all TitleWriteEvents must not contain special-characters and have a length < = 64.
    Second, although Photon uses a key 'ResultCode' the AuthResponse uses 'resultCode'

    So:
    if (authRes.ResultCode !== 1)
    

    Should become:
    if (authRes.resultCode !== 1)
    

    Doing that fixed bug.

    EDIT: The fix above is for:
    https://gist.github.com/JohnTube/122568b1183db131d50f5f17935ee21a
  • AllFatherGray
    AllFatherGray ✭✭
    edited November 2020
    Options
    @JohnTube

    Hello, I have another question, I get null errors when using URLTags like here:
    https://doc.photonengine.com/en-us/pun/v2/gameplay/web-extensions/webrpc#response

    What is the proper why to use this? I am looking to use the {Region} tag.
    Is this feature deprecated? I notice the Region key is already present in 'args' parameter despite the documents.

    EDIT:
    Earlier you said:

    "Just a note/reminder:
    PathClose cannot have an AuthCookie, so this one you should check validity by making sure all the args are there as expected and their values are valid. Then see if the GameId closed is currently marked as open/ongoing."

    How do I check if a game is "open/ongoing"?
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @AllFatherGray,

    hmm

    URL tags may not be officially supported by PlayFab integration.
    I will have to test possible workarounds.
    Yes Region is a URL tag and a webhooks/webRPC arg.

    ---

    To check if a game is on going, simply mark it or flag as on going or open in your backend (PlayFab in this case) when you get PathCreate.
  • AllFatherGray
    Options
    @JohnTube

    Ok, I will check in here in a week the latest.
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    The only hacky workaround is to use URL tags as handler name.
    Other than that you can't use them in the path as URL slug nor query string parameters.
    So I would say that you should avoid them as you can live without them and if you want you can what you need from the client anyway as POST payload (JSON property).
  • AllFatherGray
    Options
    @JohnTube

    I couldn't get PathClose to trigger when a room closed.
    Is this still a feature?
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Hi @AllFatherGray,

    PathClose is triggered when a room is removed from Photon servers.
    A room is removed from Photon servers after it becomes empty and the EmptyRoomTtl (milliseconds) expires.
  • AllFatherGray
    Options
    @JohnTube

    Thanks! It was an error with a tutorial that had 'RoomClose' when Playfab had 'RoomClosed'