question

brendan avatar image
brendan asked

photon integration with last updated PUN

A.in18dec
started a topic on Tue, 23 June 2015 at 9:00 PM

hi playfab,

recently photon made updates for pun,

it changes the SetAuthParameters, to AddAuthParameters

so, instead of call

PhotonNetwork.AuthValues.SetAuthParameters(playfabId,token)

I guess I have to call

PhotonNetwork.AuthValues.AddAuthParameter("username",playfabId);

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

But, it didnt work..

if you have a documentation for new updated PUN, it will be greatly appreciated

thank you,

[Wahyu]

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

Best Answer
Ryan.dj said on Thu, 25 June 2015 at 2:46 PM

simple fix mate heres my code

    {
PhotonNetwork.AuthValues = new AuthenticationValues ();
PhotonNetwork.AuthValues.AuthType = CustomAuthenticationType.Custom;
PhotonNetwork.AuthValues.AddAuthParameter ("username", playfabId);
PhotonNetwork.AuthValues.AddAuthParameter ("Token", result.PhotonCustomAuthenticationToken);
PhotonNetwork.AuthValues.UserId = playfabId;
PhotonNetwork.ConnectUsingSettings ("1.0");

}

all you need is a capital t for Token


6 Comments
A.in18dec said on Wed, 24 June 2015 at 12:53 AM

here is my code

using UnityEngine;
using System.Collections;

using PlayFab;
using PlayFab.ClientModels;
using PlayFab.Internal;
using PlayFab.Serialization;

public class playfabLogin : MonoBehaviour {

    public string PlayFabId;

    // Use this for initialization
    void Start () {
        PlayFabSettings.TitleId = "xxxx";
    }

    // Update is called once per frame
    void Update () {

    }

    public void loginPlayFab(){
        LoginWithPlayFabRequest request = new LoginWithPlayFabRequest ();
        request.Username = "user";
        request.Password = "pass";
        PlayFabClientAPI.LoginWithPlayFab (request,OnLoginResult,OnPlayFabError);
    }
    public void regPlayFab(){
        RegisterPlayFabUserRequest req = new RegisterPlayFabUserRequest ();
        req.Username = "user";
        req.Password = "pass";
        req.Email ="user@email.com";
        PlayFabClientAPI.RegisterPlayFabUser (req, regSuc, OnPlayFabError);
    }
    void regSuc(RegisterPlayFabUserResult res){
        Debug.Log ("reg sukses");
    }
    void OnLoginResult(LoginResult result)
    {
        Debug.Log ("sukses");

        GetPhotonAuthenticationTokenRequest request = new GetPhotonAuthenticationTokenRequest ();
        request.PhotonApplicationId = "xxx";
        PlayFabId = result.PlayFabId;
        PlayFabClientAPI.GetPhotonAuthenticationToken (request, OnRequestTokenSuccess, OnPlayFabError);
    }

    void OnRequestTokenSuccess(GetPhotonAuthenticationTokenResult result){
        PhotonNetwork.AuthValues = new AuthenticationValues ();
        PhotonNetwork.AuthValues.AuthType = CustomAuthenticationType.Custom;
        PhotonNetwork.AuthValues.AddAuthParameter ("username", PlayFabId);
        PhotonNetwork.AuthValues.AddAuthParameter ("token", result.PhotonCustomAuthenticationToken);
        PhotonNetwork.AuthValues.UserId = PlayFabId;

        PhotonNetwork.ConnectUsingSettings ("1.0");

    }
    void OnConnectedToPhoton(){
        Debug.Log ("connected to photon");
    }

    void OnPlayFabError(PlayFabError error)
    {
        Debug.Log ("Got an error: " + error.ErrorMessage);
    }
}

and here is the error

Custom Authentication failed (either due to user-input or configuration or AuthParameter string format). Calling: OnCustomAuthenticationFailed()
UnityEngine.Debug:LogError(Object)
NetworkingPeer:OnOperationResponse(OperationResponse) (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/NetworkingPeer.cs:1147)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(Byte[])
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
PhotonHandler:Update() (at Assets/Photon Unity Networking/Plugins/PhotonNetwork/PhotonHandler.cs:83)

Ryan.dj said on Thu, 25 June 2015 at 2:46 PM

simple fix mate heres my code

    {
PhotonNetwork.AuthValues = new AuthenticationValues ();
PhotonNetwork.AuthValues.AuthType = CustomAuthenticationType.Custom;
PhotonNetwork.AuthValues.AddAuthParameter ("username", playfabId);
PhotonNetwork.AuthValues.AddAuthParameter ("Token", result.PhotonCustomAuthenticationToken);
PhotonNetwork.AuthValues.UserId = playfabId;
PhotonNetwork.ConnectUsingSettings ("1.0");

}

all you need is a capital t for Token


A.in18dec said on Thu, 25 June 2015 at 9:40 PM

Thanks for the answer,

I changed it and I still got the same error.

weird,

why is it working on your code but not on mine. :(


Ryan.dj said on Fri, 26 June 2015 at 2:27 PM

have you also put your app id in to photons setting in the editor ?

if not try that as when your connecting withPhotonNetwork.ConnectUsingSettings i will pull in the app id from the setting you set ?


A.in18dec said on Fri, 26 June 2015 at 8:10 PM

that's it..
after I updated PUN, the settings replaced with blank, then I put the wrong app id (from photon account).. stupid me..

thank you very much..

PS : the capital T in token is not necessary, it works with small t too..


johntube said on Thu, 13 August 2015 at 1:21 AM

To those having issues with Photon Custom Authentication read this check list first.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.