Container for user authentication in Photon. Set AuthValues before you connect - all else is handled.
On Photon, user authentication is optional but can be useful in many cases. If you want to FindFriends, a unique ID per user is very practical. There are basically three options for user authentification: None at all, the client sets some UserId or you can use some account web-service to authenticate a user (and set the UserId server-side). Custom Authentication lets you verify end-users by some kind of login or token. It sends those values to Photon which will verify them before granting access or disconnecting the client. The Photon Cloud Dashboard will let you enable this feature and set important server values for it. https://www.exitgames.com/dashboard
Exemple #1
1
    // Use this for initialization
    void Start()
    {
        loadBalancingClient = new LoadBalancingClient(null, TurnbasedAppId, "1.0"); // the master server address is not used when connecting via nameserver

        AuthenticationValues customAuth = new AuthenticationValues();
        customAuth.AddAuthParameter("username", UserName);  // expected by the demo custom auth service
        customAuth.AddAuthParameter("token", UserToken);    // expected by the demo custom auth service
        loadBalancingClient.AuthValues = customAuth;

        loadBalancingClient.AutoJoinLobby = false;
        loadBalancingClient.ConnectToRegionMaster("us");
    }
Exemple #2
0
 public PhantomClient(string token, string user, string avatar) : base(ConnectionProtocol.Udp)
 {
     ClientIndex    = GeneralUtils.Clients.Count();
     Token          = token;
     User           = user;
     Avatar         = avatar;
     AppId          = "bf0942f7-9935-4192-b359-f092fa85bef1";
     NameServerHost = "ns.exitgames.com";
     AppVersion     = ClientUtils.GetCurrentReleaseServer() + "_2.5";
     AuthValues     = new AuthenticationValues()
     {
         AuthType = CustomAuthenticationType.Custom
     };
     AuthValues.AddAuthParameter("token", Token);
     AuthValues.AddAuthParameter("user", User);
     this.RegisterTypes();
     ConsoleUtils.Log($"[Client #{ClientIndex}] Created new PhantomClient");
     AddCallbackTarget(this);
     ConsoleUtils.Log($"[Client #{ClientIndex}] Subscribed to Client Callbacks");
     ConsoleUtils.Log($"[Client #{ClientIndex}] Connecting to Region Master USW");
     new Thread(() => UpdateThread())
     {
         IsBackground = true
     }.Start();
     ConnectToRegionMaster("USW");
 }
Exemple #3
0
    void UserIDChange(string id)
    {
        AuthenticationValues authV = new AuthenticationValues();

        authV.UserId             = id;
        PhotonNetwork.AuthValues = authV;
    }
Exemple #4
0
    /*
     * Step 3
     * This is the final and the simplest step. We create new AuthenticationValues instance.
     * This class describes how to authenticate a players inside Photon environment.
     */
    private static void AuthenticateWithPhoton(GetPhotonAuthenticationTokenResult obj)
    {
        LogMessage("Photon token acquired: " + obj.PhotonCustomAuthenticationToken + "  Authentication complete.");

        //We set AuthType to custom, meaning we bring our own, PlayFab authentication procedure.
        var customAuth = new AuthenticationValues {
            AuthType = CustomAuthenticationType.Custom
        };

        //We add "username" parameter. Do not let it confuse you: PlayFab is expecting this parameter to contain player PlayFab ID (!) and not username.
        customAuth.AddAuthParameter("username", _playFabPlayerIdCache);    // expected by PlayFab custom auth service

        //We add "token" parameter. PlayFab expects it to contain Photon Authentication Token issues to your during previous step.
        customAuth.AddAuthParameter("token", obj.PhotonCustomAuthenticationToken);

        //We finally tell Photon to use this authentication parameters throughout the entire application.
        PhotonNetwork.AuthValues = customAuth;
        //
        PhotonNetwork.AuthValues.UserId = _playFabPlayerIdCache;
        //
        //UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(0);
        PF_Bridge.RaiseCallbackSuccess(string.Empty, PlayFabAPIMethods.GenericLogin, MessageDisplayStyle.none);
        if (OnLoginSuccess != null)
        {
            OnLoginSuccess(string.Format("SUCCESS: {0}", "result.SessionTicket"), MessageDisplayStyle.error);
        }

        Debug.Log("AuthenticateWithPhoton");
    }
        public void Initialize(string UserId, string NickName)
        {
                        #if CONFIG_LIVE
            PhotonNetwork.logLevel = PhotonLogLevel.ErrorsOnly;
                        #else
            PhotonNetwork.logLevel = PhotonLogLevel.Informational;
                        #endif

            PhotonNetwork.autoJoinLobby          = false;
            PhotonNetwork.automaticallySyncScene = false;
            PhotonNetwork.BackgroundTimeout      = 500f;

            PhotonNetwork.MaxResendsBeforeDisconnect = 10;
            PhotonNetwork.QuickResends        = 3;
            PhotonNetwork.sendRate            = 2;
            PhotonNetwork.sendRateOnSerialize = 2;
            AuthenticationValues auth = new AuthenticationValues();

            auth.AuthType = CustomAuthenticationType.None;
            auth.AddAuthParameter("UserId", UserId);
            auth.AddAuthParameter("access_token", "offlien_token");                     //this token isn't required as yet.

            PhotonNetwork.playerName        = NickName;
            PhotonNetwork.AuthValues        = auth;
            M3Utils.Instance.GameRestarted += OnGameRestart;
            PhotonNetwork.OnEventCall      += OnEventCall;
        }
    private void ConnectToMasterServer(string id, string ticket)
    {
        //Debug.Log("connect to master server");
        //if (PhotonNetwork.AuthValues != null)
        //{

        //}
        //else
        //{

        //    PhotonNetwork.AuthValues = new AuthenticationValues()
        //    {

        //        AuthType = CustomAuthenticationType.Custom

        //    };

        //    PhotonNetwork.AuthValues.AddAuthParameter(id, ticket);

        //}

        AuthenticationValues authVals = new AuthenticationValues(AuthManager.playfabId);

        authVals.AuthType = CustomAuthenticationType.Custom;
        authVals.AddAuthParameter("username", AuthManager.playfabId);
        authVals.AddAuthParameter("token", ticket);

        PhotonNetwork.ConnectUsingSettings("1.0");
    }
