示例#1
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;
            }
        }
示例#2
0
        private async Task AuthenticateFacebookUser(FacebookUser loggedInUser)
        {
            OnLoggingIn?.Invoke();

            //grab the auth ticket from that user
            AuthTicket = loggedInUser.Token;

            var result = await PlayFabClient.LoginWithFacebookAsync(new LoginWithFacebookRequest()
            {
                TitleId               = PlayFabSettings.staticSettings.TitleId,
                AccessToken           = AuthTicket,
                CreateAccount         = true,
                InfoRequestParameters = InfoRequestParams
            }).ConfigureAwait(false);

            LoginResult(result);
        }
示例#3
0
        public async Task LinkFacebook()
        {
            //If there is no Facebook client, we can't do this
            if (null == Facebook)
            {
                Logout();
                OnPlayFabError?.Invoke(new PlayFabError()
                {
                    ErrorMessage = "No FacebookClient was detected",
                });
            }

            //Check if the user needs to log into Facebook
            if (!Facebook.LoggedIn || string.IsNullOrEmpty(AuthTicket))
            {
                //sign up for the logged in event
                Facebook.OnLoginSuccess -= OnFacebookLoggedIn;
                Facebook.OnLoginSuccess += OnFacebookLoggedIn;
                Facebook.OnLoginError   -= Facebook_OnLoginError;
                Facebook.OnLoginError   += Facebook_OnLoginError;

                //try to log in
                Facebook.Login();
            }
            else
            {
                OnLoggingIn?.Invoke();

                //grab the auth ticket from that user
                AuthTicket = Facebook.User.Token;

                var result = await PlayFabClient.LinkFacebookAccountAsync(new LinkFacebookAccountRequest()
                {
                    AccessToken = AuthTicket,
                }).ConfigureAwait(false);

                LoginResult(result);
            }
        }