// Attempt login with the specific username/password public void Login(string username, string password) { InitBC(); // Show loading screen ChangeScreen(ScreenState.LoggingIn); // Authenticate with brainCloud m_bcWrapper.AuthenticateUniversal(username, password, true, HandlePlayerState, DieWithMessage, "Login Failed"); }
//click authentication button public void AuthenticateBC() { if (_username.text.Equals("") || _password.text.Equals("")) { SetResponseText("Both User Name and Password fields need to be filled", Color.red); return; } _bc.AuthenticateUniversal ( _username.text, _password.text, true, AuthSuccessCallback, AuthErrorCallback ); }
//Called from Unity Button, attempting to login public void Login() { string username = GameManager.Instance.UsernameInputField.text; string password = GameManager.Instance.PasswordInputField.text; if (username.IsNullOrEmpty()) { StateManager.Instance.AbortToSignIn($"Please provide a username"); return; } if (password.IsNullOrEmpty()) { StateManager.Instance.AbortToSignIn($"Please provide a password"); return; } GameManager.Instance.CurrentUserInfo.Username = username; InitializeBC(); // Authenticate with brainCloud m_bcWrapper.AuthenticateUniversal(username, password, true, HandlePlayerState, LoggingInError, "Login Failed"); }
void OnGUI() { float tw = Screen.width / 14.0f; float th = Screen.height / 7.0f; Rect dialog = new Rect(tw, th, Screen.width - tw * 2, Screen.height - th * 2); float offsetX = 30; float offsetY = 30; Rect innerDialog = new Rect(dialog.x + offsetX, dialog.y + offsetY, dialog.width - (offsetX * 2), dialog.height - (offsetY * 2)); GUI.Box(dialog, "Unity Example"); GUILayout.BeginArea(innerDialog); GUILayout.Box("Choose Authentication Type"); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); m_selectedAuth = GUILayout.SelectionGrid(m_selectedAuth, m_authTypes, 4); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if (m_selectedAuth == (int)eAuthTypes.EMAIL) { GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); GUILayout.Label("Email:"); GUILayout.Label("Password:"******"Authenticate", GUILayout.ExpandWidth(false))) { m_authStatus = "Attempting to authenticate"; // clear out any previous profile or anonymous ids _bc.ResetStoredProfileId(); _bc.ResetStoredAnonymousId(); _bc.AuthenticateEmailPassword( m_emailId, m_emailPwd, true, OnSuccess_Authenticate, OnError_Authenticate); } } else if (m_selectedAuth == (int)eAuthTypes.UNIVERSAL) { GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); GUILayout.Label("User Id:"); GUILayout.Label("Password:"******"Authenticate", GUILayout.ExpandWidth(false))) { m_authStatus = "Attempting to authenticate"; // clear out any previous profile or anonymous ids _bc.ResetStoredProfileId(); _bc.ResetStoredAnonymousId(); _bc.AuthenticateUniversal( m_universalUserId, m_universalPwd, true, OnSuccess_Authenticate, OnError_Authenticate); } } else if (m_selectedAuth == (int)eAuthTypes.ANONYMOUS) { GUILayout.Label("Profile Id: " + _bc.GetStoredProfileId()); GUILayout.Label("Anonymous Id: " + _bc.GetStoredAnonymousId()); GUILayout.BeginHorizontal(); if (GUILayout.Button("Authenticate", GUILayout.ExpandWidth(false))) { m_authStatus = "Attempting to authenticate"; _bc.AuthenticateAnonymous(OnSuccess_Authenticate, OnError_Authenticate); } if (GUILayout.Button("Reset Profile Id", GUILayout.ExpandWidth(false))) { _bc.ResetStoredProfileId(); } if (GUILayout.Button("Reset Anonymous Id", GUILayout.ExpandWidth(false))) { _bc.ResetStoredAnonymousId(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } else if (m_selectedAuth == (int)eAuthTypes.GOOGLE) { GUILayout.Label("Google Id: " + m_googleId); GUILayout.Label("Server Auth Code: " + m_serverAuthCode); if (GUILayout.Button("Google Signin", GUILayout.ExpandWidth(false))) { #if UNITY_ANDROID m_authStatus += "\n\nInfo: If the authentication popup appears but nothing occurs after, it probably means the app isn't fully set up. Please follow the instruction here:\nhttp://getbraincloud.com/apidocs/portal-usage/authentication-google/ \n\n"; PlayGamesPlatform.Activate().Authenticate((bool success) => { if (success) { m_googleId = PlayGamesPlatform.Instance.GetUserId(); m_serverAuthCode = PlayGamesPlatform.Instance.GetServerAuthCode(); m_authStatus += "\nGoogle Auth Success. Now click \"Authenticate\"\n\n"; } else { m_authStatus += "\nGoogle Auth Failed. See documentation: https://github.com/playgameservices/play-games-plugin-for-unity\n"; m_authStatus += "Note: this can only be tested on an Android Device\n\n"; } }); #else m_authStatus += "\n\nGoogle Login will only work on an Android Device. Please build to a test device\n\n"; #endif } GUILayout.Label("Profile Id: " + _bc.GetStoredProfileId()); GUILayout.Label("Anonymous Id: " + _bc.GetStoredAnonymousId()); GUILayout.BeginHorizontal(); if (GUILayout.Button("Authenticate", GUILayout.ExpandWidth(false))) { m_authStatus = "Attempting to authenticate"; _bc.AuthenticateGoogle(m_googleId, m_serverAuthCode, true, OnSuccess_Authenticate, OnError_Authenticate); } if (GUILayout.Button("Reset Profile Id", GUILayout.ExpandWidth(false))) { _bc.ResetStoredProfileId(); } if (GUILayout.Button("Reset Anonymous Id", GUILayout.ExpandWidth(false))) { _bc.ResetStoredAnonymousId(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } else if (m_selectedAuth == (int)eAuthTypes.FACEBOOK) { #if UNITY_WEBGL || UNITY_STANDALONE_WIN GUILayout.Label("Token Id: " + AccessToken.CurrentAccessToken.TokenString); GUILayout.Label("User Id: " + _localFacebookUser.id); GUILayout.Label("First Name: " + _localFacebookUser.first_name); GUILayout.BeginHorizontal(); if (GUILayout.Button("Initialize", GUILayout.ExpandWidth(false))) { if (!FB.IsInitialized) { FB.Init(InitCallback, HideUnity); } else { FB.ActivateApp(); } } if (GUILayout.Button("Authenticate", GUILayout.ExpandWidth(false))) { m_authStatus = "Attempting to authenticate"; var perms = new List <string>() { "public_profile", "email" }; FB.LogInWithReadPermissions(perms, AuthCallback); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); #else m_authStatus = "Facebook login is only available on WebGL & Windows Standalone"; #endif } else if (m_selectedAuth == (int)eAuthTypes.XBOXLIVE) { #if UNITY_WSA if (_xboxLiveUser.IsSignedIn) { GUILayout.Label("Player Number: " + playerNumber); GUILayout.Label("Gamer Tag: " + _xboxLiveUser.Gamertag); GUILayout.Label("User ID: " + _xboxLiveUser.XboxUserId); GUILayout.BeginHorizontal(); } if (GUILayout.Button("Sign In", GUILayout.ExpandWidth(false))) { StartCoroutine(SignInManager.Instance.SignInPlayer(playerNumber)); } #else m_authStatus = "Xbox Live login is only available on Universal Windows Platform"; #endif } m_scrollPosition = GUILayout.BeginScrollView(m_scrollPosition, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); GUILayout.TextArea(m_authStatus, GUILayout.ExpandHeight(true)); GUILayout.EndScrollView(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Clear Log", GUILayout.Height(25), GUILayout.Width(100))) { m_authStatus = ""; } GUILayout.EndHorizontal(); GUILayout.EndArea(); }
void OnWindow(int windowId) { GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.BeginVertical(); GUILayout.Label("Username"); _username = GUILayout.TextField(_username, GUILayout.MinWidth(200)); GUILayout.Label("Password"); _password = GUILayout.PasswordField(_password, '*', GUILayout.MinWidth(100)); GUILayout.Space(10); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Authenticate", GUILayout.MinHeight(30), GUILayout.MinWidth(100))) { if (_username.Length == 0 || _password.Length == 0) { AppendLog("Username/password can't be empty"); } else { AppendLog("Attempting to authenticate..."); PlayerPrefs.SetString("username", _username); PlayerPrefs.SetString("password", _password); /////////////////////////////////////////////////////////////////// // brainCloud authentication /////////////////////////////////////////////////////////////////// BrainCloud.AuthenticateUniversal(_username, _password, true, OnSuccess_Authenticate, OnError_Authenticate); /////////////////////////////////////////////////////////////////// } } GUILayout.EndHorizontal(); GUILayout.Space(20); _scrollPosition = GUILayout.BeginScrollView(_scrollPosition, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); GUILayout.TextArea(_authStatus); GUILayout.EndScrollView(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Clear Log", GUILayout.MinHeight(30), GUILayout.MinWidth(100))) { _authStatus = ""; } GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); GUILayout.EndVertical(); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); }
void OnGUI() { float tw = Screen.width / 14.0f; float th = Screen.height / 7.0f; Rect dialog = new Rect(tw, th, Screen.width - tw * 2, Screen.height - th * 2); float offsetX = 30; float offsetY = 30; Rect innerDialog = new Rect(dialog.x + offsetX, dialog.y + offsetY, dialog.width - (offsetX * 2), dialog.height - (offsetY * 2)); GUI.Box(dialog, "Unity Example"); GUILayout.BeginArea(innerDialog); GUILayout.Box("Choose Authentication Type"); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); m_selectedAuth = GUILayout.SelectionGrid(m_selectedAuth, m_authTypes, 4); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if (m_selectedAuth == (int)eAuthTypes.EMAIL) { GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); GUILayout.Label("Email:"); GUILayout.Label("Password:"******"Authenticate", GUILayout.ExpandWidth(false))) { m_authStatus = "Attempting to authenticate"; // clear out any previous profile or anonymous ids _bc.ResetStoredProfileId(); _bc.ResetStoredAnonymousId(); _bc.AuthenticateEmailPassword( m_emailId, m_emailPwd, true, OnSuccess_Authenticate, OnError_Authenticate); } } else if (m_selectedAuth == (int)eAuthTypes.UNIVERSAL) { GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); GUILayout.Label("User Id:"); GUILayout.Label("Password:"******"Authenticate", GUILayout.ExpandWidth(false))) { m_authStatus = "Attempting to authenticate"; // clear out any previous profile or anonymous ids _bc.ResetStoredProfileId(); _bc.ResetStoredAnonymousId(); _bc.AuthenticateUniversal( m_universalUserId, m_universalPwd, true, OnSuccess_Authenticate, OnError_Authenticate); } } /*else if (m_selectedAuth == (int) eAuthTypes.TWITTER) * { * GUILayout.BeginHorizontal(); * GUILayout.BeginVertical(); * if (GUILayout.Button("Get PIN")) * { * StartCoroutine(Twitter.API.GetRequestToken(CONSUMER_KEY, CONSUMER_SECRET, * new Twitter.RequestTokenCallback(this.OnSuccess_GetPIN))); * } * GUILayout.EndVertical(); * GUILayout.BeginVertical(); * GUILayout.Label("PIN:"); * m_emailId = GUILayout.TextField(m_emailId, GUILayout.MinWidth(200)); * //m_emailPwd = GUILayout.PasswordField(m_emailPwd, '*', GUILayout.MinWidth(200)); * GUILayout.EndVertical(); * GUILayout.FlexibleSpace(); * GUILayout.EndHorizontal(); * * if (GUILayout.Button("Enter PIN", GUILayout.ExpandWidth(false))) * { * m_authStatus = "Attempting to authenticate"; * * // clear out any previous profile or anonymous ids * _bc.ResetStoredProfileId(); * _bc.ResetStoredAnonymousId(); * StartCoroutine(Twitter.API.GetAccessToken(CONSUMER_KEY, CONSUMER_SECRET, m_RequestTokenResponse.Token, m_emailId, * new Twitter.AccessTokenCallback(this.OnSuccess_AuthenticateTwitter))); * //_bc.AuthenticationService.AuthenticateTwitter() * * //_bc.AuthenticateEmailPassword( * // m_emailId, m_emailPwd, true, OnSuccess_Authenticate, OnError_Authenticate); * } * }*/ else if (m_selectedAuth == (int)eAuthTypes.ANONYMOUS) { GUILayout.Label("Profile Id: " + _bc.GetStoredProfileId()); GUILayout.Label("Anonymous Id: " + _bc.GetStoredAnonymousId()); GUILayout.BeginHorizontal(); if (GUILayout.Button("Authenticate", GUILayout.ExpandWidth(false))) { m_authStatus = "Attempting to authenticate"; _bc.AuthenticateAnonymous(OnSuccess_Authenticate, OnError_Authenticate); } if (GUILayout.Button("Reset Profile Id", GUILayout.ExpandWidth(false))) { _bc.ResetStoredProfileId(); } if (GUILayout.Button("Reset Anonymous Id", GUILayout.ExpandWidth(false))) { _bc.ResetStoredAnonymousId(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } else if (m_selectedAuth == (int)eAuthTypes.GOOGLE) { GUILayout.Label("Google Id: " + m_googleId); GUILayout.Label("Server Auth Code: " + m_serverAuthCode); if (GUILayout.Button("Google Signin", GUILayout.ExpandWidth(false))) { #if UNITY_ANDROID m_authStatus += "\n\nInfo: If the authentication popup appears but nothing occurs after, it probably means the app isn't fully set up. Please follow the instruction here:\nhttp://getbraincloud.com/apidocs/portal-usage/authentication-google/ \n\n"; PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder() .RequestIdToken() .RequestServerAuthCode(false) .Build(); PlayGamesPlatform.InitializeInstance(config); PlayGamesPlatform.Activate().Authenticate((bool success) => { if (success) { m_googleId = PlayGamesPlatform.Instance.GetUserId(); m_serverAuthCode = PlayGamesPlatform.Instance.GetServerAuthCode(); m_authStatus += "\nGoogle Auth Success. Now click \"Authenticate\"\n\n"; } else { m_authStatus += "\nGoogle Auth Failed. See documentation: https://github.com/playgameservices/play-games-plugin-for-unity\n"; m_authStatus += "Note: this can only be tested on an Android Device\n\n"; } }); #else m_authStatus += "\n\nGoogle Login will only work on an Android Device. Please build to a test device\n\n"; #endif } GUILayout.Label("Profile Id: " + _bc.GetStoredProfileId()); GUILayout.Label("Anonymous Id: " + _bc.GetStoredAnonymousId()); GUILayout.BeginHorizontal(); if (GUILayout.Button("Authenticate", GUILayout.ExpandWidth(false))) { m_authStatus = "Attempting to authenticate"; _bc.AuthenticateGoogle(m_googleId, m_serverAuthCode, true, OnSuccess_Authenticate, OnError_Authenticate); } if (GUILayout.Button("Reset Profile Id", GUILayout.ExpandWidth(false))) { _bc.ResetStoredProfileId(); } if (GUILayout.Button("Reset Anonymous Id", GUILayout.ExpandWidth(false))) { _bc.ResetStoredAnonymousId(); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } m_scrollPosition = GUILayout.BeginScrollView(m_scrollPosition, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); GUILayout.TextArea(m_authStatus, GUILayout.ExpandHeight(true)); GUILayout.EndScrollView(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Clear Log", GUILayout.Height(25), GUILayout.Width(100))) { m_authStatus = ""; } GUILayout.EndHorizontal(); //GUILayout.FlexibleSpace(); //GUILayout.Box("Stored Information"); GUILayout.EndArea(); }