示例#1
0
 void FbLoginCallBack(ILoginResult result)
 {
     if (result.Error == null)
     {
         Debug.Log("Facebook login successfull");
         fbauth = true;
         gauth  = false;
         string uid = AccessToken.CurrentAccessToken.UserId;
         Debug.Log("uid is null");
         if (playerInfo != null && !string.IsNullOrEmpty(playerInfo.Get("uid")) && !uid.Equals(playerInfo.Get("uid")))
         {
             awsCredentials.Clear();
             playerInfo.Delete();
         }
         Debug.Log("aws credentials is null");
         awsCredentials.AddLogin("graph.facebook.com", AccessToken.CurrentAccessToken.TokenString);
         Debug.Log("playerInfo is null");
         playerInfo.SynchronizeOnConnectivity();
         loading = true;
     }
     else
     {
         Debug.Log("Facebook Login unsuccessfully:" + result.Error);
     }
 }
        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();
        }
示例#3
0
        //public CognitoAWSCredentials GetCachedCognitoIdentity()
        //{
        //    Console.WriteLine("GetCachedCognitoIdentity");
        //    if (!string.IsNullOrEmpty(credentials.GetCachedIdentityId()) || credentials.CurrentLoginProviders.Length > 0)
        //    {
        //        return credentials;
        //    }
        //    return null;
        //}

        public async Task GetAWSCredentialsWithGoogleToken(string token)
        {
            try
            {
                CognitoAWSCredentials credentials = new CognitoAWSCredentials(this.IDENTITYPOOL_ID, RegionEndpoint.EUCentral1);
                credentials.Clear();
                credentials.AddLogin("accounts.google.com", token);

                AmazonCognitoIdentityClient cli = new AmazonCognitoIdentityClient(credentials, RegionEndpoint.EUCentral1);

                var req = new Amazon.CognitoIdentity.Model.GetIdRequest();
                req.Logins.Add("accounts.google.com", token);
                req.IdentityPoolId = this.IDENTITYPOOL_ID;

                GetIdResponse getIdResponse = await cli.GetIdAsync(req);

                var getCredentialReq = new Amazon.CognitoIdentity.Model.GetCredentialsForIdentityRequest();
                getCredentialReq.IdentityId = getIdResponse.IdentityId;
                getCredentialReq.Logins.Add("accounts.google.com", token);

                GetCredentialsForIdentityResponse getCredentialsResponse = await cli.GetCredentialsForIdentityAsync(getCredentialReq);

                UserInfo.Credentials = getCredentialsResponse.Credentials;
                UserInfo.IdentityId  = getCredentialsResponse.IdentityId;
            }
            catch (Exception ex)
            {
                Console.WriteLine("GetAWSCredentialsWithGoogleToken ERROR: " + ex.Message);
                throw ex;
            }
        }
        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();
        }
示例#5
0
    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());
    }
 /// <summary>
 /// Wipes all user data cached locally, including identity id, session
 /// credentials, dataset metadata, and all records. Any data that hasn't been
 /// synced will be lost. This method is usually used when customer logs out.
 /// <param name="wipeCredentialsAndID">Wipe Credentials and IdentityID. Defaults as true</param>
 /// </summary>
 public void WipeData(bool wipeCredentialsAndID = true)
 {
     Local.WipeData();
     if (wipeCredentialsAndID)
     {
         cognitoCredentials.Clear();
         _logger.InfoFormat("All datasets and records have been wiped");
     }
     else
     {
         _logger.InfoFormat("All data has been wiped");
     }
 }
    private void OnGUI()
    {
        float ratio = Screen.width / 600.0f;

        GUI.skin.label.fontSize  = (int)(15 * ratio);
        GUI.skin.button.fontSize = (int)(15 * ratio);

        GUI.Label(new Rect(30 * ratio, 30 * ratio, 800 * ratio, 30 * ratio), "Identity: " + myIdentity);

        if (loading)
        {
            return;
        }

        if (loggedIn)
        {
            if (GUI.Button(new Rect(Screen.width / 2 - 80 * ratio, Screen.height / 2 - 40 * ratio, 160 * ratio, 30 * ratio), "GetCognitoId"))
            {
                UpdateIdentity();
            }

            if (GUI.Button(new Rect(Screen.width / 2 - 80 * ratio, Screen.height / 2, 160 * ratio, 30 * ratio), "Clear identity"))
            {
                myIdentity = "";
                credentials.Clear();
            }

            if (GUI.Button(new Rect(Screen.width / 2 - 80 * ratio, Screen.height / 2 + 40 * ratio, 160 * ratio, 30 * ratio), "Logout"))
            {
                Application.LoadLevel(Application.loadedLevel);
                loggedIn = false;
            }
        }
        else
        {
            GUI.skin.button.fontSize = (int)(15 * ratio);
            if (GUI.Button(new Rect(Screen.width / 2 - 80 * ratio, Screen.height / 2 - 20 * ratio, 160 * ratio, 30 * ratio), "Login with Facebook"))
            {
                loading = true;
                FB.Login("email", FacebookLoginCallback);
            }
            if (GUI.Button(new Rect(Screen.width / 2 - 80 * ratio, Screen.height / 2 + 20 * ratio, 160 * ratio, 30 * ratio), "Skip authentication"))
            {
                loading = true;
                InitUnauth();
            }
        }
    }
