简体   繁体   English

获取令牌时Office365 API OutlookServicesClient挂起

[英]Office365 API OutlookServicesClient hangs when acquiring token

I am following the example from here: Get started with Office 365 APIs 我从此处跟踪示例: Office 365 API入门

When my controller action executes, it hangs on the following line inside of var "new OutlookServicesClient" 当我的控制器动作执行时,它挂在var“ new OutlookServicesClient”内部的以下行上

var authResult = await authContext.AcquireTokenSilentAsync(
    dcr.ServiceResourceId,
    new ClientCredential(this.configuration.IdaClientID, this.configuration.IdaClientSecret),
    new UserIdentifier(userObjectId, UserIdentifierType.UniqueId));

I cannot figure out why it is hanging, especially, since AcquireTokenSilentAsync works just fine in the discovery client right before this call. 我无法弄清楚它为什么挂起,尤其是因为AcquireTokenSilentAsync在此调用之前在发现客户端中可以正常工作。

Any help is greatly appreciated. 任何帮助是极大的赞赏。

My Controller Action Method: 我的控制器操作方法:

[Authorize]
public async Task<ActionResult> Index()
{    
    var contacts = new List<ContactItem>();
    var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
    var userObjectId = ClaimsPrincipal.Current.FindFirst(ClaimTypesAdditions.ObjectIdentifier).Value;

    var authContext = new AuthenticationContext(this.configuration.IdaAuthority, new AdalTokenCache(signInUserId));

    try
    {
        var discClient = new DiscoveryClient(
            new Uri(this.configuration.Office365DiscoveryServiceEndpoint),
            async () =>
            {
                var authResult = await authContext.AcquireTokenSilentAsync(
                    this.configuration.Office365DiscoveryResourceID,
                    new ClientCredential(this.configuration.IdaClientID, this.configuration.IdaClientSecret),
                    new UserIdentifier(userObjectId, UserIdentifierType.UniqueId));

                return authResult.AccessToken;
            });

        var dcr = await discClient.DiscoverCapabilityAsync("Contacts");

        var exClient = new OutlookServicesClient(
            dcr.ServiceEndpointUri,
            async () =>
            {
                var authResult = await authContext.AcquireTokenSilentAsync(
                    dcr.ServiceResourceId,
                    new ClientCredential(this.configuration.IdaClientID, this.configuration.IdaClientSecret),
                    new UserIdentifier(userObjectId, UserIdentifierType.UniqueId));

                return authResult.AccessToken;
            });

        var contactsResult = await exClient.Me.Contacts.ExecuteAsync();

        do
        {
            var c = contactsResult.CurrentPage;
            contacts.AddRange(c.Select(contact => new ContactItem { FirstName = contact.GivenName }));

            contactsResult = await contactsResult.GetNextPageAsync();
        }
        while (contactsResult != null);
    }
    catch (AdalException exception)
    {
        if (exception.ErrorCode == AdalError.FailedToAcquireTokenSilently)
        {
            authContext.TokenCache.Clear();
        }
    }

    return this.View("Index", contacts);
}

There is a bug in version of 1.0.34 Microsoft.Office365.OutlookServices.Portable that causes a deadlock in OutlookServiceClient. 1.0.34 Microsoft.Office365.OutlookServices.Portable版本中存在一个错误,该错误导致OutlookServiceClient中的死锁。 Reverting to 1.0.22 seems to work. 恢复到1.0.22似乎可行。

This is documented here https://github.com/OfficeDev/O365-ASPNETMVC-Start/commit/b5652864756636a0b141c222e964aba953357e7a#diff-04c6e90faac2675aa89e2176d2eec7d8R139 这在这里记录https://github.com/OfficeDev/O365-ASPNETMVC-Start/commit/b5652864756636a0b141c222e964aba953357e7a#diff-04c6e90faac2675aa89e2176d2eec7d8R139

And looks to be fixed in the next release as seen here https://github.com/Microsoft/Vipr/commit/aaeff5cb94204c23d7501be8fa74b0260ddc52d9 并有望在下一个版本中得到修复,如此处所示https://github.com/Microsoft/Vipr/commit/aaeff5cb94204c23d7501be8fa74b0260ddc52d9

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM