2017-08-09 21 views
0

サービスプリンシパルとPowerShellで正常にログインし、Find-AzureRmResourceGroupを使用してリソースグループを一覧表示できます。これはアクセス許可の問題ではありません。Fluent .NET APIを使用してサービスプリンシパルをAzure Resource Managerにアクセスできません

私が成功した.NET流暢APIでユーザーを認証することができます表示されますが、リソースグループを一覧表示しようとする上で、私は

Authentication error while acquiring token: 'get_user_name_failed: Failed to get user name' 

Failed to get user name ---> System.ComponentModel.Win32Exception: No mapping between account names and security IDs was done 

私のF#のソースコードを取得する:

open Microsoft.Azure.Management.ResourceManager.Fluent 
open Microsoft.Azure.Management.Fluent 

//https://docs.microsoft.com/en-us/dotnet/azure/dotnet-sdk-azure-authenticate?view=azure-dotnet#mgmt-auth 
let ClientId = "<Service Principal Application ID>" 
let ServicePrincipalPassword = "<Service Principal Password>" 
let AzureTenantId = "<tenant id goes here>" 
let AzureSubscriptionId = "<subscriptionID>" 

let azureCredentials = 
    let userLoginInformation = Authentication.UserLoginInformation() 
    userLoginInformation.ClientId <- ClientId 
    userLoginInformation.Password <- ServicePrincipalPassword 
    Authentication.AzureCredentials(userLoginInformation, AzureTenantId, AzureEnvironment.AzureGlobalCloud) 

let azure = Azure.Configure().Authenticate(azureCredentials).WithSubscription(AzureSubscriptionId) 

//fails on execution of this line 
let resourceGroups = azure.ResourceGroups.List() |> Seq.cast<IResourceGroup> 

フルエラーとスタックトレース

Microsoft.Rest.Azure.Authentication.AuthenticationException: Authentication error while acquiring token: 'get_user_name_failed: Failed to get user name'. ---> Microsoft.IdentityModel.Clients.ActiveDirectory.AdalException: get_user_name_failed: Failed to get user name ---> System.ComponentModel.Win32Exception: No mapping between account names and security IDs was done 
    --- End of inner exception stack trace --- 
    at Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformSpecificHelper.GetUserPrincipalName() 
    at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenNonInteractiveHandler.<PreRunAsync>d__0.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.IdentityModel.Clients.ActiveDirectory.AcquireTokenHandlerBase.<RunAsync>d__0.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.<AcquireTokenCommonAsync>d__0.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.<AcquireTokenAsync>d__14.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.Rest.Azure.Authentication.UserTokenProvider.<LoginSilentAsync>d__24.MoveNext() 
    --- End of inner exception stack trace --- 
    at Microsoft.Rest.Azure.Authentication.UserTokenProvider.<LoginSilentAsync>d__24.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.Azure.Management.ResourceManager.Fluent.Authentication.AzureCredentials.<ProcessHttpRequestAsync>d__21.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.Azure.Management.ResourceManager.Fluent.ResourceGroupsOperations.<ListWithHttpMessagesAsync>d__12.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.Azure.Management.ResourceManager.Fluent.ResourceGroupsOperationsExtensions.<ListAsync>d__15.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.Azure.Management.ResourceManager.Fluent.ResourceGroupsOperationsExtensions.List(IResourceGroupsOperations operations, ODataQuery`1 odataQuery) 
    at Microsoft.Azure.Management.ResourceManager.Fluent.ResourceGroupsImpl.List() 
    at <StartupCode$FSI_0005>[email protected]() in E:\GitRepos\AzureSandbox\src\AzureSandbox\Scripts\Script1.fsx:line 20 
+0

' System.ComponentModel.Win32Exception'内部例外は、ループのための私を投げていること。それは私がそこに期待しているようなものではありません。 F#については何も分かりませんが、実際にすぐにインストールして、これを再解析できるかどうかを確認します。 –

答えて

1

わかりました。 Authentication.ServicePrincipalInformation()が必要なときにAuthentication.UserLoginInformation()を使用しています。

let azureCredentials =行をこれに置き換えて正常に動作しました。

let azureCredentials = 
    let servicePrincipalInformation = Authentication.ServicePrincipalLoginInformation() 
    servicePrincipalInformation.ClientId <- ClientId 
    servicePrincipalInformation.ClientSecret <- ServicePrincipalPassword 
    Authentication.AzureCredentials(servicePrincipalInformation, AzureTenantId, AzureEnvironment.AzureGlobalCloud) 

`` `

関連する問題