创建DiscoveryClient对象时出错 [英] Error while creating DiscoveryClient object

查看:567
本文介绍了创建DiscoveryClient对象时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在创建DiscoveryClient对象时遇到问题。我试图通过授予所有权限来解决这个问题,然后生成秘密,但我仍然是相同的例外。


 public string discoveryId =" https://api.office.com/discovery/" ;; 

public string cmmAth =" https://login.windows.net/Common" ;;



公共异步任务< OutlookServicesClient> EnsureClientCreatedAsync()
{
try
{
string authority = cmmAth;
_authenticationContext = new AuthenticationContext(authority);
DiscoveryClient discoCli = new DiscoveryClient(async()=> await GetTokenHelperAsync(_authenticationContext,discoveryId));
CapabilityDiscoveryResult discoResult = await discoCli.DiscoverCapabilityAsync(" Calendar");
变种outlookCli =新OutlookServicesClient(discoResult.ServiceEndpointUri,异步()=>等待GetTokenHelperAsync(_authenticationContext,discoResult.ServiceResourceId));
返回outlookCli;

}
catch(AdalException e)
{
MessageBox.Show(e.ToString());
如果(_authenticationContext = NULL和放大器;!&安培;!_authenticationContext.TokenCache = NULL){
_authenticationContext.TokenCache.Clear();
}
返回null;
}
}

public async任务< string> GetTokenHelperAsync(AuthenticationContext context,string resourceId)
{
string accessToken = null;
AuthenticationResult result = null;
ClientCredential cliCred =新ClientCredential(QUOT; XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXX"," yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy = QUOT);
result = await context.AcquireTokenAsync(resourceId,cliCred);
accessToken = result.AccessToken;
返回accessToken;
}

我的AdalException是


 AADSTS70001:在目录api.office.com中找不到标识符为xxxxx-xxxx-xxxx-xxx-xxxxx的应用程序




thx任何帮助


Maciej 






解决方案
确定它花了一些时间,但现在我踩深一点,我得到因错误代码的DiscoveryFailedException未经授权

Hi,

i have an issue creating DiscoveryClient object. I tried to solve this by granting all permissions and THEN generating the secret but i still the same Exception.

       public string discoveryId = "https://api.office.com/discovery/";

       public string cmmAth = "https://login.windows.net/Common";        



public async Task<OutlookServicesClient> EnsureClientCreatedAsync()
        {
            try
            {
                string authority = cmmAth;
                _authenticationContext = new AuthenticationContext(authority);
                DiscoveryClient discoCli = new DiscoveryClient(async () => await GetTokenHelperAsync(_authenticationContext, discoveryId));
                CapabilityDiscoveryResult discoResult = await discoCli.DiscoverCapabilityAsync("Calendar");
                var outlookCli = new OutlookServicesClient(discoResult.ServiceEndpointUri, async () => await GetTokenHelperAsync(_authenticationContext, discoResult.ServiceResourceId));
                return outlookCli;

            }
            catch (AdalException e)
            {
                MessageBox.Show(e.ToString());
                if(_authenticationContext != null && _authenticationContext.TokenCache != null){
                    _authenticationContext.TokenCache.Clear();
                }
                return null;
            }
        }

        public async Task<string> GetTokenHelperAsync(AuthenticationContext context, string resourceId)
        {
            string accessToken = null;
            AuthenticationResult result = null;
            ClientCredential cliCred = new ClientCredential("xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx", "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy=");
            result = await context.AcquireTokenAsync(resourceId, cliCred);
            accessToken = result.AccessToken;
            return accessToken;
        }

and my AdalException is

AADSTS70001: Application with identifier xxxxx-xxxx-xxxx-xxx-xxxxx was not found in the directory api.office.com


thx for any Help

Maciej 

解决方案

Ok it took some time but now i stepped a bit deeper and i am getting an DiscoveryFailedException due to Error Code Unauthorized


这篇关于创建DiscoveryClient对象时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