Exemple #7
0
        public IActionResult Index()
        {
            var model = new AuthenticationValues();

            var certificate = HttpContext.Connection.ClientCertificate;

            if (certificate != null)
            {
                model.CertificateValues.Thumbprint   = certificate.Thumbprint;
                model.CertificateValues.FriendlyName = certificate.FriendlyName;
                model.CertificateValues.ValidFrom    = certificate.NotBefore;
                model.CertificateValues.ValidTo      = certificate.NotAfter;
                model.CertificateValues.IssuerName   = certificate.IssuerName.Name;
                model.CertificateValues.SubjectName  = certificate.SubjectName.Name;
                model.CertificateValues.UserUpn      = certificate.GetNameInfo(X509NameType.UpnName, false);
                model.CertificateValues.UserName     = certificate.GetNameInfo(X509NameType.SimpleName, false);
                model.CertificateValues.UserEmail    = certificate.GetNameInfo(X509NameType.EmailName, false);
            }

            var identity = ControllerContext.HttpContext.User.Identity;

            if (identity != null)
            {
                model.IdentityValues.IsAuthenticated    = identity.IsAuthenticated;
                model.IdentityValues.AuthenticationType = identity.AuthenticationType;
                model.IdentityValues.Name   = identity.Name;
                model.IdentityValues.Claims = HttpContext.User.Claims;
            }

            return(View(model));
        }
Exemple #8
0
    private void OnPhotonAuthenticationSuccess(GetPhotonAuthenticationTokenResult obj)
    {
        Logger.Verbose("MainPageScript.OnPhotonAuthenticationSuccess");

        // Set the Photon Connection Settings
        // See https://api.playfab.com/docs/using-photon-with-playfab/
        PhotonNetwork.PhotonServerSettings.AppID           = PhotonAppID;
        PhotonNetwork.PhotonServerSettings.HostType        = ServerSettings.HostingOption.PhotonCloud;
        PhotonNetwork.PhotonServerSettings.PreferredRegion = CloudRegionCode.us;
        PhotonNetwork.PhotonServerSettings.Protocol        = ExitGames.Client.Photon.ConnectionProtocol.Udp;

        string authToken = obj.PhotonCustomAuthenticationToken;

        AuthenticationValues customAuth = new AuthenticationValues();

        customAuth.AuthType = CustomAuthenticationType.Custom;
        customAuth.AddAuthParameter("username", PlayFabManager.PlayfabId);    // expected by PlayFab custom auth service
        customAuth.AddAuthParameter("token", authToken);                      // expected by PlayFab custom auth service

        JUMPOptions.GameVersion = AppID;
        JUMPOptions.CustomAuth  = customAuth;

        // Now Activate the JUMP Connection object that will trigger login to Photon.
        JUMPConnectionStatus = JUMPConnectionStatus.Connecting;
        JUMPConnection.gameObject.SetActive(true);
    }
Exemple #9
0
    private void AuthenticateWithPhoton(GetPhotonAuthenticationTokenResult obj)
    {
        LogMessage("Photon token acquired: " + obj.PhotonCustomAuthenticationToken + "  Authentication complete.");

        //We set AuthType to custom, meaning we bring our own, PlayFab authentication procedure.
        var customAuth = new AuthenticationValues {
            AuthType = CustomAuthenticationType.Custom
        };

        //We add "username" parameter. Do not let it confuse you: PlayFab is expecting this parameter to contain player PlayFab ID (!) and not username.
        customAuth.AddAuthParameter("username", PlayFabAuthService.PlayFabId);    // expected by PlayFab custom auth service

        //We add "token" parameter. PlayFab expects it to contain Photon Authentication Token issues to your during previous step.
        customAuth.AddAuthParameter("token", obj.PhotonCustomAuthenticationToken);

        //We finally tell Photon to use this authentication parameters throughout the entire application.
        PhotonNetwork.AuthValues = customAuth;

        if (!PhotonNetwork.IsConnected)
        {
            PhotonNetwork.ConnectUsingSettings();
        }

        PhotonNetwork.LocalPlayer.NickName = (PlayFabAuthService.PlayFabId.Split(new Char[] { '-' }))[0];
        SetLobbyPanelActive();
    }
