Exemplo n.º 1
0
 public void OnLogoutClicked()
 {
     UnlinkSilentAuth();
     ClearRememberMe();
     AuthType = Authtypes.None;
     SigninPanel.SetActive(true);
     SigninSuccessPanel.SetActive(false);
 }
Exemplo n.º 2
0
    public void Awake()
    {
        if (ClearPlayerPrefs)
        {
            UnlinkSilentAuth();
            ClearRememberMe();
            AuthType = Authtypes.None;
        }

        RememberMeUI.isOn = RememberMe;
        RememberMeUI.onValueChanged.AddListener((toggle) => { RememberMe = toggle; });
    }
    public void Link(Authtypes authType)
    {
        switch (authType)
        {
        case Authtypes.Google:
            AuthType = authType;
            PlayFabClientAPI.LinkGoogleAccount(new LinkGoogleAccountRequest()
            {
                ServerAuthCode = AuthTicket,
                ForceLink      = ForceLink
            }, (result) => {
                if (OnPlayFabLink != null)
                {
                    OnPlayFabLink.Invoke(authType, null);
                }
            }, (error) => {
                if (OnPlayFabLink != null)
                {
                    OnPlayFabLink.Invoke(authType, error);
                }
            });
            break;

        case Authtypes.Facebook:
            AuthType = authType;
            PlayFabClientAPI.LinkFacebookAccount(new LinkFacebookAccountRequest()
            {
                AccessToken = AuthTicket,
                ForceLink   = ForceLink
            }, (result) => {
                if (OnPlayFabLink != null)
                {
                    OnPlayFabLink.Invoke(authType, null);
                }
            }, (error) => {
                if (OnPlayFabLink != null)
                {
                    OnPlayFabLink.Invoke(authType, error);
                }
            });
            break;
        }
    }
Exemplo n.º 4
0
    private void OnPlayfabFacebookAuthComplete(LoginResult result)
    {
        // Store identity and session
        _playFabId     = result.PlayFabId;
        _sessionTicket = result.SessionTicket;

        RememberMeId = Guid.NewGuid().ToString();
        AuthType     = Authtypes.FaceBook;

        // 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
            );

        OnLoginSuccess(result);
    }
Exemplo n.º 5
0
 /// <summary>
 /// Kick off the authentication process by specific authtype.
 /// </summary>
 /// <param name="authType"></param>
 public void Authenticate(Authtypes authType)
 {
     AuthType = authType;
     Authenticate();
 }
Exemplo n.º 6
0
    private void AddAccountAndPassword()
    {
        SilentlyAuthenticate(
            (LoginResult result) =>
        {
            if (result == null)
            {
                //something went wrong with Silent Authentication, Check the debug console.
                OnPlayFabError(new PlayFabError()
                {
                    Error        = PlayFabErrorCode.UnknownError,
                    ErrorMessage = "Silent Authentication by Device failed"
                });
            }
            Debug.Log(result.PlayFabId);
            // Now add our username & password.
            PlayFabClientAPI.AddUsernamePassword(
                new AddUsernamePasswordRequest()
            {
                Username = result.PlayFabId,
                Email    = UsernameUI.text,
                Password = PasswordUI.text,
            },

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

                // If they opted to be remembered on next login.
                if (RememberMe)
                {
                    // Generate a new Guid
                    RememberMeId = Guid.NewGuid().ToString();

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

                // Override the auth type to ensure next login is using this auth type.
                AuthType = Authtypes.EmailAndPassword;

                // Report login result back to subscriber.
                OnLoginSuccess(result);
            },

                // Failure
                (PlayFabError error) =>
            {
                //Report error result back to subscriber
                OnPlayFabError(error);
            });
        });
    }
