Error making Azure Management Library API call when authenticating with azure active directory(使用 azure Active Directory 进行身份验证时调用 Azure 管理库 API 时出错)
问题描述
我的公司正在研究有关 Azure 的报告.我们只希望我们的客户向我们提供只读凭据以供我们使用.我做了一些研究,看起来 Azure Active Directory 就是这样做的.所以我希望使用只读的 Azure 目录应用程序进行身份验证.
为了让我开始,我关注了这篇关于通过 Azure Active Directory 使用管理 API 的博客.
但是在此 UI 中,我无法为该属性选择任何值.我不确定这是错误还是未完成功能的结果.我在这里遗漏了什么吗?
谢谢
这是我的完整代码供参考:
类程序{静态无效主要(字符串 [] 参数){var token = GetAuthorizationHeader();var credential = new TokenCloudCredentials(ConfigurationManager.AppSettings["subscriptionId"], token);使用 (var computeClient = new ComputeManagementClient(credential)){var images = computeClient.VirtualMachineOSImages.List();}}私有静态字符串 GetAuthorizationHeader(){AuthenticationResult 结果 = null;var context = new AuthenticationContext("https://login.windows.net/" + ConfigurationManager.AppSettings["tenantId"]);字符串 clientId = ConfigurationManager.AppSettings["clientId"];字符串 clientSecret = ConfigurationManager.AppSettings["clientSecret"];ClientCredential clientCred = new ClientCredential(clientId, clientSecret);var thread = new Thread(() =>{结果 = context.AcquireToken("https://management.core.windows.net/",客户信用);});线程.SetApartmentState(ApartmentState.STA);thread.Name = "AquireTokenThread";线程.Start();线程.Join();如果(结果 == 空){throw new InvalidOperationException("获取 JWT 令牌失败");}字符串令牌 = result.AccessToken;返回令牌;}}已经取得了进展.正如我与 Gaurav 讨论的那样,我需要放弃 Azure 管理库,因为目前它似乎不支持 Azure 资源管理器 (ARM) API!所以我做了原始的网络请求.它按预期工作.如果我从我的 AD 应用程序中删除角色访问权限,我会被拒绝访问.当我拥有它时,我会取回数据.
我不确定的一件事是让我的应用程序自动添加到新资源中.
另外,有没有办法列出我的 AD 应用程序可以访问的资源组?
新代码:
类程序{静态无效主要(字符串 [] 参数){var token = GetAuthorizationHeader();string subscriptionId = ConfigurationManager.AppSettings["subscriptionId"];string resourceGroupName = ConfigurationManager.AppSettings["resourceGroupName"];var uriListMachines = string.Format("https://management.azure.com/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Compute/virtualmachines?api-version=2015-05-01-preview", 订阅 ID, 资源组名);var t = WebRequest.Create(uriListMachines);t.ContentType = "应用程序/json";t.Headers.Add("授权", "承载" + token);var response = (HttpWebResponse)t.GetResponse();字符串结果 = "";使用 (var reader = new StreamReader(response.GetResponseStream())){结果 = reader.ReadToEnd();}//原始尝试://var credential = new TokenCloudCredentials(ConfigurationManager.AppSettings["subscriptionId"], token);//使用 (var client = CloudContext.Clients.CreateComputeManagementClient(credential))//{//var images = client.VirtualMachineVMImages.List();/
本文标题为:使用 azure Active Directory 进行身份验证时调用 Azu
基础教程推荐
- WPF 模态进度窗口 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
