/// <summary>
        /// Deletes a `<see cref="Credential"/>` from the storage used by the authentication object.
        /// </summary>
        /// <param name="targetUri">The uniform resource indicator used to uniquely identify the credentials.</param>
        public override async Task <bool> DeleteCredentials(TargetUri targetUri)
        {
            if (targetUri is null)
            {
                throw new ArgumentNullException(nameof(targetUri));
            }

            Credential credentials = await PersonalAccessTokenStore.ReadCredentials(targetUri);

            // Attempt to validate the credentials, if they're truly invalid delete them.
            if (!await ValidateCredentials(targetUri, credentials))
            {
                await PersonalAccessTokenStore.DeleteCredentials(targetUri);

                // Remove any related entries from the tenant cache because tenant change
                // could the be source of the invalidation, and not purging the cache will
                // trap the user in a limbo state of invalid credentials.

                // Deserialize the cache and remove any matching entry.
                string tenantUrl = targetUri.ToString();
                var    cache     = await DeserializeTenantCache(Context);

                // Attempt to remove the URL entry, if successful serialize the cache.
                if (cache.Remove(tenantUrl))
                {
                    await SerializeTenantCache(Context, cache);
                }

                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Deletes a `<see cref="Credential"/>` from the storage used by the authentication object.
        /// </summary>
        /// <param name="targetUri">The uniform resource indicator used to uniquely identify the credentials.</param>
        public override void DeleteCredentials(TargetUri targetUri)
        {
            BaseSecureStore.ValidateTargetUri(targetUri);

            Credential credentials = PersonalAccessTokenStore.ReadCredentials(targetUri);

            // This ought to be async, but the base type's method isn't.
            Task.Run(async() =>
            {
                // Attempt to validate the credentials, if they're truly invalid delete them.
                if (!await ValidateCredentials(targetUri, credentials))
                {
                    PersonalAccessTokenStore.DeleteCredentials(targetUri);

                    // Remove any related entries from the tenant cache because tenant change
                    // could the be source of the invalidation, and not purging the cache will
                    // trap the user in a limbo state of invalid credentials.

                    // Deserialize the cache and remove any matching entry.
                    string tenantUrl = targetUri.ToString();
                    var cache        = await DeserializeTenantCache();

                    // Attempt to remove the URL entry, if successful serialize the cache.
                    if (cache.Remove(tenantUrl))
                    {
                        await SerializeTenantCache(cache);
                    }
                }
            }).Wait();
        }
Example #3
0
        /// <inheritdoc/>
        public override void DeleteCredentials(TargetUri targetUri, string username)
        {
            BaseSecureStore.ValidateTargetUri(targetUri);

            Trace.WriteLine("BitbucketAuthentication::DeleteCredentials");

            Credential credentials = null;

            if ((credentials = PersonalAccessTokenStore.ReadCredentials(targetUri)) != null)
            {
                // try to delete the credentials for the explicit target uri first
                PersonalAccessTokenStore.DeleteCredentials(targetUri);
                Trace.WriteLine($"host credentials deleted for {targetUri.ActualUri}");
            }

            // tidy up and refresh tokens
            var refreshTargetUri = GetRefreshTokenTargetUri(targetUri);

            if ((credentials = PersonalAccessTokenStore.ReadCredentials(refreshTargetUri)) != null)
            {
                // try to delete the credentials for the explicit target uri first
                PersonalAccessTokenStore.DeleteCredentials(refreshTargetUri);
                Trace.WriteLine($"host refresh credentials deleted for {refreshTargetUri.ActualUri}");
            }
        }
Example #4
0
        /// <summary>
        /// Deletes a set of stored credentials by their target resource.
        /// </summary>
        /// <param name="targetUri">The 'key' by which to identify credentials.</param>
        public override void DeleteCredentials(TargetUri targetUri)
        {
            BaseSecureStore.ValidateTargetUri(targetUri);

            if (PersonalAccessTokenStore.ReadCredentials(targetUri) != null)
            {
                PersonalAccessTokenStore.DeleteCredentials(targetUri);
            }
        }
        /// <summary>
        /// Deletes a <see cref="Credential"/> from the storage used by the authentication object.
        /// </summary>
        /// <param name="targetUri">
        /// The uniform resource indicator used to uniquely identify the credentials.
        /// </param>
        public override void DeleteCredentials(TargetUri targetUri)
        {
            BaseSecureStore.ValidateTargetUri(targetUri);

            if (PersonalAccessTokenStore.ReadCredentials(targetUri) != null)
            {
                PersonalAccessTokenStore.DeleteCredentials(targetUri);
                Git.Trace.WriteLine($"credentials for '{targetUri}' deleted");
            }
        }
        /// <inheritdoc/>
        public override async Task <bool> DeleteCredentials(TargetUri targetUri, string username)
        {
            if (targetUri is null)
            {
                throw new ArgumentNullException(nameof(targetUri));
            }

            Trace.WriteLine($"Deleting Bitbucket Credentials for {targetUri.QueryUri}");

            Credential credentials = null;

            if ((credentials = await PersonalAccessTokenStore.ReadCredentials(targetUri)) != null)
            {
                // try to delete the credentials for the explicit target uri first
                await PersonalAccessTokenStore.DeleteCredentials(targetUri);

                Trace.WriteLine($"host credentials deleted for {targetUri.QueryUri}");
            }

            // tidy up and delete any related refresh tokens
            var refreshTargetUri = GetRefreshTokenTargetUri(targetUri);

            if ((credentials = await PersonalAccessTokenStore.ReadCredentials(refreshTargetUri)) != null)
            {
                // try to delete the credentials for the explicit target uri first
                await PersonalAccessTokenStore.DeleteCredentials(refreshTargetUri);

                Trace.WriteLine($"host refresh credentials deleted for {refreshTargetUri.QueryUri}");
            }

            // if we deleted per user then we should try and delete the host level credentials too if
            // they match the username
            if (targetUri.TargetUriContainsUsername)
            {
                var hostTargetUri   = new TargetUri(targetUri.ToString(false, true, true));
                var hostCredentials = await GetCredentials(hostTargetUri);

                var encodedUsername = Uri.EscapeDataString(targetUri.TargetUriUsername);
                if (encodedUsername != username)
                {
                    Trace.WriteLine($"username {username} != targetUri userInfo {encodedUsername}");
                }

                if (hostCredentials != null && hostCredentials.Username.Equals(encodedUsername))
                {
                    await DeleteCredentials(hostTargetUri, username);
                }
            }

            return(true);
        }
        /// <summary>
        /// Deletes a `<see cref="Credential"/>` from the storage used by the authentication object.
        /// </summary>
        /// <param name="targetUri">The uniform resource indicator used to uniquely identify the credentials.</param>
        public override async Task <bool> DeleteCredentials(TargetUri targetUri)
        {
            BaseSecureStore.ValidateTargetUri(targetUri);

            bool result = false;

            var normalizedTargetUri = NormalizeUri(targetUri);

            if (await PersonalAccessTokenStore.ReadCredentials(normalizedTargetUri) != null)
            {
                result = await PersonalAccessTokenStore.DeleteCredentials(normalizedTargetUri);

                Trace.WriteLine($"credentials for '{normalizedTargetUri}' deleted");
            }

            return(result);
        }
Example #8
0
        /// <inheritdoc/>
        public override void DeleteCredentials(TargetUri targetUri, string username)
        {
            BaseSecureStore.ValidateTargetUri(targetUri);

            Trace.WriteLine($"Deleting Bitbucket Credentials for {targetUri.ActualUri}");

            Credential credentials = null;

            if ((credentials = PersonalAccessTokenStore.ReadCredentials(targetUri)) != null)
            {
                // try to delete the credentials for the explicit target uri first
                PersonalAccessTokenStore.DeleteCredentials(targetUri);
                Trace.WriteLine($"host credentials deleted for {targetUri.ActualUri}");
            }

            // tidy up and delete any related refresh tokens
            var refreshTargetUri = GetRefreshTokenTargetUri(targetUri);

            if ((credentials = PersonalAccessTokenStore.ReadCredentials(refreshTargetUri)) != null)
            {
                // try to delete the credentials for the explicit target uri first
                PersonalAccessTokenStore.DeleteCredentials(refreshTargetUri);
                Trace.WriteLine($"host refresh credentials deleted for {refreshTargetUri.ActualUri}");
            }

            // if we deleted per user then we shoudl try and delete the host level credentials too if
            // they match the username
            if (targetUri.TargetUriContainsUsername)
            {
                var hostTargetUri   = targetUri.GetHostTargetUri();
                var hostCredentials = GetCredentials(hostTargetUri);
                var encodedUsername = Uri.EscapeDataString(targetUri.TargetUriUsername);
                if (encodedUsername != username)
                {
                    Trace.WriteLine($"username {username} != targetUri userInfo {encodedUsername}");
                }

                if (hostCredentials != null && hostCredentials.Username.Equals(encodedUsername))
                {
                    DeleteCredentials(targetUri.GetHostTargetUri(), username);
                }
            }
        }
Example #9
0
        /// <summary>
        /// Deletes a `<see cref="Credential"/>` from the storage used by the authentication object.
        /// </summary>
        /// <param name="targetUri">The uniform resource indicator used to uniquely identify the credentials.</param>
        public override async Task <bool> DeleteCredentials(TargetUri targetUri)
        {
            if (targetUri is null)
            {
                throw new ArgumentNullException(nameof(targetUri));
            }

            bool result = false;

            var normalizedTargetUri = NormalizeUri(targetUri);

            if (await PersonalAccessTokenStore.ReadCredentials(normalizedTargetUri) != null)
            {
                result = await PersonalAccessTokenStore.DeleteCredentials(normalizedTargetUri);

                Trace.WriteLine($"credentials for '{normalizedTargetUri}' deleted");
            }

            return(result);
        }