Xamarin.Forms: Clear cookies in WebViews

If you are authenticating through WebView, and acquire a token on successful login, you may have experienced that on re-login scenarios the authentication details is not requested again, because the browser is storing the previously logged in user. You may have to clear the browser’s cookies section to get rid of the useless previous user’s details.

Go ahead and create a dependency service, because we will write some platform specific code! 🙂

Xamarin.Forms code

Define an interface like this

	public interface IDeviceSpecificService
	{
		void ClearCookies();
	}

And use the code like this

DependencyService.Get<IDeviceSpecificService>().ClearCookies();

Xamarin.Android implementation

[assembly: Dependency(typeof(DeviceSpecificService))]
namespace AnAwesomeCompany.AGreatProject.Presentation.Droid.Implementations
{
	public class DeviceSpecificService : IDeviceSpecificService
	{
		public void ClearCookies()
		{
			Android.Webkit.CookieManager.Instance.RemoveAllCookie();
		}
	}
}

Xamarin.IOS implementation

[assembly: Dependency(typeof(DeviceSpecificService))]
namespace AnAwesomeCompany.AGreatProject.Presentation.IOS.Implementations
{
    public class DeviceSpecificService : IDeviceSpecificService
	{
		public void ClearCookies()
		{
              NSHttpCookieStorage CookieStorage = NSHttpCookieStorage.SharedStorage;
              foreach (var cookie in CookieStorage.Cookies)
                      CookieStorage.DeleteCookie(cookie);
		}
	}
}
This content has 2 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

Android: Get keys signature from keystore

On Windows change directory to:

C:\Program Files (x86)\Java\jre1.8.0_271\bin

Give out the following command for keytool

keytool -list -keystore "C:\source_to_keystorw\keystorefilename.keystore" -storepass supersecurepassword

Results the following:

Keystore type: jks
Keystore provider: SUN

Your keystore contains 1 entry

com.companyname.projectname.appdeliverykey, 2021.05.20., PrivateKeyEntry,
Certificate fingerprint (SHA-256): 44:58:C2:B6:84:0A:9C:E0:09:8A:DD:ED:8C:EC:E7:BD:3D:0F:CC:17:32:BC:77:D6:BB:32:E8:5B:43:25:84:DF

This content has 2 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

Azure DevOps: Setup private NuGet feed with CI

In case you need a private NuGet feed, you can do it in Azure DevOps. This can be handy for businesses reusing their code between several codebases.

What will contain the example

In this tutorial, I will show you how to share code through NuGet packages so that it can be used in multiple projects. The Example will walk you through the game engine of an IDLE game. IDLE games are games that do not require much user interaction. The point of games is that they run or produce even when the user is not playing them. The goods produced offline can eventually be used by the player, to upgrade producers or to buy more producers.

The game engine is developed on the IDLEGAMEENGINE branch. Different games, such as a restaurant game or a programming game, can use this game engine. The games have a common logic of operation, only the story of the games differs. This design helps in development to fix bugs by only having to fix the bug in one place and it will be fixed in all games.

Step 0: Create your shared code

I will not go into details about the implementation of the game engine in this tutorial. The point is to create source code that you want to share with other source code.

Step 1: Create the NuGet feed

Go to your projects Azure DevOps site, and select Artifacts from the list on the left. Push the Create feed button. You can select from several visibility options for the new feed.

Step 2. Automate NuGet package publish to the feed

You probably have a repository with the code, what you want to share. Go To Pipelines on the left, then create a pipeline to get NuGet packages published automatically. (If you are experienced, you can make Release pipelines) In the following sections, i will guide you through how to make a CI pipeline, to pack and publish the NuGet packages automatically every time the main branch gets updated.

Navigate to Pipelines section

Go to pipelines and Select create pipeline button.

Select where do you store the code what you want to publish to your private NuGet feed. In my case, I store the GameEngine code in Azure DevOps, so I will continue with this.

Select the Repository which contains the code to be shared.

Select the desired build template for the project. I’ve implemented the core code in .NET Core, so i will continue with ASP.NET Core.

By default this template creates you a NuGetToolInstaller task, a Nugetcommand Task, and a VS Build task.

We will add a 4th task which can be added by searching for NuGet task.

Set up the tasks parameters as the following: Command should be push. The path to the NuGet packages to publish should be the path where the VSBuild builds the application.

Select the target feed location properly. My target feed is at the same organization, so it will appear in the dropdown list. For External NuGet server, you will need to specify a connector to that resource.

Ensure that, the NuGet package will only build, when the csproj is configured to build as a NuGet package. You will need the following settings for your project in order to make a NuGet from it.

Save the pipeline and run it. If you have configured everything correctly, you will see a lot of green ticks in the progress window

This seems to be well configured

When you navigate to the Artifacts/Packages section, you will see that the NuGet package has been pushed successfully to the private feed.

The recently pushed NuGet will appear here

Step 3.: Use your private repository on your projects

In order to use the recently updated package, you will need to set up your local Visual Studio instance to be able to use your private feed.

Adding a new package source

Go to your VS settings, select the NuGet section, and click on the Sources subsection. Click On add and define the connection details presented by clicking the “Connect to feed” button in the Azure DevOps / artifacts section.

Once you have configured the Visual Studio well, you will see the NuGet Package available when you are trying to add a new package to your proejct.

This content has 2 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.

WordPress WooCommerce: Hide update cart button from checkout page

Add this custom CSS (Customize/Custom CSS) in order to hide the ‘Update cart’ button from the checkout page.

button[name='update_cart']{
    display: none !important
}

The button’s name should differ. Ensure the button’s name with developer tools within your browser.

This content has 2 years. Some of the information in this post may be out of date or no longer work. Please, read this page keeping its age in your mind.