Assuming, the user profiles are maintained and contain the manager for every user, getting the manager with some CSOM code is simple.
PeopleManager peopleManager = new PeopleManager(ctx); ClientResult<string> p = peopleManager.GetUserProfilePropertyFor(accountName, "Manager"); ctx.ExecuteQueryRetry();
The manager could be read from p.Value in the code above. The important part in this snippet is the notation of the accountName. It must be “i:0#.f|membership|username@domain”. The code above will return the manager with the same notation.