当前位置: 首页 > 编程语言 > C#

401UnauthorizedwhensubscribingtopushnotificationsusingExchangeservicesandOAuth分享

时间:2023-04-10 15:59:52 C#

401UnauthorizedwhensubscribingtopushnotificationsusingExchangeservicesandOAuth,如下:varauthenticationTask=awaitauthenticationContext.AcquireTokenAsync("https://outlook.office365.com",newClientCredential(clientID,clientSecret));字符串targetSmtp="user123@mydomain.onmicrosoft.com";ExchangeServiceexchangeService=newExchangeService(ExchangeVersion.Exchange2013);exchangeService.Url=someURL;exchangeService.TraceEnabled=true;exchangeService.TraceFlags=TraceFlags.All;exchangeService.ImpersonatedUserId=newImpersonatedUserId(ConnectingIdType.PrincipalName,"user123"@mydomain.comonmicrosoft);exchangeService.HttpHeaders.Add("X-AnchorMailbox",targetSmtp);exchangeService.Credentials=newOAuthCredentials(authenticationTask.AccessToken);PushSubscription订阅=exchangeService.SubscribeToPushNotifications(new[]{someFolder},newUril,post,EventType.NewMail,EventType.Created,EventType.Deleted,EventType.Modified,EventType.Moved,EventType.Copied);我能够为我的应用程序获取令牌,但是当为用户(user123@mydomain.onmicrosoft.com)订阅推送通知时,我收到“请求失败。远程服务器返回错误:(401)未经授权。“错误更新:尝试按照与此处提到的完全相同的步骤进行操作:AzureAD应用程序访问令牌交换模拟,但对于那些遇到同样问题的人来说仍然得到401,我们需要使用证书(而不是使用客户端密码)来获取已注册应用程序的访问令牌。有关如何执行此操作的更多详细信息,请参阅:https://blogs.msdn.microsoft.com/exchangedev/2015/01/21/building-daemon-or-service-apps-with-office-365-mail-Calendar-and-contactAPI-oauth2-customercredentialflow/以上是C#学习教程:401UnauthorizedsharingofallcontentwhensubscribingtopushnotificationsusingExchangeservicesandOAuth,如果对大家有用需要了解更多C#学习教程,希望大家多多关注—本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:

最新推荐
猜你喜欢