UWP Microsoft.Identity.Client 无提示通过登录

UWP Microsoft.Identity.Client pass login without promt

我正在使用 Microsoft Graph API 访问 Outlook 日历。在我的 UWP 应用程序中,我使用的是 Nuget 上提供的 Microsoft.Identity.Client。这没有问题,但我第一次想要获得用户日历,我必须登录。这是我用于验证/获取令牌的代码

private async Task<string> GetTokenForUserAsync()
{
    string tokenForUser = null;
    string[] Scopes = { "https://graph.microsoft.com/Calendars.Read" };

    PublicClientApplication identityClient = new PublicClientApplication(clientId);
    AuthenticationResult authResult;
    IEnumerable<IUser> users = identityClient.Users;

    if (users.Count() > 0)
    {
        try
        {
            authResult = await identityClient.AcquireTokenSilentAsync(Scopes, users.First());
            tokenForUser = authResult.AccessToken;
        }
        catch
        {
            tokenForUser = null;
        }
    }
    else
    {
        try
        {
            authResult = await identityClient.AcquireTokenAsync(Scopes);
            tokenForUser = authResult.AccessToken;
        }
        catch
        {
            tokenForUser = null;
        }
    }

    return tokenForUser;
}

第一次调用此任务时,我必须在打开的某种 WebView 中使用我的 Outlook 凭据登录。在第一个请求之后,就不再需要了,因为 identityClient.Users 确实包含我的登录用户。 现在我试图实现的是我可以对我的登录进行硬编码并将其传递给身份验证。但我发现的唯一一件事是能够通过 AcquireTokenAsync() 重载

提供登录用户名(Outlook 邮件地址)
authResult = await identityClient.AcquireTokenAsync(Scopes, "myuser@outlook.com");

但是此方法内部没有重载来提供密码。那么还有其他选择可以将密码传递给这个电话吗?我使用 REST API 的主要原因是因为此应用程序在 Windows 10 IoT Core 上 运行,并且没有可用的 AppointmentStore(本地日历)。

你可以尝试使用WebAccount class to store the user's account information for future use once a user has authorized your app once. Please see the Web Account Manager topic and look into the Store the account for future use部分。

在尝试了不同的解决方案后,但没有提供我正在寻找的东西,我决定走另一条路。 现在为了阅读日历,我只使用订阅的 ics / ical 文件,它提供了几乎实时的日历访问,无需授权。