Example #1
0
        /// <summary>
        /// Gets the Identity Id corresponding to the credentials retrieved from Cognito.
        /// Note: this setting may change during execution. To be notified of its
        /// new value, attach a listener to IdentityChangedEvent
        /// </summary>
        public string GetIdentityId()
        {
            if (!IsIdentitySet)
            {
                var cachedIdentityId = this.GetCachedIdentityId();
                if (string.IsNullOrEmpty(cachedIdentityId))
                {
                    var getIdRequest = new GetIdRequest
                    {
                        AccountId      = AccountId,
                        IdentityPoolId = IdentityPoolId,
                        Logins         = Logins
                    };
#if BCL
                    var response = cib.GetId(getIdRequest);
#else
                    var response = Amazon.Runtime.Internal.Util.AsyncHelpers.RunSync <GetIdResponse>(() => cib.GetIdAsync(getIdRequest));
#endif

                    UpdateIdentity(response.IdentityId, true);
                }
                else
                {
                    UpdateIdentity(cachedIdentityId, false);
                }
            }

            return(identityId);
        }
        /// <summary>
        /// Provides a way to override fetching the identity in case of developer authenticated identities.
        /// The default behaviour will be using Cognito to retrieve the identity id.
        /// </summary>
        /// <returns>returns a <see cref="IdentityState"/></returns>
        protected virtual IdentityState RefreshIdentity()
        {
            bool isCached = true;

            if (!IsIdentitySet)
            {
                var getIdRequest = new GetIdRequest
                {
                    AccountId      = AccountId,
                    IdentityPoolId = IdentityPoolId,
                    Logins         = Logins
                };
#if BCL || UNITY
                var response = cib.GetId(getIdRequest);
#else
                var response = Amazon.Runtime.Internal.Util.AsyncHelpers.RunSync <GetIdResponse>(() => cib.GetIdAsync(getIdRequest));
#endif
                isCached = false;
                UpdateIdentity(response.IdentityId);
            }
            return(new IdentityState(identityId, isCached));
        }