“无法以静默方式获取令牌。 调用方法AcquireToken“
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; }
给出错误“无法以静默方式获取令牌。调用方法AcquireToken”
请确保该应用程序已在Office 365租户AD下注册,否则您将无法发现并使用Office 365服务。
步骤#1下载示例项目AspNetMvc-with-O365.zip 。
步骤#2在Office 365租户AD下注册应用程序,声明Office 365 Exchange Online>读取用户邮件权限,并将REPLY URL设置为“ http:// localhost:2659 / ”。
步骤#3在web.config文件中,从Azure AD门户复制ClientId,TenantId和Client Secret。
步骤#4在Visual Studio中运行项目并使用Azure AD帐户登录
预期结果应如下:
如果您已获得令牌问题,也可以单击“清除缓存数据库”按钮。