Had this issue and got it sorted by doing the following:
Make sure the App Permissions in azure is from the Application permissions, not the Delegate permissions because we require Unattended access
Application permission set so it works for me:
- Files.Read.All
- Files.ReadWrite.All
- Sites.Manage.All
- Sites.Read.All
- Sites.ReadWrite.All