Exemple #10
0
        public void DeleteBookingUsingBasicAuth()
        {
            //Make a post request to add new booking and save its bookingid
            Dictionary <string, string> header = new Dictionary <string, string>()
            {
                { "Content-Type", "application/json" },
                { "Accept", "application/json" }
            };
            Booking          booking                     = new Booking("Manisha", "Chanda", 200, true, new Bookingdates(new DateTime(2011, 12, 28), new DateTime(2012, 3, 1)), "Vacation so do not disturb");
            RestClientHelper restClientHelper            = new RestClientHelper();
            IRestResponse <BookingResponse> restresponse = restClientHelper.PerformPostRequest <BookingResponse>(URLEndPoint.bookingurl, header, null, booking, DataFormat.Json);

            Assert.AreEqual(200, (int)restresponse.StatusCode);
            Assert.IsNotNull(restresponse.Data, "Rest response is null");
            int bookingid = restresponse.Data.bookingid;

            //Use basic authentication and perfrom delete request using bookingid
            header = new Dictionary <string, string>()
            {
                { "Content-Type", "application/json" },
                { "Authorization", AuthenticationValues.Base64EncodedBaiscAuth() }
            };
            RestClientHelper restClientHelper1 = new RestClientHelper();
            IRestResponse    restResponse1     = restClientHelper1.PerformDeleteRequest(URLEndPoint.bookingurl + bookingid, header, null);

            Assert.AreEqual(201, (int)restResponse1.StatusCode);

            //Verify the booking id and its values does not exist
            restResponse1 = restClientHelper.PerformDeleteRequest(URLEndPoint.bookingurl + bookingid, header, null);
            Assert.AreEqual(405, (int)restResponse1.StatusCode);
        }
Exemple #11
0
    private void AuthSuccessCallback(string UserID)
    {
        LoginMsg.text = "Auth Success";

        SystemManage.GetAllTitleData();                 //取得所有title data
        SystemManage.GetAllStroeItem();                 //取得所有物品

        //使用playfab登入photon
        PlayFabClientAPI.GetPhotonAuthenticationToken(new GetPhotonAuthenticationTokenRequest()
        {
            PhotonApplicationId = PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime
        }, (xr) =>
        {
            var customAuth = new AuthenticationValues {
                AuthType = CustomAuthenticationType.Custom
            };

            customAuth.AddAuthParameter("username", UserID);
            customAuth.AddAuthParameter("token", xr.PhotonCustomAuthenticationToken);

            PhotonNetwork.AuthValues = customAuth;
            PhotonNetwork.ConnectUsingSettings();

            LoginMsg.text = "Login....";
        },
                                                      (xe) =>
        {
            LoginMsg.text = "Login Fail";
            ModalHelper.WarningMessage("Photon Authentication fail.");
        });
    }
Exemple #12
0
    private void OnPhotonTokenReceived(GetPhotonAuthenticationTokenResult result)
    {
        Debug.Log("Received photon token");

        //We set AuthType to custom, meaning we bring our own, PlayFab authentication procedure.
        var customAuth = new AuthenticationValues {
            AuthType = CustomAuthenticationType.Custom
        };

        //We add "username" parameter. Do not let it confuse you: PlayFab is expecting this parameter to contain player PlayFab ID (!) and not username.
        customAuth.AddAuthParameter("username", PlayerId);    // expected by PlayFab custom auth service

        //We add "token" parameter. PlayFab expects it to contain Photon Authentication Token issues to your during previous step.
        customAuth.AddAuthParameter("token", result.PhotonCustomAuthenticationToken);

        //We finally tell Photon to use this authentication parameters throughout the entire application.
        PhotonNetwork.AuthValues = customAuth;

        //Finally we will initialize photon with any custom data
        InitializePhoton();

        if (OnLogin != null)
        {
            OnLogin();
        }
    }
Exemple #13
0
 private void Start()
 {
     _chatClient            = new ChatClient(new ChatListener(this));
     _chatClient.ChatRegion = "US";
     _authValue             = new AuthenticationValues(ServiceManager.PlayerManager.LocalPlayerProfile.Uid);
     _chatClient.Connect(ChatAppId, ChatAppVersion, _authValue);
     PhotonPeer.RegisterType(typeof(PlayerInfoMessage), PlayerInfoMessage.Id, PlayerInfoMessage.Serialize, PlayerInfoMessage.Deserialize);
 }
    // Use this for initialization
    void Start()
    {
        loadBalancingClient = new LoadBalancingClient(null, TurnbasedAppId, "1.0"); // the master server address is not used when connecting via nameserver
        AuthenticationValues customAuth = new AuthenticationValues();

        customAuth.SetAuthParameters(UserName, UserToken);
        loadBalancingClient.AutoJoinLobby = false;
        loadBalancingClient.CustomAuthenticationValues = customAuth;
        loadBalancingClient.ConnectToRegionMaster("eu");
    }
Exemple #15
0
    void Start()
    {
        AuthenticationValues authenticationValues = new AuthenticationValues("0");

        PhotonNetwork.AuthValues = authenticationValues;

        PhotonNetwork.AutomaticallySyncScene = true;
        PhotonNetwork.NickName = Master.GameSettings.UserName;
        PhotonNetwork.ConnectUsingSettings();
    }
