Azure的API无法进行身份验证请求 [英] Azure API failed to authenticate the request

查看:218
本文介绍了Azure的API无法进行身份验证请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是下一个code能为Azure的AD身份验证令牌

I am using the next code to get the token for Azure AD authentication

errorMessage = "";
        AuthenticationResult result = null;
        var context = new AuthenticationContext(String.Format(CultureInfo.InvariantCulture, ConfigurationManager.AppSettings["login"], ConfigurationManager.AppSettings["tenantId"]),false);
        ClientCredential clientCredential = new ClientCredential(ConfigurationManager.AppSettings["clientId"], ConfigurationManager.AppSettings["key"]);
        try
        {
            result = context.AcquireToken(ConfigurationManager.AppSettings["apiEndpoint"], clientCredential);
        }
        catch (AdalException ex)
        {
            if (ex.ErrorCode == "temporarily_unavailable")
            {
                errorMessage = "Temporarily Unavailable";
                return null;
            }
            else
            {
                errorMessage = "Unknown Error";
                return null;
            }
        }
        string token = result.AccessToken;
        var credential = new TokenCloudCredentials(ConfigurationManager.AppSettings["subscriptionId"],token);
        //string certificateString = ConfigurationManager.AppSettings["managementCertificate"];
        //var cert = new X509Certificate2(Convert.FromBase64String(base64cer));
        return credential;

在那之后我做的下一步创建在Azure中的网站

After that I am doing the next to create a website in Azure

            using (var computeClient = new WebSiteManagementClient(credentials))
        {
            var result = computeClient.WebSites.IsHostnameAvailable(websiteName);
            if (result.IsAvailable)
            {
                await computeClient.WebSites.CreateAsync(WebSpaceNames.WestEuropeWebSpace, new WebSiteCreateParameters() {
                    Name= websiteName,
                    ServerFarm= ConfigurationManager.AppSettings["servicePlanName"]
                });
            }
            else
            {
                return ResultCodes.ObjectNameAlreadyUsed;
            }
        }

但每次我执行,我得到了以下错误:

But every time I execute that I got the following error:

ForbiddenError:服务器无法验证请求。验证证书是有效的,并与此订阅关联。

ForbiddenError: The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription.

我试过了,因为他们在这里说导入管理证书:
<一href=\"https://www.simple-talk.com/cloud/security-and-compliance/windows-azure-management-certificates/\" rel=\"nofollow\">https://www.simple-talk.com/cloud/security-and-compliance/windows-azure-management-certificates/

I tried to import the management certificate as they said here: https://www.simple-talk.com/cloud/security-and-compliance/windows-azure-management-certificates/

和也试过这样:
http://technetlibrary.com/change-windows-azure-subscription-azure-powershell/198

有关进口管理证书。结果
我也给了应用程序的权限来访问管理API。

For importing management certificate.
Also I gave the application permissions to access management API.

推荐答案

Azure的AD身份验证不使用管理证书认证。

Azure AD Authentication DOES NOT use the management certificate authentication.

有是在MSDN一个很好的文档和code样品就如何解决当前的问题。
身份验证服务管理请求

There is a good documentation and code sample on MSDN on how to resolve your current issue. Authenticating Service Management Requests

这篇关于Azure的API无法进行身份验证请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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