Separate or single authentication for photon realtime and photon chat?
Options
avimon
✭
in Photon Chat
Hello,
I would like to ask do need to separately authenticate photon realtime and photon chat or both are done using this:
I would like to ask one more thing, since I have created another application for chat in photon dashboard, do I have to set custom server authentication for chat application too or only setting in photon realtime application is enough.
I would like to ask do need to separately authenticate photon realtime and photon chat or both are done using this:
private void RequestPhotonToken(PFLoginResult result) { Debug.Log("PlayFab authenticated. Requesting photon token..."); _playFabPlayerId = result.PlayFabId; PlayFabClientAPI.GetPhotonAuthenticationToken(new GetPhotonAuthenticationTokenRequest() { PhotonApplicationId = PhotonNetwork.PhotonServerSettings.AppID }, AuthenticateWithPhoton, OnPlayFabError); } private void AuthenticateWithPhoton(GetPhotonAuthenticationTokenResult obj) { Debug.Log("Photon token acquired: " + obj.PhotonCustomAuthenticationToken + " Authentication complete."); var customAuth = new AuthenticationValues { AuthType = CustomAuthenticationType.Custom }; customAuth.AddAuthParameter("username", _playFabPlayerId); // expected by PlayFab custom auth service customAuth.AddAuthParameter("token", obj.PhotonCustomAuthenticationToken); PhotonNetwork.AuthValues = customAuth; }Also if needs separate authentication please guide me through that.
I would like to ask one more thing, since I have created another application for chat in photon dashboard, do I have to set custom server authentication for chat application too or only setting in photon realtime application is enough.
0
Comments
-
Hi @avimon,
If you want to use Chat and PUN you need two separate applications, one per type.
If you want to make use of PlayFab authentication for both PUN and Chat, you need to authenticate each one separately.
Follow the guide for each application type:
- PUN
- Chat
These pages contain the steps required and the client code.1 -
yes.1
-
object of type ChatClient.
Class and file can be found in "Assets\PhotonChatApi" available in PUN or in Photon .Net SDKs (Unity etc.).1 -
No get a token for each app.1
-
No. Connect to PlayFab, get Photon token then connect to Photon Cloud.1
-
@JohnTube Is that applicable for both chat and realtime apps? because I have read somewhere that its necessary for a player to join room for message transmission which is only possible after connection with photon.
Please also explain me whether I should usePhotonNetwork.ConnectUsingSettings("")
beforeExitGames.Client.Photon.Chat.ChatClient.Connect ( string appId, string appVersion, AuthenticationValues authValues )
or both of these connections are independent of each other? and really thanks a lot for clearing so many doubts.0 -
both of these connections are independent of each other?This is correct.
You're welcome.1 -
Will there be any problem with connection or token are just for authentication purpose?There won't be any problem with the connection as tokens are just for authentication.1
-
@JohnTube
using PhotonChatClient = ExitGames.Client.Photon.Chat.ChatClient; using PhotonChat = ExitGames.Client.Photon.Chat; using ExitGames.Client.Photon; private static readonly PhotonChat.IChatClientListener listener; public PhotonChatClient chatClient = new PhotonChatClient(listener, ConnectionProtocol.Udp); private void OnLoginSuccess(PFLoginResult result) { RequestPhotonRealtimeToken(result); RequestPhotonChatToken(result); } private void RequestPhotonRealtimeToken(PFLoginResult result) { Debug.Log("PlayFab authenticated. Requesting realtime photon token..."); _playFabPlayerId = result.PlayFabId; PlayFabClientAPI.GetPhotonAuthenticationToken(new GetPhotonAuthenticationTokenRequest() { PhotonApplicationId = PhotonNetwork.PhotonServerSettings.AppID }, AuthenticateWithRealtimePhoton, OnPlayFabError); } private void AuthenticateWithRealtimePhoton(GetPhotonAuthenticationTokenResult obj) { Debug.Log("Realtime Photon token acquired: " + obj.PhotonCustomAuthenticationToken + " Authentication complete."); var customAuth = new AuthenticationValues { AuthType = CustomAuthenticationType.Custom }; customAuth.AddAuthParameter("username", _playFabPlayerId); customAuth.AddAuthParameter("token", obj.PhotonCustomAuthenticationToken); PhotonNetwork.AuthValues = customAuth; } private void RequestPhotonChatToken(PFLoginResult result) { Debug.Log("PlayFab authenticated. Requesting chat photon token..."); PlayFabClientAPI.GetPhotonAuthenticationToken(new GetPhotonAuthenticationTokenRequest() { PhotonApplicationId = PhotonNetwork.PhotonServerSettings.ChatAppID }, AuthenticateWithChatPhoton, OnPlayFabError); } private void AuthenticateWithChatPhoton(GetPhotonAuthenticationTokenResult result) { Debug.Log("Chat Photon token acquired: " + result.PhotonCustomAuthenticationToken + " Authentication complete."); chatClient.AuthValues = new PhotonChat.AuthenticationValues(); chatClient.AuthValues.AuthType = PhotonChat.CustomAuthenticationType.Custom; chatClient.AuthValues.AddAuthParameter("username", _playFabPlayerId); chatClient.AuthValues.AddAuthParameter("token", result.PhotonCustomAuthenticationToken); chatClient.AuthValues.UserId = _playFabPlayerId; }
There is something wrong with this code here which I have implemented. Photon Realtime app is authenticated successfully and I have even recieved its JSON response in playfab but no JSON response is returned for Chat app. Does that mean my Chat app is not yet authenticated.
Please check mychatClient
object. I don't think I don't think I have correctly created it. Also help me to correct it.
InAuthenticateWithChatPhoton
method I had to writechatClient.AuthValues = new PhotonChat.AuthenticationValues();
instead ofchatClient.AuthValues = new AuthenticationValues();
which is given in the photon doc because it prompted an error telling me to explicitly convert its type toExitGames.Client.Photon.Chat
May be it is because of wrong creation of mychatClient
object. Please help me through this .0 -
@JohnTube
using PhotonChatClient = ExitGames.Client.Photon.Chat.ChatClient; using PhotonChat = ExitGames.Client.Photon.Chat; using ExitGames.Client.Photon; private static readonly PhotonChat.IChatClientListener listener; public PhotonChatClient chatClient = new PhotonChatClient(listener, ConnectionProtocol.Udp); private void OnLoginSuccess(PFLoginResult result) { RequestPhotonRealtimeToken(result); RequestPhotonChatToken(result); } private void RequestPhotonRealtimeToken(PFLoginResult result) { Debug.Log("PlayFab authenticated. Requesting realtime photon token..."); _playFabPlayerId = result.PlayFabId; PlayFabClientAPI.GetPhotonAuthenticationToken(new GetPhotonAuthenticationTokenRequest() { PhotonApplicationId = PhotonNetwork.PhotonServerSettings.AppID }, AuthenticateWithRealtimePhoton, OnPlayFabError); } private void AuthenticateWithRealtimePhoton(GetPhotonAuthenticationTokenResult obj) { Debug.Log("Realtime Photon token acquired: " + obj.PhotonCustomAuthenticationToken + " Authentication complete."); var customAuth = new AuthenticationValues { AuthType = CustomAuthenticationType.Custom }; customAuth.AddAuthParameter("username", _playFabPlayerId); customAuth.AddAuthParameter("token", obj.PhotonCustomAuthenticationToken); PhotonNetwork.AuthValues = customAuth; } private void RequestPhotonChatToken(PFLoginResult result) { Debug.Log("PlayFab authenticated. Requesting chat photon token..."); PlayFabClientAPI.GetPhotonAuthenticationToken(new GetPhotonAuthenticationTokenRequest() { PhotonApplicationId = PhotonNetwork.PhotonServerSettings.ChatAppID }, AuthenticateWithChatPhoton, OnPlayFabError); } private void AuthenticateWithChatPhoton(GetPhotonAuthenticationTokenResult result) { Debug.Log("Chat Photon token acquired: " + result.PhotonCustomAuthenticationToken + " Authentication complete."); chatClient.AuthValues = new PhotonChat.AuthenticationValues(); chatClient.AuthValues.AuthType = PhotonChat.CustomAuthenticationType.Custom; chatClient.AuthValues.AddAuthParameter("username", _playFabPlayerId); chatClient.AuthValues.AddAuthParameter("token", result.PhotonCustomAuthenticationToken); chatClient.AuthValues.UserId = _playFabPlayerId; }
There is something wrong with this code here because my Photon Realtime app is successfully authenticated and I even recieved JSON response for that in PlayFab but there is no JSON response returned for Chat app. Does that mean My Chat app is not yet authenticated?
Please check mychatClient
object. I think I have created it in wrong way and if yes please help me to correct it.
InAuthenticateWithChatPhoton
method I had to writechatClient.AuthValues = new PhotonChat.AuthenticationValues();
instead ofchatClient.AuthValues = new AuthenticationValues()
; which was given in photon docs beacause it prompted an error telling me to explcitly convert its type toExitGames.Client.Photon.Chat
May be it is beacause of my wrong creation ofchatClient
object. Please guide me through this.0 -
I even recieved JSON response for that in PlayFab but there is no JSON response returned for Chat app. Does that mean My Chat app is not yet authenticated?What do you mean by this? what are you referring to with "JSON response"? you meanGetPhotonAuthenticationTokenResult? and why is it received for PUN only?
You need to implement the Photon Chat listener interface in some class or some MonoBehaviour or even in the same class as the one you create the PhotonChat object.public class SomeClass : PhotonChat.IChatClientListener { // TODO: implement interface
You can create the PhotonChat object in a Start method of a MonoBehaviour or a constructor of another class.Do I have to download Photon Chat from Asset store or PUN is enough for implementing Photon Chat since PUN asset contains PhotonChatApi named folder in its package?PUN includes Photon Chat so no need to download anything else to use Photon Chat.0 -
@JohnTube Thanks a lot. Finally I got my both applications authenticated and the responses I was talking about which I got on authentication from PlayFab are as follows:
-- img deleted as it contained an appid --
-- img deleted as it contained an appid --
Thanks again for guiding me whole time. Have a good day !!!0