[英]How to connect and access Azure Datalake Gen1 storage using Azure Ad username and password only - c#
[英]Connect to Azure AD using username/password
我有一個Azure Api REST,可以通過輸入用戶名/密碼來訪問。 我如何從C#訪問此API?
經過一番搜索,我發現有關使用AuthenticationContext ..的東西對我來說不起作用Authenticationcontext .AcquireToken(resource,clientId,credential);
我在哪里可以獲取' resource '參數和ClientID 。
非常感謝
我的大部分工作都基於這篇文章奠定了基礎。
您需要首先在Azure AD中創建本機應用程序,然后添加Windows Azure Service Management API權限。
從此應用程序獲取ClientID 。
這是我當前用於獲取可與Management SDK一起使用的令牌的代碼:
string userName = "yourUserName";
string password = "yourPassword";
string directoryName = "yourDirectory.onmicrosoft.com";
string clientId = "{ClientId obtained by creating an App in the Active Directory}";
var credentials= new UserPasswordCredential(string.Format("{0}@{1}", userName, directoryName), password);
var authenticationContext = new AuthenticationContext("https://login.windows.net/" + directoryName);
var result = await authenticationContext.AcquireTokenAsync("https://management.core.windows.net/", clientID, credentials);
var jwtToken = result.AccessToken;
//Example accesing Azure Cdn Management API
string subscriptionId = "xxxx-xxxxxx-xxxx-xxxxxxx";
using (var cdn = new CdnManagementClient(new TokenCredentials(jwtToken)) { SubscriptionId = subscriptionId })
{
//do something...
}
您可以在Azure門戶> Azure AD部分的域名上獲取目錄名稱 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.