public void Authenticate(PlayFabAuthService authService, Action <LoginResult> resultCallback, Action <PlayFabError> errorCallback, AuthKeys authKeys)
        {
            // If username & password is empty, then do not continue, and Call back to Authentication UI Display
            if (!authService.RememberMe && string.IsNullOrEmpty(authService.Email) && string.IsNullOrEmpty(authService.Password))
            {
                authService.InvokeDisplayAuthentication();
                return;
            }

            // We have not opted for remember me in a previous session, so now we have to login the user with email & password.
            PlayFabClientAPI.LoginWithEmailAddress(new LoginWithEmailAddressRequest
            {
                Email    = authService.Email,
                Password = authService.Password,
                InfoRequestParameters = authService.InfoRequestParams,
                TitleId = PlayFabSettings.TitleId
            },
                                                   resultCallback,
                                                   error =>
            {
                // If user not registered, create one with RegisterPlayFabUser, because LoginWithEmailAddressRequest does not contains "CreateAccount" option.
                if (error.Error == PlayFabErrorCode.AccountNotFound)
                {
                    UnityEngine.Debug.LogWarning("Authentication failed. Try to register account.");
                    PlayFabClientAPI.RegisterPlayFabUser(new RegisterPlayFabUserRequest
                    {
                        Username = authService.Username,
                        Password = authService.Password,
                        Email    = authService.Email,
                        InfoRequestParameters = authService.InfoRequestParams,
                        TitleId = PlayFabSettings.TitleId
                    },
                                                         (registerSuccess) =>
                    {
                        // convert RegisterResult to LoginResult
                        resultCallback.Invoke(new LoginResult
                        {
                            AuthenticationContext = registerSuccess.AuthenticationContext,
                            EntityToken           = registerSuccess.EntityToken,
                            CustomData            = registerSuccess.CustomData,
                            NewlyCreated          = true,
                            PlayFabId             = registerSuccess.PlayFabId,
                            SessionTicket         = registerSuccess.SessionTicket,
                            SettingsForUser       = registerSuccess.SettingsForUser,
                            Request       = registerSuccess.Request,
                            LastLoginTime = DateTime.UtcNow
                        });
                    }, errorCallback);
                }
                // otherwise return error
                else
                {
                    errorCallback.Invoke(error);
                }
            });
        }
예제 #2
0
        public void Authenticate(PlayFabAuthService authService, Action <LoginResult> resultCallback, Action <PlayFabError> errorCallback, AuthKeys authKeys)
        {
            if (string.IsNullOrEmpty(authService.Username) || string.IsNullOrEmpty(authService.Password) || string.IsNullOrEmpty(authService.Email))
            {
                authService.InvokeDisplayAuthentication();
                return;
            }

            PlayFabClientAPI.LoginWithPlayFab(new LoginWithPlayFabRequest
            {
                InfoRequestParameters = authService.InfoRequestParams,
                Password = authService.Password,
                Username = authService.Username,
                TitleId  = PlayFabSettings.TitleId
            },
                                              resultCallback,
                                              error =>
            {
                // If user not registered, create one.
                // Do it because LoginWithPlayFabRequest does not contains "CreateAccount" option.
                if (error.Error == PlayFabErrorCode.AccountNotFound)
                {
                    UnityEngine.Debug.LogWarning("Authentication failed. Try to register account.");
                    PlayFabClientAPI.RegisterPlayFabUser(new RegisterPlayFabUserRequest
                    {
                        Username = authService.Username,
                        Password = authService.Password,
                        Email    = authService.Email,
                        InfoRequestParameters = authService.InfoRequestParams,
                        TitleId = PlayFabSettings.TitleId
                    },
                                                         (registerSuccess) =>
                    {
                        // convert RegisterResult to LoginResult
                        resultCallback.Invoke(new LoginResult
                        {
                            AuthenticationContext = registerSuccess.AuthenticationContext,
                            EntityToken           = registerSuccess.EntityToken,
                            CustomData            = registerSuccess.CustomData,
                            NewlyCreated          = true,
                            PlayFabId             = registerSuccess.PlayFabId,
                            SessionTicket         = registerSuccess.SessionTicket,
                            SettingsForUser       = registerSuccess.SettingsForUser,
                            Request       = registerSuccess.Request,
                            LastLoginTime = DateTime.UtcNow
                        });
                    }, errorCallback);
                }
                // otherwise return error
                else
                {
                    errorCallback.Invoke(error);
                }
            });
        }
예제 #3
0
        public void Authenticate(PlayFabAuthService authService, Action <LoginResult> resultCallback, Action <PlayFabError> errorCallback, AuthKeys authKeys)
        {
            if (authKeys == null || string.IsNullOrEmpty(authKeys.AuthTicket))
            {
                authService.InvokeDisplayAuthentication();
                return;
            }

            PlayFabClientAPI.LoginWithFacebookInstantGamesId(new LoginWithFacebookInstantGamesIdRequest
            {
                FacebookInstantGamesSignature = authKeys.AuthTicket,
                InfoRequestParameters         = authService.InfoRequestParams,
                CreateAccount = true
            }, resultCallback, errorCallback);
        }
        public void Authenticate(PlayFabAuthService authService, Action <LoginResult> resultCallback, Action <PlayFabError> errorCallback, AuthKeys authKeys = null)
        {
            if (authKeys == null || string.IsNullOrEmpty(authKeys.WindowsHelloPublicKeyHint) || string.IsNullOrEmpty(authKeys.WindowsHelloChallengeSignature))
            {
                authService.InvokeDisplayAuthentication();
                return;
            }

            PlayFabClientAPI.LoginWithWindowsHello(new LoginWithWindowsHelloRequest
            {
                ChallengeSignature    = authKeys.WindowsHelloChallengeSignature,
                PublicKeyHint         = authKeys.WindowsHelloPublicKeyHint,
                InfoRequestParameters = authService.InfoRequestParams
            }, resultCallback, errorCallback);
        }
예제 #5
0
        public void Authenticate(PlayFabAuthService authService, Action <LoginResult> resultCallback, Action <PlayFabError> errorCallback, AuthKeys authKeys)
        {
            if (authKeys == null || string.IsNullOrEmpty(authKeys.AuthTicket) || string.IsNullOrEmpty(authKeys.OpenIdConnectionId))
            {
                authService.InvokeDisplayAuthentication();
                return;
            }

            PlayFabClientAPI.LoginWithOpenIdConnect(new LoginWithOpenIdConnectRequest
            {
                ConnectionId          = authKeys.OpenIdConnectionId,
                IdToken               = authKeys.AuthTicket,
                InfoRequestParameters = authService.InfoRequestParams,
                CreateAccount         = true
            }, resultCallback, errorCallback);
        }