gpt4 book ai didi

c# - 如何通过 AAD 对 Azure 服务管理请求进行身份验证

转载 作者:太空狗 更新时间:2023-10-29 20:16:27 27 4
gpt4 key购买 nike

我尝试了3种方法,但没有结果:

  1. 根据这篇文章https://msdn.microsoft.com/en-us/library/azure/ee460782.aspx我已在 AAD 中注册了新的 Web 应用程序,并具有访问 Azure 服务管理 API 的权限(步骤 1-9),并编写了建议的两行代码来获取 token :
    var context = new AuthenticationContext($"https://login.windows.net/{tenantId}");
var result = context.AcquireToken("https://management.core.windows.net/", clientId, new Uri(redirectUri));

,但失败并出现异常:

Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException was unhandled
Message: An unhandled exception of type 'Microsoft.IdentityModel.Clients.ActiveDirectory.AdalServiceException' occurred in Microsoft.IdentityModel.Clients.ActiveDirectory.dll
Additional information: AADSTS90014: The request body must contain the following parameter: 'client_secret or client_assertion'.
Trace ID: aa2d6962-5aea-4f8e-bed4-9e83c7631887
Correlation ID: f7f1a61e-1720-4243-96fa-cff182150931
  • 我也尝试过:
  •     var context = new AuthenticationContext($"https://login.windows.net/{tenantId}");
    var result = context.AcquireToken("https://management.core.windows.net/", new ClientCredential(clientId, clientSecret));

    其中 clientSecret 是我的应用程序的 secret 应用程序 key 。此版本返回一个 token ,但使用此 token 的请求返回403 Forbidden:服务器无法验证请求。验证证书是否有效并与此订阅关联。

  • 我找到的最后一个 http://blogs.msdn.com/b/cloud_solution_architect/archive/2015/03/02/authenticating-azure-service-management-api-with-azure-ad-user-credentials.aspx ,建议:
  •     var context = new AuthenticationContext(string.Format("https://login.windows.net/{0}", tenantId));

    // TODO: Replace with your Azure AD user credentials (i.e. <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c3a2a7aeaaad83a0acadb7acb0acedacadaeaaa0b1acb0aca5b7eda0acae" rel="noreferrer noopener nofollow">[email protected]</a>)
    string user = "{YOUR-USERID]";
    string pwd = "{YOUR-USER-PASSWORD}";
    var userCred = new UserCredential(user, pwd);

    AuthenticationResult result =
    await context.AcquireTokenAsync("https://management.core.windows.net/", clientId, userCred);

    但它也会失败,并出现与第一种情况相同的异常......

    你能帮我一下吗?

    最佳答案

    在 Azure 门户中创建应用程序时,应将“应用程序类型”更改为“ native 客户端应用程序”。

    关于c# - 如何通过 AAD 对 Azure 服务管理请求进行身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33305581/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com