示例#1
0
 internal void InvokeDisplayAuthentication()
 {
     if (OnDisplayAuthentication != null)
     {
         OnDisplayAuthentication.Invoke();
     }
 }
示例#2
0
    /// <summary>
    /// Authenticate the user by the Auth Type that was defined.
    /// </summary>
    public void Authenticate()
    {
        switch (AuthType)
        {
        case Authtypes.None:
            if (OnDisplayAuthentication != null)
            {
                OnDisplayAuthentication.Invoke();
            }
            break;

        case Authtypes.Silent:
            SilentlyAuthenticate();
            break;

        case Authtypes.EmailAndPassword:
            AuthenticateEmailPassword();
            break;

        case Authtypes.RegisterPlayFabAccount:
            AddAccountAndPassword();
            break;

        case Authtypes.GoogleAccount:
            AddGoogleAccount();
            break;
        }
    }
示例#3
0
        /// <summary>
        /// Authenticate the user by the Auth Type that was defined.
        /// </summary>
        public async Task Authenticate()
        {
            switch (AuthType)
            {
            case AuthType.Silent:
            {
                OnLoggingIn?.Invoke();
                var platform = CrossDeviceInfo.Current.Platform;
                await SilentlyAuthenticate(platform).ConfigureAwait(false);
            }
            break;

            case AuthType.EmailAndPassword:
            {
                OnLoggingIn?.Invoke();
                await AuthenticateEmailPassword().ConfigureAwait(false);
            }
            break;

            case AuthType.RegisterPlayFabAccount:
            {
                OnLoggingIn?.Invoke();
                await AddAccountAndPassword().ConfigureAwait(false);
            }
            break;

            case AuthType.Facebook:
            {
                await AuthenticateFacebook().ConfigureAwait(false);
            }
            break;

            case AuthType.Google:
            {
                OnLoggingIn?.Invoke();
                await AuthenticateGooglePlayGames().ConfigureAwait(false);
            }
            break;

            default:
            {
                if (RememberMe)
                {
                    OnLoggingIn?.Invoke();
                    AuthType = AuthType.EmailAndPassword;
                    await AuthenticateEmailPassword().ConfigureAwait(false);
                }
                else
                {
                    OnDisplayAuthentication?.Invoke();
                }
            }
            break;
            }
        }
示例#4
0
        /// <summary>
        /// Authenticate a user in PlayFab using an Email & Password combo
        /// </summary>
        protected virtual async Task AuthenticateEmailPassword()
        {
            //Check if the users has opted to be remembered.
            if (RememberMe && !string.IsNullOrEmpty(RememberMeId))
            {
                //If the user is being remembered, then log them in with a customid that was
                //generated by the RememberMeId property
                var customIdResult = await PlayFabClient.LoginWithCustomIDAsync(new LoginWithCustomIDRequest()
                {
                    TitleId               = PlayFabSettings.staticSettings.TitleId,
                    CustomId              = RememberMeId,
                    CreateAccount         = true,
                    InfoRequestParameters = this.InfoRequestParams
                }).ConfigureAwait(false);

                LoginResult(customIdResult);

                return;
            }
            else if (string.IsNullOrEmpty(Email) || string.IsNullOrEmpty(Password))
            {
                //a good catch: If username & password is empty, then do not continue, and Call back to Authentication UI Display
                OnDisplayAuthentication.Invoke();
                return;
            }
            else
            {
                //We have not opted for remember me in a previous session, so now we have to login the user with email & password.
                var emailResult = await PlayFabClient.LoginWithEmailAddressAsync(new LoginWithEmailAddressRequest()
                {
                    TitleId  = PlayFabSettings.staticSettings.TitleId,
                    Email    = this.Email,
                    Password = this.Password,
                    InfoRequestParameters = this.InfoRequestParams
                }).ConfigureAwait(false);

                //Note: At this point, they already have an account with PlayFab using a Username (email) & Password
                //If RememberMe is checked, then generate a new Guid for Login with CustomId.
                if (RememberMe)
                {
                    RememberMeId = Guid.NewGuid().ToString();
                    AuthType     = AuthType.EmailAndPassword;

                    //Fire and forget, but link a custom ID to this PlayFab Account.
                    await PlayFabClient.LinkCustomIDAsync(new LinkCustomIDRequest()
                    {
                        CustomId  = RememberMeId,
                        ForceLink = ForceLink
                    }).ConfigureAwait(false);
                }

                LoginResult(emailResult);
            }
        }
示例#5
0
        /// <summary>
        /// Authenticate the user by the Auth Type that was defined.
        /// </summary>
        public void Authenticate()
        {
            var authType = AuthType;

            Debug.Log(authType);
            switch (authType)
            {
            case Authtypes.None:
                if (OnDisplayAuthentication != null)
                {
                    OnDisplayAuthentication.Invoke();
                }
                break;

            case Authtypes.Silent:
                SilentlyAuthenticate();
                break;

            case Authtypes.EmailAndPassword:
                AuthenticateEmailPassword();
                break;

            case Authtypes.RegisterPlayFabAccount:
                AddAccountAndPassword();
                break;

            case Authtypes.Steam:
                AuthenticateSteam();
                break;

            case Authtypes.Facebook:
                AuthenticateFacebook();
                break;

            case Authtypes.Google:
                AuthenticateGooglePlayGames();
                break;

            case Authtypes.Xbox:
                AuthenticateXbox();
                break;

            case Authtypes.PSN:
                AuthenticatePSN();
                break;

            case Authtypes.OpenId:
                AuthenticateOpenId();
                break;
            }
        }