Exemplo n.º 7
0
    private void AuthenticateEmailPassword()
    {
        if (RememberMe && !string.IsNullOrEmpty(RememberMeId))
        {
            PlayFabClientAPI.LoginWithCustomID(
                new LoginWithCustomIDRequest()
            {
                TitleId               = PlayFabSettings.TitleId,
                CustomId              = RememberMeId,
                CreateAccount         = true,
                InfoRequestParameters = InfoRequestParams
            },

                //Success
                (LoginResult result) =>
            {
                _playFabId     = result.PlayFabId;
                _sessionTicket = result.SessionTicket;

                OnLoginSuccess(result);
            },

                //Failure
                (PlayFabError error) =>
            {
                OnPlayFabError(error);
            }
                );

            return;
        }

        if (string.IsNullOrEmpty(UsernameUI.text) && string.IsNullOrEmpty(PasswordUI.text))
        {
            OnDisplayAuthentication();
            return;
        }

        PlayFabClientAPI.LoginWithEmailAddress(
            new LoginWithEmailAddressRequest()
        {
            TitleId  = PlayFabSettings.TitleId,
            Email    = UsernameUI.text,
            Password = PasswordUI.text,
            InfoRequestParameters = InfoRequestParams
        },

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

            // 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
                    );
            }

            OnLoginSuccess(result);
        },

            // Failure
            (PlayFabError error) =>
        {
            OnPlayFabError(error);
        });
    }
Exemplo n.º 8
0
 private void Authenticate(Authtypes auth_type)
 {
     AuthType = auth_type;
     Authenticate();
 }
Exemplo n.º 9
0
        /// <summary>
        /// Linking for auth types
        /// </summary>
        /// <param name="authType"></param>
        public void Link(Authtypes authType)
        {
            switch (authType)
            {
            case Authtypes.Google:
                AuthType = authType;
                PlayFabClientAPI.LinkGoogleAccount(new LinkGoogleAccountRequest()
                {
                    ServerAuthCode = AuthTicket,
                    ForceLink      = ForceLink
                }, (result) =>
                {
                    if (OnPlayFabLink != null)
                    {
                        OnPlayFabLink.Invoke(authType, null);
                    }
                }, (error) =>
                {
                    if (OnPlayFabLink != null)
                    {
                        OnPlayFabLink.Invoke(authType, error);
                    }
                });
                break;

            case Authtypes.Facebook:
                AuthType = authType;
                PlayFabClientAPI.LinkFacebookAccount(new LinkFacebookAccountRequest()
                {
                    AccessToken = AuthTicket,
                    ForceLink   = ForceLink
                }, (result) =>
                {
                    if (OnPlayFabLink != null)
                    {
                        OnPlayFabLink.Invoke(authType, null);
                    }
                }, (error) =>
                {
                    if (OnPlayFabLink != null)
                    {
                        OnPlayFabLink.Invoke(authType, error);
                    }
                });
                break;

            case Authtypes.Xbox:
                AuthType = Authtypes.Xbox;
                PlayFabClientAPI.LinkXboxAccount(new LinkXboxAccountRequest()
                {
                    XboxToken = AuthTicket,
                    ForceLink = ForceLink
                }, (result) =>
                {
                    if (OnPlayFabLink != null)
                    {
                        OnPlayFabLink.Invoke(authType, null);
                    }
                }, (error) =>
                {
                    if (OnPlayFabLink != null)
                    {
                        OnPlayFabLink.Invoke(authType, error);
                    }
                });
                break;

            case Authtypes.Steam:
                AuthType = Authtypes.Steam;
                PlayFabClientAPI.LinkSteamAccount(new LinkSteamAccountRequest()
                {
                    SteamTicket = AuthTicket,
                    ForceLink   = ForceLink
                }, (result) =>
                {
                    if (OnPlayFabLink != null)
                    {
                        OnPlayFabLink.Invoke(authType, null);
                    }
                }, (error) =>
                {
                    if (OnPlayFabLink != null)
                    {
                        OnPlayFabLink.Invoke(authType, error);
                    }
                });
                break;

            case Authtypes.PSN:
                //TODO: how do we handle PSN in the sdks?
                //This might need to be generated.
                break;

            case Authtypes.OpenId:
                AuthType = Authtypes.OpenId;

                break;
            }
        }