public void AddAuthentication(string provider, string authToken) { Debug.Log("Cognito Identity: Adding login provider: " + provider + " auth: " + authToken + " to Cognito Id: " + m_credentials.GetCachedIdentityId()); m_credentials.AddLogin(provider, authToken); string guestName = m_guestIdCache.GetNameById(m_credentials.GetCachedIdentityId()); RefreshIdentity(guestName); }
public void CredentialsTests() { CognitoAWSCredentials cred1 = new CognitoAWSCredentials(poolId, ActualEndpoint); string id1 = null, id2 = null, id3 = null; AutoResetEvent ars = new AutoResetEvent(false); cred1.GetIdentityIdAsync((result) => { id1 = result.Response; ars.Set(); }, new Amazon.Runtime.AsyncOptions() { ExecuteCallbackOnMainThread = false }); ars.WaitOne(); Utils.AssertFalse(string.IsNullOrEmpty(id1)); var cred2 = new CognitoAWSCredentials(poolId, ActualEndpoint); cred2.GetIdentityIdAsync((result) => { id2 = result.Response; ars.Set(); }, new Amazon.Runtime.AsyncOptions() { ExecuteCallbackOnMainThread = false }); ars.WaitOne(); Utils.AssertFalse(string.IsNullOrEmpty(id2)); Assert.AreEqual(id1, id2); cred1.Clear(); Utils.AssertStringIsNullOrEmpty(cred1.GetCachedIdentityId()); cred1.GetIdentityIdAsync((result) => { id3 = result.Response; ars.Set(); }, new Amazon.Runtime.AsyncOptions() { ExecuteCallbackOnMainThread = false }); ars.WaitOne(); Assert.IsNotNull(id3); Assert.AreNotEqual(id1, id3); cred1.Clear(); cred2.Clear(); }
public void MultipleIdentityPoolTests() { CreatePool(); Utils.AssertTrue(allPoolIds.Count == 2); var pool1 = allPoolIds[0]; var pool2 = allPoolIds[1]; var cred1 = new CognitoAWSCredentials(pool1, ActualEndpoint); var cred2 = new CognitoAWSCredentials(pool2, ActualEndpoint); string id1 = null, id2 = null; AutoResetEvent ars = new AutoResetEvent(false); cred1.GetIdentityIdAsync((result) => { id1 = result.Response; ars.Set(); }, new Amazon.Runtime.AsyncOptions() { ExecuteCallbackOnMainThread = false }); ars.WaitOne(); Utils.AssertFalse(string.IsNullOrEmpty(id1)); cred2.GetIdentityIdAsync((result) => { id2 = result.Response; ars.Set(); }, new Amazon.Runtime.AsyncOptions() { ExecuteCallbackOnMainThread = false }); ars.WaitOne(); Utils.AssertFalse(string.IsNullOrEmpty(id2)); Assert.AreNotEqual(id1, id2); cred1.Clear(); Utils.AssertStringIsNullOrEmpty(cred1.GetCachedIdentityId()); cred2.Clear(); cred1.Clear(); }
/// <summary> /// A helper function to get the identity id of the dataset from credentials /// provider. If the identity id is null, UNKNOWN_IDENTITY_ID will be /// returned. /// </summary> /// <returns>The identity identifier.</returns> /// <param name="provider">Provider.</param> public static string GetIdentityId(CognitoAWSCredentials credentials) { return(string.IsNullOrEmpty(credentials.GetCachedIdentityId()) ? UNKNOWN_IDENTITY_ID : credentials.GetCachedIdentityId()); }
void OnGUI() { float ratio = Screen.width / 600.0f; GUI.skin.label.fontSize = (int)(15 * ratio); GUI.skin.button.fontSize = (int)(15 * ratio); if (syncManager == null) { GUILayout.Space(20); GUILayout.Label("Please setup the Cognito credentials"); return; } if (GetComponent <CharacterList> ().enabled) { if (GUI.Button(new Rect(30 * ratio, 30 * ratio, 120 * ratio, 30 * ratio), "Save")) { SaveToDataset(); } else if (GUI.Button(new Rect(30 * ratio, 70 * ratio, 120 * ratio, 30 * ratio), "Load")) { LoadFromDataset(); } else if (GUI.Button(new Rect(Screen.width - 150 * ratio, 30 * ratio, 120 * ratio, 30 * ratio), "Logout")) { if (credentials.CurrentLoginProviders.Length > 0) //Auth identity { if (FB.IsLoggedIn) { FB.Logout(); } credentials.Clear(); syncManager.WipeData(); } Application.LoadLevel(Application.loadedLevel); } if (credentials.CurrentLoginProviders.Length == 0) //Unauth { if (GUI.Button(new Rect(Screen.width - 150 * ratio, 70 * ratio, 120 * ratio, 30 * ratio), "Link with FB")) { GetComponent <CharacterList> ().enabled = false; //Disable GUI FB.Login("email", FacebookLoginCallback); } } } else { GUI.Label(new Rect(30 * ratio, 30 * ratio, 120 * ratio, 30 * ratio), "Please wait..."); } GUI.Label(new Rect(20 * ratio, Screen.height - 50 * ratio, 600 * ratio, 30 * ratio), "Identity: " + credentials.GetCachedIdentityId()); }