Well, I eventually found a solution for this.
If you registered your application using Azure AD (as a web application / web API, not your own application), you will receive the client ID and secret key for this application.
The code for obtaining a token without a pop-up window is as follows:
AuthenticationParameters ap = AuthenticationParameters.CreateFromResourceUrlAsync( new Uri(resource+"/api/data/v8.1")).Result; AuthenticationContext ac = new AuthenticationContext(ap.Authority); AuthenticationResult r = await ac.AcquireTokenAsync(ap.Resource, new ClientCredential(clientId,clientSecret));
the resource is the base URL of your Dynamics CRM deployment.
Authentication parameters are detected at runtime, as suggested in this MSDN article .
source share