Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# UWP Microsoft.Identity.Client无提示登录_C#_Uwp_Calendar_Win Universal App_Outlook Restapi - Fatal编程技术网

C# UWP Microsoft.Identity.Client无提示登录

C# UWP Microsoft.Identity.Client无提示登录,c#,uwp,calendar,win-universal-app,outlook-restapi,C#,Uwp,Calendar,Win Universal App,Outlook Restapi,我正在使用Microsoft Graph API访问Outlook日历。在我的UWP应用程序中,我使用的是Microsoft.Identity.Client,它在Nuget上可用。这没有问题,但是第一次我想得到一个用户日历,我必须登录。这是我用来验证/获取令牌的代码 private async Task<string> GetTokenForUserAsync() { string tokenForUser = null; string[] Scopes = { "h

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

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;
}

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

一旦用户授权了您的应用程序,您可以尝试使用该类存储用户的帐户信息,以备将来使用。请查看主题并查看该部分。

在尝试了不同的解决方案后,我决定改弦易辙,因为这些解决方案无法满足我的需求。
现在,为了阅读日历,我只需使用Subscribed ics/ical文件,它在未经授权的情况下提供对日历的几乎实时访问。

您拥有身份验证并获得令牌,为什么不直接使用令牌呢?一般来说,如果你有令牌,你应该有一些访问数据源的权限。你是对的,但是令牌必须是第一次获取的,那么我可以调用AcquireTokenSilentAsnc()。我的问题与获取令牌的第一次身份验证有关,我正在寻找一种方法,将电子邮件地址和密码传递给AcquireTokenAsync()任务,而无需填写打开的表单。存储登录从来都不是问题。您的解决方案还可以,但它还需要用户输入,因此我无法在项目中使用它。
authResult = await identityClient.AcquireTokenAsync(Scopes, "myuser@outlook.com");