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);
        }
Example #2
0
        public async Task <string> GetClientIdAsync()
        {
            var getIdResponse = await _cognitoIdentityClient.GetIdAsync(new GetIdRequest()
            {
                IdentityPoolId = IDENTITY_POOL_ID
            });

            this.ClientId = getIdResponse.IdentityId;
            return(this.ClientId);
        }
        /// <inheritdoc/>
        /// <remarks>
        /// ID is retrieved from Cognito and saved to parameter store.
        /// </remarks>
        public async ValueTask <string> GetClientIdAsync(CancellationToken cancellationToken)
        {
            if (string.IsNullOrWhiteSpace(_clientId))
            {
                var getIdResponse = await _cognitoIdentityClient.GetIdAsync(new GetIdRequest
                {
                    IdentityPoolId = IDENTITY_POOL_ID
                }, cancellationToken);

                _clientId = getIdResponse.IdentityId;
                _parameterStore.SetParameter(CLIENT_ID, _clientId);
            }

            return(_clientId);
        }
        /// <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));
        }