示例#8
0
    public void FBHasLoggedIn(string token, string id)
    {
        string oldFacebookId = playerInfo.Get("FacebookId");

        if (string.IsNullOrEmpty(oldFacebookId) || id.Equals(oldFacebookId))
        {
            playerInfo.Put("FacebookId", id);
            credentials.AddLogin("graph.facebook.com", token);
        }
        else
        {
            Debug.Log("New user detected.");
            credentials.Clear();
            playerInfo.Delete();
            credentials.AddLogin("graph.facebook.com", token);
            Synchronize();
            StartCoroutine(WaitForEndOfSync(id));
        }
    }
示例#9
0
        //internal async Task<CognitoUser> ResetPassword(string username)
        //{
        //    AmazonCognitoIdentityProviderClient provider = new AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials());

        //    CognitoUserPool userPool = new CognitoUserPool(this.POOL_ID, this.CLIENTAPP_ID, provider);

        //    CognitoUser user = new CognitoUser(username, this.CLIENTAPP_ID, userPool, provider);
        //    await user.ForgotPasswordAsync();
        //    return user;
        //}

        //internal async Task<CognitoUser> UpdatePassword(string username, string code, string newpassword)
        //{
        //    AmazonCognitoIdentityProviderClient provider = new AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials());

        //    CognitoUserPool userPool = new CognitoUserPool(this.POOL_ID, this.CLIENTAPP_ID, provider);

        //    CognitoUser user = new CognitoUser(username, this.CLIENTAPP_ID, userPool, provider);
        //    await user.ConfirmForgotPasswordAsync(code, newpassword);
        //    return user;
        //}

        public async Task ValidateUser(string username, string password)
        {
            try
            {
                AmazonCognitoIdentityProviderClient provider = new AmazonCognitoIdentityProviderClient(new Amazon.Runtime.AnonymousAWSCredentials(), RegionEndpoint.EUCentral1);
                CognitoUserPool userPool = new CognitoUserPool(this.USERPOOL_ID, this.CLIENTAPP_ID, provider);
                CognitoUser     user     = new CognitoUser(username, this.CLIENTAPP_ID, userPool, provider);

                InitiateSrpAuthRequest authRequest = new InitiateSrpAuthRequest();
                authRequest.Password = password;

                AuthFlowResponse authFlowResponse = await user.StartWithSrpAuthAsync(authRequest).ConfigureAwait(false);

                if (authFlowResponse.AuthenticationResult == null)
                {
                    throw new Exception("Cognito authentication error");
                }

                GetUserResponse userDetails = await user.GetUserDetailsAsync();

                string idtoken = authFlowResponse.AuthenticationResult.IdToken;

                //CognitoAWSCredentials creds = user.GetCognitoAWSCredentials(this.IDENTITYPOOL_ID, RegionEndpoint.EUCentral1);
                CognitoAWSCredentials creds = new CognitoAWSCredentials(this.IDENTITYPOOL_ID, RegionEndpoint.EUCentral1);
                creds.Clear();
                //creds.CurrentLoginProviders.SetValue(idtoken, 0);
                //creds.CurrentLoginProviders.SetValue(idtoken, 1);
                creds.AddLogin("cognito-idp." + RegionEndpoint.EUCentral1.SystemName + ".amazonaws.com/" + this.USERPOOL_ID, idtoken);

                UserInfo.Clear();
                UserInfo.Credentials = creds;
                UserInfo.UserId      = userDetails.UserAttributes.Find(x => x.Name.ToLower() == "sub").Value;
                UserInfo.UserName    = user.Username;
                UserInfo.Email       = userDetails.UserAttributes.Find(x => x.Name.ToLower() == "email").Value;
                UserInfo.Picture     = "userphoto";
            }
            catch (Exception ex)
            {
                Console.WriteLine("ValidateUser ERROR: " + ex.Message);
                throw ex;
            }
        }
示例#10
0
 public void Logout()
 {
     Debug.Log("Cognito Identity: Clearing credentials");
     m_credentials.Clear();
     Status = LoginStatus.LoggedOut;
 }