我有 Data Lake Store (Gen-2) 的 clientId 和 clientSecret,我正在寻找一种使用 C# 以编程方式为其创建 SAS 令牌的方法。我浏览了文档,但没有找到创建 SAS 令牌的方法。任何指导将不胜感激。谢谢。
正如 Md Farid Uddin Kiron 所建议的,我使用了这段代码但没有成功:
//Token Request End Point
string tokenUrl = $"https://login.microsoftonline.com/<tenantId>.onmicrosoft.com/oauth2/token";
var tokenRequest = new HttpRequestMessage(HttpMethod.Post, tokenUrl);
//I am Using client_credentials as It is mostly recommended
tokenRequest.Content = new FormUrlEncodedContent(new Dictionary<string, string>
{
["grant_type"] = "client_credentials",
["client_id"] = "--------",
["client_secret"] = "-------",
["resource"] = "https://<datalake gen2 name>.dfs.core.windows.net/"
});
dynamic json;
AccessTokenClass results = new AccessTokenClass();
HttpClient client = new HttpClient();
var tokenResponse = client.SendAsync(tokenRequest).GetAwaiter();
json = tokenResponse.GetResult().Content.ReadAsStringAsync().GetAwaiter();
results = JsonConvert.DeserializeObject<AccessTokenClass>(json);
它给了我状态 400 错误。