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.
Select the Office 365 SharePoint Online API.
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.
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).
- A good article to read about this is the one from Microsoft regarding the topic of granting access via Azure AD: Granting access via Azure AD App-Only
- Mikael Svenson linked a solution to this problem on twitter: Modifying terms using app-only tokens in SharePoint – undocumented work-around