How to work the OAuth2 with Nextcloud?

OK, I think I get your problem.

Unfortunaely, I doubt that OAuth2 will help you much here. The NC implementation only allows to authenticate users: third party apps can request and check the validity of a user by means of the question if this user is part of a NC instance. Similar to the common login via google/github/facebook/… on many pages. AFAIK the implementation does not provide authentication, so you cannot use these to login in NC itself. There is another app to provide this but this is a separate issue/topic.

In fact, you are facing an inter-app communication problem. I asked a few months ago a similar question: Integration of apps - best practices.

Regarding the dependency injection issue:
You should be able to

use OCA\GroupFolders\Folder\FolderManager

This is independent of the class is present or not. Then you can do

if (class_exists(FolderManager::class)) { /* ... */ }

You must not use the class unless you know it is reachable by PHP. So you must not simply write a class with the appropriate constructor but you will ost probably have to write the same class twice (like a wrapper) and throw an exception in the case the class was not found. Here is an untested code snippet to get the idea:

if (class_exists(FolderManager::class) {
  class FolderManagerWrapper {
    public function __construct(FolderManager(FolderManager $fm) {
      $this->fm = $fm;
    }
    public function getManager() {
      return $this->fm;
    }
  }
} else {
  class FolderManagerWrapper {
    public function __construct() {
    }
    public function getManager() {
      throw new Exception('The Groupfolder app was not installed');
    }
  }
}

As I said, I have not tested it yet. So you might need to tweak a bit.
Is this what you where looking for?