none
Rest Graph API 提示AccessToken无效 RRS feed

  • 问题

  • 我的代码如下:

                var client = new HttpClient();
                var queryString = HttpUtility.ParseQueryString(string.Empty);


                // Specify values for the following required parameters
                queryString["api-version"] = "1.6";
                queryString["Authorization"] = "{我的Token}";
                queryString["Content-Type"] = "application/json";
                // Specify values for path parameters (shown as {...})
                var uri = "https://graph.chinacloudapi.cn/{我的TenantID}/users?" + queryString;

                //Authorization
                //Authentication
                var response = await client.GetAsync(uri);

                if (response.Content != null)
                {
                    var responseString = await response.Content.ReadAsStringAsync();
                    Console.WriteLine(responseString);
                }

    我的Token是使用如下代码获取的:

                AuthenticationContext authenticationContext = new AuthenticationContext("https://login.chinacloudapi.cn/{我的TenantID}", false);
                // Config for OAuth client credentials
                ClientCredential clientCred = new ClientCredential("{我的ClientID}", "{我的PassWord}");
                AuthenticationResult authenticationResult = authenticationContext.AcquireToken("https://graph.chinacloudapi.cn", clientCred);
                string token = authenticationResult.AccessToken;

    但是在执行上面的代码的时候提示我AccessTOken找不到,具体提示错误如下:

    {"odata.error":{"code":"Authentication_MissingOrMalformed","message":{"lang":"en","value":"Access Token missing or malformed."},"values":null}}

    莫不是graph.chinacloudapi.cn没提供这个功能吧?

    2015年11月6日 9:46

答案

  • 你好,

    租户ID,ClientID和ClientSecret 三个参数有没有填写正确呢? 如果都是正确,然后终结点也是中国区的,应该是可以得到token的。

    租户可以在下图的位置找到。

    ID和Secret看下图


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    2015年11月9日 3:38

全部回复

  • 红色区域改为:https://management.core.chinacloudapi.cn/

    2015年11月9日 1:37
  • 修改了,还是一样的错误

    2015年11月9日 2:15
  • 你好,

    >> 莫不是graph.chinacloudapi.cn没提供这个功能吧?

    中国区是有这个功能的。从你的代码上来看,是要在桌面程序中集成Azure AD是吧? 世纪互联的文档中有步骤说明如何集成,还有示例代码。请访问下面的文档查看,http://www.windowsazure.cn/documentation/articles/active-directory-devquickstarts-dotnet/


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2015年11月9日 2:49
  • 你好,

    租户ID,ClientID和ClientSecret 三个参数有没有填写正确呢? 如果都是正确,然后终结点也是中国区的,应该是可以得到token的。

    租户可以在下图的位置找到。

    ID和Secret看下图


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    2015年11月9日 3:38