Exemple #16
0
    void Start()
    {
        AuthenticationValues authValues = new AuthenticationValues();

        authValues.UserId     = PlayerPrefs.GetString(Prefs.PLAYER_NAME_PREF);
        authValues.AuthType   = CustomAuthenticationType.None;
        chatClient            = new ChatClient(this, connectProtocol);
        chatClient.ChatRegion = "EU";
        chatClient.Connect("c212f995-7a94-43d4-9b01-067a8b58d7af", "0.01", authValues);
    }
Exemple #17
0
    public virtual bool OpAuthenticateOnce(string appId, string appVersion, AuthenticationValues authValues, string regionCode, EncryptionMode encryptionMode, ConnectionProtocol expectedProtocol)
    {
        if (this.DebugOut >= 3)
        {
            base.get_Listener().DebugReturn(3, "OpAuthenticate()");
        }
        Dictionary <byte, object> dictionary = new Dictionary <byte, object>();

        if (authValues != null && authValues.Token != null)
        {
            dictionary.set_Item(221, authValues.Token);
            return(this.OpCustom(231, dictionary, true, 0, false));
        }
        if (encryptionMode == EncryptionMode.DatagramEncryption && expectedProtocol != null)
        {
            Debug.LogWarning("Expected protocol set to UDP, due to encryption mode DatagramEncryption. Changing protocol in PhotonServerSettings from: " + PhotonNetwork.PhotonServerSettings.Protocol);
            PhotonNetwork.PhotonServerSettings.Protocol = 0;
            expectedProtocol = 0;
        }
        dictionary.set_Item(195, expectedProtocol);
        dictionary.set_Item(193, (byte)encryptionMode);
        dictionary.set_Item(220, appVersion);
        dictionary.set_Item(224, appId);
        if (!string.IsNullOrEmpty(regionCode))
        {
            dictionary.set_Item(210, regionCode);
        }
        if (authValues != null)
        {
            if (!string.IsNullOrEmpty(authValues.UserId))
            {
                dictionary.set_Item(225, authValues.UserId);
            }
            if (authValues.AuthType != CustomAuthenticationType.None)
            {
                dictionary.set_Item(217, (byte)authValues.AuthType);
                if (!string.IsNullOrEmpty(authValues.Token))
                {
                    dictionary.set_Item(221, authValues.Token);
                }
                else
                {
                    if (!string.IsNullOrEmpty(authValues.AuthGetParameters))
                    {
                        dictionary.set_Item(216, authValues.AuthGetParameters);
                    }
                    if (authValues.AuthPostData != null)
                    {
                        dictionary.set_Item(214, authValues.AuthPostData);
                    }
                }
            }
        }
        return(this.OpCustom(231, dictionary, true, 0, base.get_IsEncryptionAvailable()));
    }
Exemple #18
0
    public virtual bool OpAuthenticateOnce(string appId, string appVersion, AuthenticationValues authValues, string regionCode, EncryptionMode encryptionMode, ConnectionProtocol expectedProtocol)
    {
        if (this.DebugOut >= 3)
        {
            this.get_Listener().DebugReturn((DebugLevel)3, "OpAuthenticate()");
        }
        Dictionary <byte, object> dictionary = new Dictionary <byte, object>();

        if (authValues != null && authValues.Token != null)
        {
            dictionary[(byte)221] = (object)authValues.Token;
            return(this.OpCustom((byte)231, dictionary, true, (byte)0, false));
        }
        if (encryptionMode == EncryptionMode.DatagramEncryption && expectedProtocol != null)
        {
            Debug.LogWarning((object)("Expected protocol set to UDP, due to encryption mode DatagramEncryption. Changing protocol in PhotonServerSettings from: " + (object)PhotonNetwork.PhotonServerSettings.Protocol));
            PhotonNetwork.PhotonServerSettings.Protocol = (ConnectionProtocol)0;
            expectedProtocol = (ConnectionProtocol)0;
        }
        dictionary[(byte)195] = (object)(byte)expectedProtocol;
        dictionary[(byte)193] = (object)(byte)encryptionMode;
        dictionary[(byte)220] = (object)appVersion;
        dictionary[(byte)224] = (object)appId;
        if (!string.IsNullOrEmpty(regionCode))
        {
            dictionary[(byte)210] = (object)regionCode;
        }
        if (authValues != null)
        {
            if (!string.IsNullOrEmpty(authValues.UserId))
            {
                dictionary[(byte)225] = (object)authValues.UserId;
            }
            if (authValues.AuthType != CustomAuthenticationType.None)
            {
                dictionary[(byte)217] = (object)authValues.AuthType;
                if (!string.IsNullOrEmpty(authValues.Token))
                {
                    dictionary[(byte)221] = (object)authValues.Token;
                }
                else
                {
                    if (!string.IsNullOrEmpty(authValues.AuthGetParameters))
                    {
                        dictionary[(byte)216] = (object)authValues.AuthGetParameters;
                    }
                    if (authValues.AuthPostData != null)
                    {
                        dictionary[(byte)214] = authValues.AuthPostData;
                    }
                }
            }
        }
        return(this.OpCustom((byte)231, dictionary, true, (byte)0, this.get_IsEncryptionAvailable()));
    }
