Cust Authentication Server-Side Code

Options
I've successfully implemented Photon's Custom Authentication and I'm now trying to set the UserId value when the player logs in. Unfortunately, I have no idea where to start. It seems like the documentation is either out-of-date or non-existent.

What is the correct response the server should send back in order to set the UserId? Here is what I have tried (with no success):
{'ResultCode': 1, 'Data': {'UserId': 1}}
{'ResultCode': 1, UserId': 1}
Also, if there is documentation on this could someone please point me in the right direction? Thanks!

Comments

  • Diadem
    Options
    EDIT:
    {'ResultCode': 1, 'Data': {'UserId': 1}}
    {'ResultCode': 1, 'UserId': 1}
  • JohnTube
    JohnTube ✭✭✭✭✭
    edited August 2015
    Options
    Hi @Diadem,

    It seems like you know what you're doing. The correct response should be
    {'ResultCode': 1, 'UserId': <userId>}.

    Unfortunately the feature that makes setting UserId after receiving custom authentication response possible was only introduced in LoadBalancing SDK v4.0.0.10 and it will be available in PUN v1.61.

    If you want to do it manually, all you need is to set the local UserId to the value of the parameter (ParameterCode.UserId = 225) received in the custom authentication response (OperationCode.Authenticate = 230).
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    @Diadem,

    try adding these lines :
    if (operationResponse.Parameters.ContainsKey(ParameterCode.UserId)) {
        //DebugReturn(DebugLevel.ERROR, operationResponse.ToStringFull());
        this.CustomAuthenticationValues.UserId = operationResponse.Parameters[ParameterCode.UserId] as string;
    }
    in NetworkingPeer.OnOperationResponse() when operationResponse.OperationCode == OperationCode.Authenticate.
  • Diadem
    Options
    Thanks @JohnTube
  • Diadem
    Options
    Hey @JohnTube - does this work for PUN? I'm not finding any documentation on NetworkingPeer for PUN.

    I'm going to try OnWebRpcResponse to see if that works
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Diadem said:

    Hey @JohnTube - does this work for PUN? I'm not finding any documentation on NetworkingPeer for PUN.

    I'm going to try OnWebRpcResponse to see if that works

    No, OnWebRpcResponse does not have anything to do with this. It is the callback of WebRPC operations only.

    Go to "NetworkingPeer.cs" file in your project and find OnOperationResponse then update it :
    
    void OnOperationResponse(OperationResponse operationResponse){
           switch(operationResponse.Operation){
                case OperationCode.Authenticate :
                          if (operationResponse.Parameters.ContainsKey(ParameterCode.UserId)) {
                             this.CustomAuthenticationValues.UserId = operationResponse.Parameters[ParameterCode.UserId] as string;
                           }
                break;
          }
    }
  • Diadem
    Diadem
    edited August 2015
    Options
    @JohnTube YOU ARE AMAZING.

    Thank you.