我的公司正在研究有关 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();/
ASP.NET Core 使用 Azure Active Directory 进行身份验证并ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 进行身
ASP.NET Core 2.0 Web API Azure Ad v2 令牌授权不起作用ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授权不起作用)
ASP Core Azure Active Directory 登录使用角色ASP Core Azure Active Directory Login use roles(ASP Core Azure Active Directory 登录使用角色)
如何获取守护进程或服务器到 C# ASP.NET Web API 的How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何获取守护进程或服务器到 C# ASP.N
.Net Core 2.0 - 获取 AAD 访问令牌以与 Microsoft Graph.Net Core 2.0 - Get AAD access token to use with Microsoft Graph(.Net Core 2.0 - 获取 AAD 访问令牌以与 Microsoft Graph 一起使用)
异步调用时 Azure KeyVault Active Directory AcquireTokenAAzure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(异步调用时 Azure KeyVault Active Directory AcquireTokenAsync 超