public void TestGlobalErrorCallbackUsingWrapper() { BrainCloudClient.Instance.RegisterGlobalErrorCallback(GlobalErrorHandler); TestResult tr = new TestResult(); BrainCloudWrapper.GetInstance().AuthenticateUniversal("", "zzz", true, tr.ApiSuccess, tr.ApiError, this); tr.RunExpectFail(StatusCodes.FORBIDDEN, ReasonCodes.TOKEN_DOES_NOT_MATCH_USER); Assert.AreEqual(_globalErrorCount, 1); }
public void Login() { m_username = GameObject.Find("UsernameBox").GetComponent <InputField>().text; m_password = GameObject.Find("PasswordBox").GetComponent <InputField>().text; if (m_connectedToPhoton) { if (m_username.Length == 0 || m_password.Length == 0) { GameObject.Find("DialogDisplay").GetComponent <DialogDisplay>().DisplayDialog("Username/password can't be empty!"); } else if (!m_username.Contains("@")) { GameObject.Find("DialogDisplay").GetComponent <DialogDisplay>().DisplayDialog("Not a valid email address!"); } else { AppendLog("Attempting to authenticate..."); PlayerPrefs.SetString("username", m_username); if (GameObject.Find("Toggle").GetComponent <Toggle>().isOn) { PlayerPrefs.SetString("password", m_password); PlayerPrefs.SetInt("remember", 1); } else { PlayerPrefs.SetString("password", ""); PlayerPrefs.SetInt("remember", 0); } m_isLoggingIn = true; /////////////////////////////////////////////////////////////////// // brainCloud authentication /////////////////////////////////////////////////////////////////// BrainCloudWrapper.GetInstance().AuthenticateEmailPassword(m_username, m_password, true, OnSuccess_Authenticate, OnError_Authenticate); //BrainCloudWrapper.GetInstance().AuthenticateUniversal(m_username, m_password, true, OnSuccess_Authenticate, OnError_Authenticate); /////////////////////////////////////////////////////////////////// } } }
void OnWindow(int windowId) { GUILayout.FlexibleSpace(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); GUILayout.BeginVertical(); GUILayout.Label("Username"); m_username = GUILayout.TextField(m_username, GUILayout.MinWidth(200)); GUILayout.Label("Password"); m_password = GUILayout.PasswordField(m_password, '*', GUILayout.MinWidth(100)); GUILayout.Space(10); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Authenticate", GUILayout.MinHeight(30), GUILayout.MinWidth(100))) { if (m_username.Length == 0 || m_password.Length == 0) { AppendLog("Username/password can't be empty"); } else { AppendLog("Attempting to authenticate..."); PlayerPrefs.SetString("username", m_username); PlayerPrefs.SetString("password", m_password); /////////////////////////////////////////////////////////////////// // brainCloud authentication /////////////////////////////////////////////////////////////////// BrainCloudWrapper.GetInstance().AuthenticateUniversal(m_username, m_password, true, OnSuccess_Authenticate, OnError_Authenticate); /////////////////////////////////////////////////////////////////// } } GUILayout.EndHorizontal(); GUILayout.Space(20); m_scrollPosition = GUILayout.BeginScrollView(m_scrollPosition, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); GUILayout.TextArea(m_authStatus); GUILayout.EndScrollView(); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("Clear Log", GUILayout.MinHeight(30), GUILayout.MinWidth(100))) { m_authStatus = ""; } GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); GUILayout.EndVertical(); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); }
void OnGUI() { float tw = Screen.width / 5; float th = Screen.height / 7; Rect dialog = new Rect(tw, th, tw * 3, th * 5); 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, m_authTypes.Length); 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 BrainCloudWrapper.GetInstance().ResetStoredProfileId(); BrainCloudWrapper.GetInstance().ResetStoredAnonymousId(); BrainCloudWrapper.GetInstance().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 BrainCloudWrapper.GetInstance().ResetStoredProfileId(); BrainCloudWrapper.GetInstance().ResetStoredAnonymousId(); BrainCloudWrapper.GetInstance().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 BrainCloudWrapper.GetInstance().ResetStoredProfileId(); BrainCloudWrapper.GetInstance().ResetStoredAnonymousId(); StartCoroutine(Twitter.API.GetAccessToken(CONSUMER_KEY, CONSUMER_SECRET, m_RequestTokenResponse.Token, m_emailId, new Twitter.AccessTokenCallback(this.OnSuccess_AuthenticateTwitter))); //BrainCloudWrapper.GetBC().AuthenticationService.AuthenticateTwitter() //BrainCloudWrapper.GetInstance().AuthenticateEmailPassword( // m_emailId, m_emailPwd, true, OnSuccess_Authenticate, OnError_Authenticate); } } else if (m_selectedAuth == (int)eAuthTypes.ANONYMOUS) { GUILayout.Label("Profile Id: " + BrainCloudWrapper.GetInstance().GetStoredProfileId()); GUILayout.Label("Anonymous Id: " + BrainCloudWrapper.GetInstance().GetStoredAnonymousId()); GUILayout.BeginHorizontal(); if (GUILayout.Button("Authenticate", GUILayout.ExpandWidth(false))) { m_authStatus = "Attempting to authenticate"; BrainCloudWrapper.GetInstance().AuthenticateAnonymous(OnSuccess_Authenticate, OnError_Authenticate); } if (GUILayout.Button("Reset Profile Id", GUILayout.ExpandWidth(false))) { BrainCloudWrapper.GetInstance().ResetStoredProfileId(); } if (GUILayout.Button("Reset Anonymous Id", GUILayout.ExpandWidth(false))) { BrainCloudWrapper.GetInstance().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(); }
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 BrainCloudWrapper.GetInstance().ResetStoredProfileId(); BrainCloudWrapper.GetInstance().ResetStoredAnonymousId(); BrainCloudWrapper.GetInstance().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 BrainCloudWrapper.GetInstance().ResetStoredProfileId(); BrainCloudWrapper.GetInstance().ResetStoredAnonymousId(); BrainCloudWrapper.GetInstance().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 * BrainCloudWrapper.GetInstance().ResetStoredProfileId(); * BrainCloudWrapper.GetInstance().ResetStoredAnonymousId(); * StartCoroutine(Twitter.API.GetAccessToken(CONSUMER_KEY, CONSUMER_SECRET, m_RequestTokenResponse.Token, m_emailId, * new Twitter.AccessTokenCallback(this.OnSuccess_AuthenticateTwitter))); * //BrainCloudWrapper.GetBC().AuthenticationService.AuthenticateTwitter() * * //BrainCloudWrapper.GetInstance().AuthenticateEmailPassword( * // m_emailId, m_emailPwd, true, OnSuccess_Authenticate, OnError_Authenticate); * } * }*/ else if (m_selectedAuth == (int)eAuthTypes.ANONYMOUS) { GUILayout.Label("Profile Id: " + BrainCloudWrapper.GetInstance().GetStoredProfileId()); GUILayout.Label("Anonymous Id: " + BrainCloudWrapper.GetInstance().GetStoredAnonymousId()); GUILayout.BeginHorizontal(); if (GUILayout.Button("Authenticate", GUILayout.ExpandWidth(false))) { m_authStatus = "Attempting to authenticate"; BrainCloudWrapper.GetInstance().AuthenticateAnonymous(OnSuccess_Authenticate, OnError_Authenticate); } if (GUILayout.Button("Reset Profile Id", GUILayout.ExpandWidth(false))) { BrainCloudWrapper.GetInstance().ResetStoredProfileId(); } if (GUILayout.Button("Reset Anonymous Id", GUILayout.ExpandWidth(false))) { BrainCloudWrapper.GetInstance().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: " + BrainCloudWrapper.GetInstance().GetStoredProfileId()); GUILayout.Label("Anonymous Id: " + BrainCloudWrapper.GetInstance().GetStoredAnonymousId()); GUILayout.BeginHorizontal(); if (GUILayout.Button("Authenticate", GUILayout.ExpandWidth(false))) { m_authStatus = "Attempting to authenticate"; BrainCloudWrapper.GetInstance().AuthenticateGoogle(m_googleId, m_serverAuthCode, true, OnSuccess_Authenticate, OnError_Authenticate); } if (GUILayout.Button("Reset Profile Id", GUILayout.ExpandWidth(false))) { BrainCloudWrapper.GetInstance().ResetStoredProfileId(); } if (GUILayout.Button("Reset Anonymous Id", GUILayout.ExpandWidth(false))) { BrainCloudWrapper.GetInstance().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(); }