THIS IS NOT POSSIBLE TO PERFORM IN SHAREPOINT ON PREM

By registering a new application in the AAD that have permission to access "Office 365 SharePoint Online" - Read and write managed metadata means that it can now handle your taxonomy on its own without the need of authenticating as a user.

settings_permissions

Select the Office 365 SharePoint Online API.

edit_managed_metadata

And do not I repeat DO NOT forget to press grant permissions. Otherwise you will probably go and wonder why it is not working and probably think that I am lying to you.

grant_permissions

You are now able to manage your terms in termstore using a app-only token.

Good to know is that when using the app-only token registered with the AAD you need to authenticate your application with a certificate. If you have registered your application using the _layouts/15/appregnew.aspx and _layouts/15/appinv.aspx pages you will need to do it the way Mikael Svenson did it (link below).