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

Best Answer

Answers

  • I did look at the Docs.. but there are no examples, and I really don't understand them..
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited September 2017
    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);
        }
  • 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!
    Regards
  • 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!
    Regards
  • JohnTube
    JohnTube ✭✭✭✭✭
    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.
  • 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!
    Regards
  • TheGamerX20
    edited September 2017
    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!!
    Regards
  • JohnTube
    JohnTube ✭✭✭✭✭
    I'm glad you managed to make it work!
    I'm sorry I have found out that I mixed custom auth and webRPC in a previous post, I fixed it here.
  • No problem!
    Thanks a lot for your help!

    Any idea on how to mark this as resolved? :)
  • JohnTube
    JohnTube ✭✭✭✭✭
    I changed type of topic from discussion to question and marked one post as answer.