Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.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# &引用;无法以静默方式获取令牌。调用方法AcquireToken“;_C#_Asp.net Mvc_Api_Office365_Adal - Fatal编程技术网

C# &引用;无法以静默方式获取令牌。调用方法AcquireToken“;

C# &引用;无法以静默方式获取令牌。调用方法AcquireToken“;,c#,asp.net-mvc,api,office365,adal,C#,Asp.net Mvc,Api,Office365,Adal,给出错误“无法以静默方式获取令牌。调用方法AcquireToken”请确保应用已在Office 365租户广告下注册,否则您将无法发现和使用Office 365服务 步骤1下载示例项目 步骤#2在Office 365租户广告下注册应用程序,声明Office 365 Exchange Online>读取用户邮件权限,并将回复URL设置为“”。 步骤#3在web.config文件中,从Azure AD portal复制ClientId、TenantId和客户端机密 步骤4在Visual Stud

给出错误“无法以静默方式获取令牌。调用方法AcquireToken”

请确保应用已在Office 365租户广告下注册,否则您将无法发现和使用Office 365服务

步骤1下载示例项目

步骤#2在Office 365租户广告下注册应用程序,声明Office 365 Exchange Online>读取用户邮件权限,并将回复URL设置为“”。

步骤#3在web.config文件中,从Azure AD portal复制ClientId、TenantId和客户端机密

步骤4在Visual Studio中运行项目,并使用Azure AD帐户登录

预期结果如下:


如果您有acquire token问题,也可以单击“清除缓存数据库”按钮。

您看到过类似的问题吗?是的,我已经检查过了,我没有那个错误。伙计们,你们能给我提点别的建议吗?>由于一个复习过程,我把你们的问题难倒了。然而,我对这个问题的了解是有限的。但如果你给它一点时间,有人可能会在它上面难倒。我还为您添加了C#标记,这可能会吸引更多的注意。
try
{
    ClientCredential clientCredential = new ClientCredential("***********","**************");
    UserIdentifier userIdentifier = new UserIdentifier(userObjectId, UserIdentifierType.UniqueId);

    DiscoveryClient discClient = new DiscoveryClient(SettingsHelper.DiscoveryServiceEndpointUri,
        async () =>
        {
            var authResult = await authContext.AcquireTokenSilentAsync(SettingsHelper.DiscoveryServiceResourceId,
                                                                       clientCredential, userIdentifier);

            return authResult.AccessToken;
        });

    var dcr = await discClient.DiscoverCapabilityAsync(capabilityName);

    return new OutlookServicesClient(dcr.ServiceEndpointUri,
        async () =>
        {
            var authResult = await authContext.AcquireTokenSilentAsync(dcr.ServiceResourceId, clientCredential, userIdentifier);
            return authResult.AccessToken;
        });
}
catch (AdalException exception)
{
    //Handle token acquisition failure
    if (exception.ErrorCode == AdalError.FailedToAcquireTokenSilently)
    {
        authContext.TokenCache.Clear();
        throw exception;
    }
    return null;
}