示例#6
0
        public void Authenticate(AuthKeys authKeys = null)
        {
            if (AuthType == AuthTypes.None)
            {
                if (OnDisplayAuthentication != null)
                {
                    OnDisplayAuthentication.Invoke();
                }

                return;
            }

            if (RememberMe && !string.IsNullOrEmpty(RememberMeId))
            {
                PlayFabClientAPI.LoginWithCustomID(new LoginWithCustomIDRequest
                {
                    CustomId = RememberMeId,
                    InfoRequestParameters = InfoRequestParams,
                    CreateAccount         = true
                }, InvokeLoginSuccess, InvokePlayFabError);
                return;
            }

            var auth = _authStrategies[AuthType];

            auth.Authenticate(this, resultCallback =>
            {
                // Store Identity and session
                AuthenticationContext = resultCallback.AuthenticationContext;

                // Note: At this point, they already have an account with PlayFab using a Username (email) & Password
                // If RememberMe is checked, then generate a new Guid for Login with CustomId.
                if (RememberMe && string.IsNullOrEmpty(RememberMeId))
                {
                    //Fire and forget, but link a custom ID to this PlayFab Account.
                    PlayFabClientAPI.LinkCustomID(new LinkCustomIDRequest
                    {
                        CustomId              = GetOrCreateRememberMeId(),
                        ForceLink             = ForceLink,
                        AuthenticationContext = AuthenticationContext
                    }, null, null);
                }
                InvokeLoginSuccess(resultCallback);
            }, InvokePlayFabError, authKeys);
        }
    private void AuthenticateFacebook()
    {
#if FACEBOOK
        if (FB.IsInitialized && FB.IsLoggedIn && !string.IsNullOrEmpty(AuthTicket))
        {
            PlayFabClientAPI.LoginWithFacebook(new LoginWithFacebookRequest()
            {
                TitleId               = PlayFabSettings.TitleId,
                AccessToken           = AuthTicket,
                CreateAccount         = true,
                InfoRequestParameters = InfoRequestParams
            }, (result) =>
            {
                //Store Identity and session
                _playFabId     = result.PlayFabId;
                _sessionTicket = result.SessionTicket;

                //check if we want to get this callback directly or send to event subscribers.
                if (OnLoginSuccess != null)
                {
                    //report login result back to the subscriber
                    OnLoginSuccess.Invoke(result);
                }
            }, (error) =>
            {
                //report errro back to the subscriber
                if (OnPlayFabError != null)
                {
                    OnPlayFabError.Invoke(error);
                }
            });
        }
        else
        {
            if (OnDisplayAuthentication != null)
            {
                OnDisplayAuthentication.Invoke();
            }
        }
#endif
    }
        /// <summary>
        /// Authenticate the user by the Auth Type that was defined.
        /// </summary>
        public void Authenticate()
        {
            switch (AuthType)
            {
            case Authtypes.None:
                OnDisplayAuthentication?.Invoke();
                break;

            case Authtypes.Silent:
                SilentlyAuthenticate();
                break;

            case Authtypes.EmailAndPassword:
                AuthenticateEmailPassword();
                break;

            case Authtypes.RegisterPlayFabAccount:
                AddAccountAndPassword();
                break;
            }
        }
示例#9
0
    /// <summary>
    /// Authenticate a user in PlayFab using an Email & Password combo
    /// </summary>
    private void AuthenticateEmailPassword()
    {
        //Check if the users has opted to be remembered.
        if (RememberMe && !string.IsNullOrEmpty(RememberMeId))
        {
            // If the user is being remembered, then log them in with a customid that was
            // generated by the RememberMeId property
            PlayFabClientAPI.LoginWithCustomID(
                new LoginWithCustomIDRequest()
            {
                TitleId               = PlayFabSettings.TitleId,
                CustomId              = RememberMeId,
                CreateAccount         = true,
                InfoRequestParameters = InfoRequestParams
            },

                // Success
                (LoginResult result) =>
            {
                //Store identity and session
                _playFabId     = result.PlayFabId;
                _sessionTicket = result.SessionTicket;

                if (OnLoginSuccess != null)
                {
                    //report login result back to subscriber
                    OnLoginSuccess.Invoke(result);
                }
            },

                // Failure
                (PlayFabError error) =>
            {
                if (OnPlayFabError != null)
                {
                    //report error back to subscriber
                    OnPlayFabError.Invoke(error);
                }
            });

            return;
        }

        // If username & password is empty, then do not continue, and Call back to Authentication UI Display
        if (string.IsNullOrEmpty(Email) && string.IsNullOrEmpty(Password))
        {
            OnDisplayAuthentication.Invoke();
            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()
        {
            TitleId  = PlayFabSettings.TitleId,
            Email    = Email,
            Password = Password,
            InfoRequestParameters = InfoRequestParams
        },

            // Success
            (LoginResult result) =>
        {
            // Store identity and session
            _playFabId     = result.PlayFabId;
            _sessionTicket = result.SessionTicket;

            // Note: At this point, they already have an account with PlayFab using a Username (email) & Password
            // If RememberMe is checked, then generate a new Guid for Login with CustomId.
            if (RememberMe)
            {
                RememberMeId = Guid.NewGuid().ToString();
                AuthType     = Authtypes.EmailAndPassword;

                // Fire and forget, but link a custom ID to this PlayFab Account.
                PlayFabClientAPI.LinkCustomID(
                    new LinkCustomIDRequest
                {
                    CustomId  = RememberMeId,
                    ForceLink = ForceLink
                },
                    null,       // Success callback
                    null        // Failure callback
                    );
            }

            if (OnLoginSuccess != null)
            {
                //report login result back to subscriber
                OnLoginSuccess.Invoke(result);
            }
        },

            // Failure
            (PlayFabError error) =>
        {
            if (OnPlayFabError != null)
            {
                //Report error back to subscriber
                OnPlayFabError.Invoke(error);
            }
        });
    }