WebRPCs and AuthCookie
Hello!
I got Custom Authentication and WebRPCs working for my Photon Project..
I have a Script on my PHP Server that requires the User to be logged in.. and I need to get data from it.
How do I get the AuthCookie and send it with the WebRPC so the Script knows that the User is logged in?
I use Sessions on my PHP Server
if(!isset($_SESSION['user']))
{
//user logged in.. send data
}
else
//error
Thanks!
Regards
I got Custom Authentication and WebRPCs working for my Photon Project..
I have a Script on my PHP Server that requires the User to be logged in.. and I need to get data from it.
How do I get the AuthCookie and send it with the WebRPC so the Script knows that the User is logged in?
I use Sessions on my PHP Server
if(!isset($_SESSION['user']))
{
//user logged in.. send data
}
else
//error
Thanks!
Regards
0
Best Answer
-
Here is an example of plain PHP Custom Auth:
$json = file_get_contents('php://input'); $request_data = json_decode($json); // process data and construct optional auth_cookie and optional data $response_success = array( "ResultCode" => 0, "Message" => "Success!", "AuthCookie" => auth_cookie "Data" => data ); $json_success = json_encode($response_success); echo $json_success;
Here is an example of plain PHP WebRPC:$json = file_get_contents('php://input'); $request_data = json_decode($json); $user_id = $request_data["UserId"]; $region = $request_data["Region"]; $app_version = $request_data["AppVersion"]; $app_id = $request_data["AppId"]; if (isset($request_data["AuthCookie"])) { $auth_cookie = $request_data["AuthCookie"]; } // process data then return response $response_success = array( "ResultCode" => 0, "Message" => "Success!", "Data" => data ); $json_success = json_encode($response_success); echo $json_success;
Also by “Photon Server”, do you mean that this only works with the Photon Server that we can host? Or does it also work with the Photon Cloud, Which is what I’m using?AuthCookie is supported by Photon Cloud and Photon Server. Photon Cloud is "based on" Photon Server.5
Answers
-
I did look at the Docs.. but there are no examples, and I really don't understand them..0
-
Hi @TheGamerX20,
Thank you for choosing Photon!
Here is how AuthCookie should work:
In Custom Authentication response you return an AuthCookie object to Photon Server.
Photon Server keeps this AuthCookie stored (encrypted) per user.
For WebRPCs or some WebHooks you can from client side tell Photon Server to send that AuthCookie with the HTTP request.
The AuthCookie of the respective player will be sent from Photon Server back to your web service to verify the identity of the player (also for your use case: identify "session" (not "PHP session") and confirm that player is connected) and make sure the origin of the request is Photon Server.
To do so you need to set a WebFlag in the method call. This is not available in PUN yet but I can give you an example of how to set it manually.
In "NetworkingPeer.cs" add:public bool WebRpc(string uriPath, object parameters, bool sendAuthCookie) { Dictionary<byte, object> opParameters = new Dictionary<byte, object>(); opParameters.Add(ParameterCode.UriPath, uriPath); opParameters.Add(ParameterCode.WebRpcParameters, parameters); if (sendAuthCookie) { opParameters.Add(ParameterCode.EventForward, (byte)0x02); } return this.OpCustom(OperationCode.WebRpc, opParameters, true); }
1 -
Hi! Thank your for your reply!
This might not be the right place.. but can you please tell me how I’d send the AuthCookie from PHP?
Also by “Photon Server”, do you mean that this only works with the Photon Server that we can host? Or does it also work with the Photon Cloud, Which is what I’m using?
Thanks!
Regards0 -
Here is an example of plain PHP Custom Auth:
$json = file_get_contents('php://input'); $request_data = json_decode($json); // process data and construct optional auth_cookie and optional data $response_success = array( "ResultCode" => 0, "Message" => "Success!", "AuthCookie" => auth_cookie "Data" => data ); $json_success = json_encode($response_success); echo $json_success;
Here is an example of plain PHP WebRPC:$json = file_get_contents('php://input'); $request_data = json_decode($json); $user_id = $request_data["UserId"]; $region = $request_data["Region"]; $app_version = $request_data["AppVersion"]; $app_id = $request_data["AppId"]; if (isset($request_data["AuthCookie"])) { $auth_cookie = $request_data["AuthCookie"]; } // process data then return response $response_success = array( "ResultCode" => 0, "Message" => "Success!", "Data" => data ); $json_success = json_encode($response_success); echo $json_success;
Also by “Photon Server”, do you mean that this only works with the Photon Server that we can host? Or does it also work with the Photon Cloud, Which is what I’m using?AuthCookie is supported by Photon Cloud and Photon Server. Photon Cloud is "based on" Photon Server.5 -
Hi, Thanks for your reply!
I already have all of this setup, and I know how to return the AuthCookie.. and I’m already returning data.. but what I wanted to know is how to GET or CONSTRUCT the AuthCookie.. like I said, I already have the WebRPCs working and everything.. but I need to get & send the AuthCookie.
I’m sorry if I’m bothering you with this..
Thanks!
Regards0 -
That depends totally on you. It is a custom solution, you may use PHP sessions like session ID or other custom or defined
$_SESSION
key/values.1 -
Hi!
Can you please tell me EXACTLY what I should do?
How do I send the AuthCookie.. this is the only thing I need... do I just send the ID(session_id();) and then what?
Also does AuthCookie get sent from PHP://input?
Or does is it like a cookie and gets sent automatically..
I’m not home so I can’t test right now..
Thanks!
Regards0 -
Hi!
I finally figured it out!
The AuthCookie does get sent from the php://input
and you have to use it manually..
Thank you so much for your help!
Really appreciate it!
Thanks!!
Regards0 -
No problem!
Thanks a lot for your help!
Any idea on how to mark this as resolved?0 -
I changed type of topic from discussion to question and marked one post as answer.0