Exemple #19
0
    void Start()
    {
        print("conectando ao servidor...");
        AuthenticationValues authValues = new AuthenticationValues("0");

        PhotonNetwork.AuthValues             = authValues;
        PhotonNetwork.AutomaticallySyncScene = true;
        PhotonNetwork.NickName    = MasterManager.GameSettings.NickName;
        PhotonNetwork.GameVersion = MasterManager.GameSettings.GameVersion;
        PhotonNetwork.ConnectUsingSettings();
    }
    void OnAuthTokenResult(GetPhotonAuthenticationTokenResult result)
    {
        AuthenticationValues customAuth = new AuthenticationValues();

        customAuth.AuthType = CustomAuthenticationType.Custom;
        customAuth.AddAuthParameter("username", playfabId);
        customAuth.AddAuthParameter("token", result.PhotonCustomAuthenticationToken);

        PhotonNetwork.AuthValues = customAuth;

        PhotonNetwork.ConnectUsingSettings("v0.1d");
    }
    public void ConnectToChatServer()
    {
        ConnectionProtocol connectionProtocol = ConnectionProtocol.Udp;

        this.client = new ChatClient(this, connectionProtocol);
        AuthenticationValues authenticationValues = new AuthenticationValues();

        authenticationValues.AuthType = CustomAuthenticationType.None;
        this.client.Connect(PhotonNetwork.PhotonServerSettings.AppSettings.AppIdChat, "0", authenticationValues);
        this.connectionState.text = "Connecting to chat server...";
        Debug.Log("Attempting to Connect to Chat.");
    }
Exemple #22
0
    // Use this for initialization
    void Start()
    {
        loadBalancingClient = new LoadBalancingClient(null, TurnbasedAppId, "1.0"); // the master server address is not used when connecting via nameserver

        AuthenticationValues customAuth = new AuthenticationValues();

        customAuth.AddAuthParameter("username", UserName);  // expected by the demo custom auth service
        customAuth.AddAuthParameter("token", UserToken);    // expected by the demo custom auth service
        loadBalancingClient.AuthValues = customAuth;

        loadBalancingClient.ConnectToRegionMaster("eu");
    }
    private void AuthenticateWithPhoton(GetPhotonAuthenticationTokenResult obj)
    {
        LogMessage("Photon token acquired: " + obj.PhotonCustomAuthenticationToken + "  Authentication complete.");
        var customAuth = new AuthenticationValues {
            AuthType = CustomAuthenticationType.Custom
        };

        customAuth.AddAuthParameter("username", _playFabPlayerIdCache);
        customAuth.AddAuthParameter("token", obj.PhotonCustomAuthenticationToken);
        PhotonNetwork.AuthValues = customAuth;
        LoginScene.Instance.LoginClick();
    }
Exemple #24
0
    private void OnLoginMobileSuccess(LoginResult result)
    {
        PlayerVariables.Inistance.setUserPlayFabID(result.PlayFabId);

        AuthenticationValues auth = new AuthenticationValues(result.PlayFabId);

        PhotonNetwork.AuthValues = auth;
        PhotonNetwork.NickName   = result.PlayFabId;

        PhotonNetwork.ConnectUsingSettings();
        PlayfabDataGetter.Inistance.GetAllData(result.PlayFabId);
    }
Exemple #25
0
    private void Start()
    {
        Debug.Log("Connecting to Photon...", this);
        AuthenticationValues authValues = new AuthenticationValues("0");

        PhotonNetwork.AuthValues             = authValues;
        PhotonNetwork.SendRate               = 20; //20.
        PhotonNetwork.SerializationRate      = 5;  //10.
        PhotonNetwork.AutomaticallySyncScene = true;
        PhotonNetwork.NickName               = MasterManager.GameSettings.NickName;
        PhotonNetwork.GameVersion            = MasterManager.GameSettings.GameVersion;
        PhotonNetwork.ConnectUsingSettings();
    }
    public void Connect()
    {
        _loadBalancingClient.UserId = _userToken;
        AuthenticationValues customAuth = new AuthenticationValues(_loadBalancingClient.UserId);

        customAuth.AuthType = CustomAuthenticationType.Custom;
        customAuth.AddAuthParameter("username", _userName);          // expected by the demo custom auth service
        customAuth.AddAuthParameter("token", _userToken);            // expected by the demo custom auth service
        _loadBalancingClient.AuthValues = customAuth;
        _loadBalancingClient.NickName   = _userName;

        _loadBalancingClient.AutoJoinLobby = false;
        _loadBalancingClient.ConnectToRegionMaster("eu");
    }
Exemple #27
0
    public void Connect(string userName, string userID)
    {
        StartCoroutine(WaitingForConnectMaster());
        AuthenticationValues authentication = new AuthenticationValues();

        authentication.UserId    = userID;
        PhotonNetwork.AuthValues = authentication;

        // #Critical, we must first and foremost connect to Photon Online Server.
        PhotonNetwork.GameVersion            = "alpha";
        PhotonNetwork.NickName               = userName;
        PhotonNetwork.AutomaticallySyncScene = true;
        PhotonNetwork.ConnectUsingSettings();
    }
    private void AuthenticateWithPhoton(GetPhotonAuthenticationTokenRequest obj)
    {
        LogMessage("Photon token acquired: " + obj.PhotonCustomAuthenticationToken + " Authentication comeplete.");

        var customAuth = new AuthenticationValues {
            AuthType = CustomAuthenticationType.Custom
        };

        customAuth.AddAuthParameter("username", _playFabPlayerIdCache);

        PhotonNetwork.AuthValues = customAuth;

        PhotonNetwork.ConnectUsingSettings();
    }
