2016-04-17 9 views
3

Azure REST ApiをAzure Automationから呼び出そうとしているので、authヘッダーを取得する必要があります。私はADALを使っていますが、Azure Automationでは以下の点で失敗します。ADALとAzureの自動化

Azure AutomationでADALを使用する方法は?

ERROR: Exception calling "AcquireToken" with "4" argument(s): "Unable to find an entry point named 'GetPerAdapterInfo' in DLL 'iphlpapi.dll'." At C:\Modules\User\azureadauth\azureadauth.psm1:16 char:5 + $authResult = $authContext.AcquireToken($resourceAppIdURI, $clien ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : EntryPointNotFoundException

ERROR: You cannot call a method on a null-valued expression. At C:\Modules\User\azureadauth\azureadauth.psm1:19 char:5 + $authHeader = $authResult.CreateAuthorizationHeader() + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull

答えて

0

エラーから、オートメーションはテストクラス自体のエントリポイントを見つけることができないようです。

+0

に依存しないように見える方法の自動化接続の証明書を使用してアクセストークンを作成するための別の方法を見つけることによってこの問題を回避することができましたADALアセンブリの – Eosfor

+0

、それはtmyの自動化ではなく、 "Azure Automation service"です。 – Eosfor

0

Azure APIをAzure Automationから呼び出すには、これを行う必要はありません。これにAzure PowerShellコマンドレットを使用できます。Azure PowerShellコマンドレットは、Azure Automationのすぐに出荷され、認証を処理します。詳細はhttps://azure.microsoft.com/en-us/documentation/articles/automation-configuring/をご覧ください。

+0

[Azure Resource Health Service]のAPIを呼び出そうとしています(https://azure.microsoft.com/en-us/blog/reduce-troubleshooting -time-with-azure-resource-health /)とPowerShellの対応がないため、手動でauthヘッダーを取得する必要があります。 – Eosfor

+0

@ Eosfor authヘッダーを取得するためにpowershellを使用できます。 – BenV

+0

@BenV ADALアセンブリを使用してヘッダーを取得していましたが、オートメーションでは機能しません。私はADALがなければそれをすることができるのですか?私を助けてくれますか? – Eosfor

1

同じ問題が発生しました。調査の際に私が見つけたことと、それをどう回避できるかがここにあります。 Azure Graph APIのアクセストークンを作成するために、インターネット上に浮かんでいるサンプルの1つに従っているとします。例として、一般的にこのような何かを見て:

$TenantId = "YourTenantIdHere" 
$authString = "https://login.microsoftonline.com/" + $TenantId 
$resourceUrl = "https://graph.windows.net" 

$authenticationContext = [Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext]::new($authString, $false) 

# Use common client 
$clientId = "1950a258-227b-4e31-a9cf-717495945fc2" 
$redirectUrl = "urn:ietf:wg:oauth:2.0:oob" 

$GraphApiAccessToken = $authenticationContext.AcquireToken($resourceUrl, $clientId, $redirectUrl, [Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior]::Auto).AccessToken 

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]" 
$headers.Add("Authorization", $GraphApiAccessToken) 

はあなたには、ローカル環境とすべてがうまく動いたことを実行しましたが、あなたはAzureの自動アカウントでそれを実行しようとしたとき、あなたはあなたが投稿エラーを得ました。それが私に起こったことだから分かっています。

骨董エラーで言及された「のIphlpapi.dll」ファイルについての詳細を知るために、私は、このコマンドを実行することによって、そのファイルのバージョン情報を一覧表示するAzureのオートメーションアカウントでランブックを作成しました:

(Get-Item C:\Windows\System32\IPHLPAPI.DLL).VersionInfo | fl 

これが結果です:私のローカル環境で同じコマンドを実行する

OriginalFilename : IpHlpApi.dll 
FileDescription : IP Helper API Library 
ProductName  : Microsoft® Windows® Operating System 
Comments   : 
CompanyName  : Microsoft Corporation 
FileName   : C:\Windows\System32\IPHLPAPI.DLL 
FileVersion  : 6.2.9200.2203 (x64fre.140823-0405) 
ProductVersion : 6.2.9200.2203 
IsDebug   : False 
IsPatched   : False 
IsPreRelease  : False 
IsPrivateBuild : False 
IsSpecialBuild : False 
Language   : English (United States) 
LegalCopyright : © Microsoft Corporation. All rights reserved. 
LegalTrademarks : 
PrivateBuild  : 
SpecialBuild  : 
FileVersionRaw : 6.2.9200.2203 
ProductVersionRaw : 6.2.9200.2203 

をもたらした:

OriginalFilename : iphlpapi.dll.mui 
FileDescription : IP Helper API 
ProductName  : Microsoft® Windows® Operating System 
Comments   : 
CompanyName  : Microsoft Corporation 
FileName   : C:\Windows\System32\IPHLPAPI.DLL 
FileVersion  : 10.0.15063.0 (WinBuild.160101.0800) 
ProductVersion : 10.0.15063.0 
IsDebug   : False 
IsPatched   : False 
IsPreRelease  : False 
IsPrivateBuild : False 
IsSpecialBuild : False 
Language   : English (United States) 
LegalCopyright : © Microsoft Corporation. All rights reserved. 
LegalTrademarks : 
PrivateBuild  : 
SpecialBuild  : 
FileVersionRaw : 10.0.15063.0 
ProductVersionRaw : 10.0.15063.0 

Azure Automation Accountのファイルのバージョンがはるかに古いため、AzureRm.Profileモジュールと互換性がないようです。

私は、AcquireTokenが関数である「のIphlpapi.dll」

$servicePrincipalConnection = Get-AutomationConnection -Name 'YourAzureAutomationConnectionNameHere' 
$tenantId = 'YourTenantIdHere' 

$certificate = Get-AutomationCertificate -Name 'YourAutomationConnectionCertificateNameHere' 

$authorizationUrl = "https://login.microsoftonline.com/$tenantId" 
$resourceUrl = "https://graph.windows.net" 

$authenticationContext = [Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext]::new($authorizationUrl, $false) 

$assertionCert = new-object Microsoft.IdentityModel.Clients.ActiveDirectory.ClientAssertionCertificate($servicePrincipalConnection.ApplicationId, $certificate) 

$accessToken = $authenticationContext.AcquireToken($resourceUrl, $assertionCert).AccessToken 
関連する問題