使用用户身份验证通过 net sdk 连接数据湖的最佳方式是什么

What is the best way to connect on data lake through net sdk using user authentication

我想将本地文件附加到数据湖上的文件。有人可以 post 举个例子,什么是使用 .net sdk 连接数据湖存储的最佳方式。

此 GitHub 存储库中说明了身份验证:https://azure.microsoft.com/en-us/resources/samples/data-lake-analytics-dotnet-auth-options/

有几个基本步骤: - 收集您需要进行身份验证的信息 - clientids、token audiences、tenantid 等。 - 使用该信息获得证书。该 repo 中的函数 GetCreds_User_Popup 包含交互式最终用户身份验证所需的代码 - 最后,使用凭据创建您需要的 .NET 客户端对象

如果您想在没有登录表单的情况下静默登录,这是解决方案:

    string _username = <your azure username>
    string _pass = <your azure  password>
    string _adlsAccountName = <name of your data lake store>
    string _subId = <your subscription id>
    string localFolderPath = @"<yourfolderpath>"
    string localFilePath = Path.Combine(localFolderPath, "<yourFile>");
    string remoteFolderPath = "/path on data lake/";
    string remoteFilePath = Path.Combine(remoteFolderPath, "yourFileonDataLake");

var tenantId = "<your tenant id>"; //you can find this in right top corner on azure portal
var nativeClientApp_clientId = "1950a258-227b-4e31-a9cf-717495945fc2"; // you can use this one
var activeDirectoryClientSettings = ActiveDirectoryClientSettings.UsePromptOnly(nativeClientApp_clientId, new Uri("urn:ietf:wg:oauth:2.0:oob"));
var creds = UserTokenProvider.LoginSilentAsync(nativeClientApp_clientId, tenantId, _username, _password).Result;
_adlsClient = new DataLakeStoreAccountManagementClient(creds) { SubscriptionId = _subId };
_adlsFileSystemClient = new DataLakeStoreFileSystemManagementClient(creds);

如果您想要在数据湖上登录的表单,只需使用 UserTokenProvider 中的 LoginWithPromptAsyncMethod。

这是设置。现在您可以使用 _adlsFileSystemClient 的上传、追加等。希望这会对某人有所帮助。