Exemple #29
0
        public void UpdateBooking_JsonRequest_JsonResponse_BaiscAuth()
        {
            //Make a post request to add new booking and save its bookingid
            Dictionary <string, string> header = new Dictionary <string, string>()
            {
                { "Content-Type", "application/json" },
                { "Accept", "application/json" }
            };
            DateTime         checkin                     = new DateTime(2016, 02, 18);
            DateTime         checkout                    = new DateTime(2017, 02, 21);
            Booking          booking                     = new Booking("Manisha", "Chanda", 200, true, new Bookingdates(checkin, checkout), "Towel");
            RestClientHelper restClientHelper            = new RestClientHelper();
            IRestResponse <BookingResponse> restresponse = restClientHelper.PerformPostRequest <BookingResponse>(URLEndPoint.bookingurl, header, null, booking, DataFormat.Json);

            Assert.AreEqual(200, (int)restresponse.StatusCode);
            int bookingid = restresponse.Data.bookingid;

            //Make a put request and update booking using bookingid
            header = new Dictionary <string, string>()
            {
                { "Content-Type", "application/json" },
                { "Accept", "application/json" },
                { "Authorization", AuthenticationValues.Base64EncodedBaiscAuth() }
            };
            checkin  = new DateTime(2016, 02, 09);
            checkout = new DateTime(2017, 02, 20);
            Booking                 booking1          = new Booking("Manu", "Chandu", 150, true, new Bookingdates(checkin, checkout), "Towel not needed");
            RestClientHelper        restClientHelper1 = new RestClientHelper();
            IRestResponse <Booking> restresponse1     = restClientHelper1.PerformPutRequest <Booking>(URLEndPoint.bookingurl + bookingid, header, null, booking1, DataFormat.Json);

            Assert.AreEqual(200, (int)restresponse1.StatusCode);

            //Make a get response and verify the booking has been updated
            header = new Dictionary <string, string>()
            {
                { "Accept", "application/json" }
            };
            RestClientHelper        restClientHelper2 = new RestClientHelper();
            IRestResponse <Booking> restresponse2     = restClientHelper2.PerformGetRequest <Booking>(URLEndPoint.bookingurl + bookingid, header);

            Assert.AreEqual(200, (int)restresponse2.StatusCode);
            Assert.IsNotNull(restresponse2.Content, "Rest response is null");
            Assert.IsTrue(restresponse2.Data.firstname.Contains("Manu"), "Firstname is not updated ");
            Assert.IsTrue(restresponse2.Data.lastname.Contains("Chandu"), "Lastname is not updated");
            Assert.AreEqual(150, restresponse2.Data.totalprice, "Total price is not updated");
            Assert.AreEqual(Booking.convertdateinstring(checkin), Booking.convertdateinstring(restresponse2.Data.bookingdates.checkin), "Checkin date is not updated");
            Assert.AreEqual(Booking.convertdateinstring(checkout), Booking.convertdateinstring(restresponse2.Data.bookingdates.checkout), "Checkout date is not updated");
            Assert.IsTrue(restresponse2.Data.additionalneeds.Contains("Towel not needed"), "Additional needs is not updated");
        }
    public void ConnectToMasterServer(string id, string ticket)
    {
        AuthenticationValues customAuth = new AuthenticationValues();
        customAuth.AuthType = CustomAuthenticationType.Custom;
        customAuth.AddAuthParameter("username", id);    // expected by PlayFab custom auth service
        customAuth.AddAuthParameter("token", ticket);   // expected by PlayFab custom auth service

        this.GameInstance.AuthValues = customAuth;

        //this.GameInstance.AutoJoinLobby = false;                      // use this, if you don't list current rooms
        this.GameInstance.loadBalancingPeer.QuickResendAttempts = 2;    // option to re-send reliable stuff more quickly
        this.GameInstance.loadBalancingPeer.SentCountAllowance = 8;     // default + some quick resends

        this.GameInstance.ConnectToRegionMaster("US");  // connect to the US region of Photon Cloud
    }
    //Connect without photon authentication ( login with inputname)
    public void Connect(string _nickName, string userid = "")
    {
        nickName = _nickName;
        Debug.Log("PhotonNetwork.AuthValues.UserId" + PhotonNetwork.AuthValues.UserId);
        if (string.IsNullOrEmpty(userid) && string.IsNullOrEmpty(PhotonNetwork.AuthValues.UserId))
        {
            userid = _nickName;
            AuthenticationValues authValue = new AuthenticationValues(userid);
            PhotonNetwork.AuthValues = authValue;
        }
        //Debug.Log("Connect "+_nickName+"user id "+userid);

        PhotonNetwork.NickName = _nickName;
        PhotonNetwork.ConnectUsingSettings();
    }
    void AuthenticatewithPhoton(GetPhotonAuthenticationTokenResult result)
    {
        Notify.text = "Photon token acquired Authentication complete.";

        var customAuth = new AuthenticationValues
        {
            AuthType = CustomAuthenticationType.Custom
        };

        customAuth.AddAuthParameter("username", PlayfabId);
        customAuth.AddAuthParameter("token", result.PhotonCustomAuthenticationToken);

        PhotonNetwork.AuthValues = customAuth;

        SceneManager.LoadScene(1);
    }
        /// <summary>
        /// Sends this app's appId and appVersion to identify this application server side.
        /// This is an async request which triggers a OnOperationResponse() call.
        /// </summary>
        /// <remarks>
        /// This operation makes use of encryption, if that is established before.
        /// See: EstablishEncryption(). Check encryption with IsEncryptionAvailable.
        /// This operation is allowed only once per connection (multiple calls will have ErrorCode != Ok).
        /// </remarks>
        /// <param name="appId">Your application's name or ID to authenticate. This is assigned by Photon Cloud (webpage).</param>
        /// <param name="appVersion">The client's version (clients with differing client appVersions are separated and players don't meet).</param>
        /// <param name="authValues">Contains all values relevant for authentication (with third-party external Custom Authentication optionally).</param>
        /// <param name="regionCode">When authenticating for a specific region, a NameServer will forward you to that region's MasterServer.</param>
        /// <param name="getLobbyStatistics">Set to true on Master Server to receive "Lobby Statistics" events.</param>
        /// <returns>If the operation could be sent (has to be connected).</returns>
        public virtual bool OpAuthenticate(string appId, string appVersion, AuthenticationValues authValues, string regionCode, bool getLobbyStatistics)
        {
            if (this.DebugOut >= DebugLevel.INFO)
            {
                this.Listener.DebugReturn(DebugLevel.INFO, "OpAuthenticate()");
            }

            Dictionary<byte, object> opParameters = new Dictionary<byte, object>();
            if (getLobbyStatistics)
            {
                // must be sent in operation, even if a Token is available
                opParameters[ParameterCode.LobbyStats] = true;
            }

            if (authValues != null && authValues.Token != null)
            {
                opParameters[ParameterCode.Secret] = authValues.Token;
                return this.OpCustom(OperationCode.Authenticate, opParameters, true, (byte) 0, false);
            }

            opParameters[ParameterCode.AppVersion] = appVersion;
            opParameters[ParameterCode.ApplicationId] = appId;

            if (!string.IsNullOrEmpty(regionCode))
            {
                opParameters[ParameterCode.Region] = regionCode;
            }

            if (authValues != null)
            {

                if (!string.IsNullOrEmpty(authValues.UserId))
                {
                    opParameters[ParameterCode.UserId] = authValues.UserId;
                }

                if (authValues.AuthType != CustomAuthenticationType.None)
                {
                    if (!this.IsProtocolSecure && !this.IsEncryptionAvailable)
                    {
                        this.Listener.DebugReturn(DebugLevel.ERROR, "OpAuthenticate() failed. When you want Custom Authentication encryption is mandatory.");
                        return false;
                    }

                    opParameters[ParameterCode.ClientAuthenticationType] = (byte) authValues.AuthType;
                    if (!string.IsNullOrEmpty(authValues.Token))
                    {
                        opParameters[ParameterCode.Secret] = authValues.Token;
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(authValues.AuthGetParameters))
                        {
                            opParameters[ParameterCode.ClientAuthenticationParams] = authValues.AuthGetParameters;
                        }
                        if (authValues.AuthPostData != null)
                        {
                            opParameters[ParameterCode.ClientAuthenticationData] = authValues.AuthPostData;
                        }
                    }
                }
            }

            bool sent = this.OpCustom(OperationCode.Authenticate, opParameters, true, (byte) 0, this.IsEncryptionAvailable);
            if (!sent)
            {
                this.Listener.DebugReturn(DebugLevel.ERROR, "Error calling OpAuthenticate! Did not work. Check log output, CustomAuthenticationValues and if you're connected.");
            }
            return sent;
        }
    /// <summary>
    /// Sends this app's appId and appVersion to identify this application server side.
    /// This is an async request which triggers a OnOperationResponse() call.
    /// </summary>
    /// <remarks>
    /// This operation makes use of encryption, if that is established before.
    /// See: EstablishEncryption(). Check encryption with IsEncryptionAvailable.
    /// This operation is allowed only once per connection (multiple calls will have ErrorCode != Ok).
    /// </remarks>
    /// <param name="appId">Your application's name or ID to authenticate. This is assigned by Photon Cloud (webpage).</param>
    /// <param name="appVersion">The client's version (clients with differing client appVersions are separated and players don't meet).</param>
    /// <param name="userId"></param>
    /// <param name="authValues"></param>
    /// <returns>If the operation could be sent (has to be connected).</returns>
    public virtual bool OpAuthenticate(string appId, string appVersion, string userId, AuthenticationValues authValues)
    {
        if (this.DebugOut >= DebugLevel.INFO)
        {
            this.Listener.DebugReturn(DebugLevel.INFO, "OpAuthenticate()");
        }

        Dictionary<byte, object> opParameters = new Dictionary<byte, object>();
        opParameters[ParameterCode.AppVersion] = appVersion;
        opParameters[ParameterCode.ApplicationId] = appId;

        if (!string.IsNullOrEmpty(userId))
        {
            opParameters[ParameterCode.UserId] = userId;
        }

        if (authValues != null && authValues.AuthType != CustomAuthenticationType.None)
        {
            if (!this.IsEncryptionAvailable)
            {
                this.Listener.DebugReturn(DebugLevel.ERROR, "OpAuthenticate() failed. When you want Custom Authentication encryption is mandatory.");
                return false;
            }

            opParameters[ParameterCode.ClientAuthenticationType] = (byte)authValues.AuthType;
            if (!string.IsNullOrEmpty(authValues.Secret))
            {
                opParameters[ParameterCode.Secret] = authValues.Secret;
            }
            else
            {
                if (!string.IsNullOrEmpty(authValues.AuthParameters))
                {
                    opParameters[ParameterCode.ClientAuthenticationParams] = authValues.AuthParameters;
                }
                if (authValues.AuthPostData != null)
                {
                    opParameters[ParameterCode.ClientAuthenticationData] = authValues.AuthPostData;
                }
            }
        }

        return this.OpCustom(OperationCode.Authenticate, opParameters, true, (byte)0, this.IsEncryptionAvailable);
    }
    private void ConnectToMasterServer(string id, string ticket)
    {
        //Debug.Log("connect to master server");
        //if (PhotonNetwork.AuthValues != null)
        //{

        //}
        //else
        //{

        //    PhotonNetwork.AuthValues = new AuthenticationValues()
        //    {

        //        AuthType = CustomAuthenticationType.Custom

        //    };

        //    PhotonNetwork.AuthValues.AddAuthParameter(id, ticket);

        //}

        AuthenticationValues authVals = new AuthenticationValues(AuthManager.playfabId);
        authVals.AuthType = CustomAuthenticationType.Custom;
        authVals.AddAuthParameter("username", AuthManager.playfabId);
        authVals.AddAuthParameter("token", ticket);

        PhotonNetwork.ConnectUsingSettings("1.0");

    }
    /// <summary>
    /// Sends this app's appId and appVersion to identify this application server side.
    /// This is an async request which triggers a OnOperationResponse() call.
    /// </summary>
    /// <remarks>
    /// This operation makes use of encryption, if that is established before.
    /// See: EstablishEncryption(). Check encryption with IsEncryptionAvailable.
    /// This operation is allowed only once per connection (multiple calls will have ErrorCode != Ok).
    /// </remarks>
    /// <param name="appId">Your application's name or ID to authenticate. This is assigned by Photon Cloud (webpage).</param>
    /// <param name="appVersion">The client's version (clients with differing client appVersions are separated and players don't meet).</param>
    /// <param name="authValues">Optional authentication values. The client can set no values or a UserId or some parameters for Custom Authentication by a server.</param>
    /// <param name="regionCode">Optional region code, if the client should connect to a specific Photon Cloud Region.</param>
    /// <param name="encryptionMode"></param>
    /// <param name="expectedProtocol"></param>
    /// <returns>If the operation could be sent (has to be connected).</returns>
    public virtual bool OpAuthenticateOnce(string appId, string appVersion, AuthenticationValues authValues, string regionCode, EncryptionMode encryptionMode, ConnectionProtocol expectedProtocol)
    {
        if (this.DebugOut >= DebugLevel.INFO)
            {
                this.Listener.DebugReturn(DebugLevel.INFO, "OpAuthenticate()");
            }

            var opParameters = new Dictionary<byte, object>();

            // shortcut, if we have a Token
            if (authValues != null && authValues.Token != null)
            {
                opParameters[ParameterCode.Secret] = authValues.Token;
                return this.OpCustom(OperationCode.AuthenticateOnce, opParameters, true, (byte)0, false);   // we don't have to encrypt, when we have a token (which is encrypted)
            }

            if (encryptionMode == EncryptionMode.DatagramEncryption && expectedProtocol != ConnectionProtocol.Udp)
            {
                Debug.LogWarning("Expected protocol set to UDP, due to encryption mode DatagramEncryption. Changing protocol in PhotonServerSettings from: " + PhotonNetwork.PhotonServerSettings.Protocol);
                PhotonNetwork.PhotonServerSettings.Protocol = ConnectionProtocol.Udp;
                expectedProtocol = ConnectionProtocol.Udp;
            }

            opParameters[ParameterCode.ExpectedProtocol] = (byte)expectedProtocol;
            opParameters[ParameterCode.EncryptionMode] = (byte)encryptionMode;

            opParameters[ParameterCode.AppVersion] = appVersion;
            opParameters[ParameterCode.ApplicationId] = appId;

            if (!string.IsNullOrEmpty(regionCode))
            {
                opParameters[ParameterCode.Region] = regionCode;
            }

            if (authValues != null)
            {
                if (!string.IsNullOrEmpty(authValues.UserId))
                {
                    opParameters[ParameterCode.UserId] = authValues.UserId;
                }

                if (authValues.AuthType != CustomAuthenticationType.None)
                {
                    opParameters[ParameterCode.ClientAuthenticationType] = (byte)authValues.AuthType;
                    if (!string.IsNullOrEmpty(authValues.Token))
                    {
                        opParameters[ParameterCode.Secret] = authValues.Token;
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(authValues.AuthGetParameters))
                        {
                            opParameters[ParameterCode.ClientAuthenticationParams] = authValues.AuthGetParameters;
                        }
                        if (authValues.AuthPostData != null)
                        {
                            opParameters[ParameterCode.ClientAuthenticationData] = authValues.AuthPostData;
                        }
                    }
                }
            }

            return this.OpCustom(OperationCode.AuthenticateOnce, opParameters, true, (byte)0, this.IsEncryptionAvailable);
    }