@Madan Bisht here's a sample of code I used to obtain an access token that worked for me:
IPublicClientApplication app = PublicClientApplicationBuilder
.Create("<your client id>")
.WithTenantId("<your tenant id>")
.Build();
AuthenticationResult authResult = null;
authResult = await app.AcquireTokenInteractive(new string[] { "EWS.AccessAsUser.All" }).ExecuteAsync();
if (authResult != null)
{
_AccessToken = authResult.AccessToken;
}
This will open up a login Window for authenticating with Azure AD, and if the user you are logging in as has not already consented to the requested scopes, you will be prompted to consent. The device code flow works similarly, and will ask for consent if not already granted. Another method I found useful was this one:
authResult = await app.AcquireTokenByIntegratedWindowsAuth(new string[] { "EWS.AccessAsUser.All" }).ExecuteAsync();
This will only work if the user has already consented, but I found it useful for a background process to silently acquire a token. I was going to try caching tokens from an interactive login, but the Windows authentication worked, and was simpler.