The code here shows some of the ways of getting an access token by a daemon app (Client) to call an API (Server). We use the methods from the authentication libraries provided by Microsoft to get the access token.
More details can be found in this blog post.