AvePoint Cloud Governance は、PowerShell と統合するための Software Development Kit (SDK) を提供しています。利用を開始する方法については、以下の説明を参照してください。
1. 以下のコマンドを使用して、Cloud Governance PowerShell モジュールをインストールします。
Install-Module -Name Cloud.Governance.Client
*注意: Cloud Governance PowerShell モジュールには、PowerShell 3.0 以上が必要です。
2. AvePoint Cloud Governance API で認証するには、以下から方法を選択します。
•クライアント ID およびクライアント シークレットを使用した認証
i. AvePoint Cloud Governance モダン管理センター > 設定 > システム設定 > API 認証プロファイル に移動し、リボン上で [作成] をクリックします。
ii. 名前 – プロファイルの名前を入力します。
iii. クライアント シークレットの期間を構成します。プロファイルの作成日が開始日になります。テキスト ボックスに数値を入力し、ドロップダウン リストから 日間、週間、か月間、年間 を時間単位として選択します。
iv. この Cloud Governance API アクセス トークンを使用して呼び出せるサービスを定義します。
v. [保存] をクリックして構成を保存します。
vi. API 認証の詳細を示す 注意 ウィンドウが表示されます。コピー ()
ボタンをクリックして、クライアント シークレットをクリップボードにコピーします。
*注意: クライアント シークレットは 1 回のみ表示されます。ウィンドウを閉じると、クライアント シークレットは取得できなくなります。
vii. AvePoint Cloud Governance API で認証するには、以下の例を参照してください。
userPrincipalName パラメーターの値は、AvePoint Cloud Governance API の起動に使用される代理ユーザーのログイン名です。ユーザーのアカウントが AvePoint Online Services に追加されており、AvePoint Cloud Governance のサブスクリプションを持っていることを確認してください。
API URL は、AvePoint Cloud Governance 環境によって異なります。使用している環境に応じて、次の API URL のいずれかを選択してください。
AvePoint Cloud Governance 環境 |
API URL |
本番環境 |
|
インサイダー環境 – 米国東部 (バージニア) データ センター |
https://insider-governance-api-us-east.avepointonlineservices.com |
インサイダー環境 – 東ヨーロッパ (アイルランド) データ センター |
https://insider-governance-api-north-europe.avepointonlineservices.com |
• AvePoint Online Services で登録されたアプリでの認証
*注意: この方法では、この Cloud Governance API アクセス トークンを使用して呼び出せるサービスを制限できません。
i. AvePoint Online Services > システム管理 > アプリの登録 ページに移動して、AvePoint Cloud Governance 用のアプリを登録します。詳細については、アプリの登録の構成 を参照してください。
ii. アプリの登録後、アクセス トークンを取得し、 AvePoint Cloud Governance パブリック API で認証を実行します。アクセス トークンを取得するには、以下の属性を指定してください。
要素 |
説明 |
identityServiceUrl |
本番環境の場合 • https://identity.avepointonlineservices.com を使用します。 |
clientId |
AvePoint Online Services > システム管理 > アプリの登録 で登録されたアプリのアプリケーション (クライアント) ID を指定します。 |
clientsecret |
AvePoint Online Services > システム管理 > アプリの登録 で登録されたアプリのクライアント シークレットを指定します。 |
scope |
アプリに付与される権限を指定します。AvePoint Cloud Governance の場合、値は cloudgovernance.fullcontrol.all です。 |
certificate |
アプリの登録時に使用した .cer 証明書に対応する .pfx 証明書ファイルのパスです。 |
username |
AvePoint Cloud Governance API の呼び出しに使用される委任ユーザーのユーザー名を指定します。 |
証明書の場合:
function Get-IdentityServiceToken { [CmdletBinding()] [OutputType([string])] Param( [Parameter(Mandatory)] [string]$IdentityServiceUri, [Parameter(Mandatory)] [string]$Scope, [Parameter(Mandatory)] [string]$ClientId, [Parameter(Mandatory)] [Alias("Certificate", "Cert")] [System.Security.Cryptography.X509Certificates.X509Certificate2]$SigningCertificate ) PROCESS { 'Calling method: Get-IdentityServiceToken' | Write-Debug $encodedThumbprint = ConvertTo-Base64UrlEncodedString -Bytes $SigningCertificate.GetCertHash() $headerTable = [ordered]@{typ = "JWT"; alg = "RS256"; kid = $encodedThumbprint } $header = $headerTable | ConvertTo-Json -Compress | ConvertTo-Base64UrlEncodedString $now = Get-Date $currentEpochTime = Convert-DateTimeToEpoch -DateTime $now $notBefore = $currentEpochTime $futureEpochTime = Convert-DateTimeToEpoch -DateTime ($now.AddHours(1)) $payloadTable = [ordered]@{sub = $ClientId; jti = ([System.Guid]::NewGuid()).ToString(); iss = $ClientId; aud = $IdentityServiceUri.TrimEnd('/') + "/connect/token"; nbf = $notBefore; exp = $futureEpochTime; iat = $currentEpochTime } $payload = $payloadTable | ConvertTo-Json -Compress | ConvertTo-Base64UrlEncodedString $jwtPlainText = "{0}.{1}" -f $header, $payload $jwtSig = New-JwtRsaSignature -JsonWebToken $jwtPlainText -SigningCertificate $SigningCertificate $ClientAssertion = "{0}.{1}" -f $jwtPlainText, $jwtSig $RequestUri = $IdentityServiceUri.TrimEnd('/') + "/connect/token" $Body = @{ grant_type = 'client_credentials' scope = $Scope username = '{username}' client_assertion_type = 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer' client_assertion = $ClientAssertion } $Response = Invoke-WebRequest -Uri $RequestUri -Method 'POST' -Body $Body return (ConvertFrom-Json $Response).access_token } }
function New-JwtRsaSignature { [CmdletBinding()] [OutputType([string])] Param( [System.Security.Cryptography.X509Certificates.X509Certificate2]$SigningCertificate, [String]$JsonWebToken ) PROCESS { 'Calling method: New-JwtRsaSignature' | Write-Debug $rsaSigFormatter = [System.Security.Cryptography.RSAPKCS1SignatureFormatter]::new() $rsaSigFormatter.SetKey($SigningCertificate.PrivateKey) $rsaSigFormatter.SetHashAlgorithm("SHA256") [byte[]]$message = [System.Text.Encoding]::UTF8.GetBytes($JsonWebToken) $shaAlg = [System.Security.Cryptography.SHA256]::Create() [byte[]]$messageDigest = $shaAlg.ComputeHash($message) $sigBytes = $rsaSigFormatter.CreateSignature($messageDigest) return ConvertTo-Base64UrlEncodedString -Bytes $sigBytes } }
function ConvertTo-Base64UrlEncodedString { [CmdletBinding()] [OutputType([string])] Param ( [Parameter(Position = 0, ParameterSetName = "String", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [string]$InputString,
[Parameter(Position = 1, ParameterSetName = "Byte Array", Mandatory = $false, ValueFromPipeline = $false, ValueFromPipelineByPropertyName = $false)] [byte[]]$Bytes ) PROCESS { [string]$base64UrlEncodedString = ""
if ($PSBoundParameters.ContainsKey("Bytes")) { $output = [Convert]::ToBase64String($Bytes) $output = $output.Split('=')[0] # Remove any trailing '='s $output = $output.Replace('+', '-') # 62nd char of encoding $output = $output.Replace('/', '_') # 63rd char of encoding $base64UrlEncodedString = $output
} else { $encoder = [System.Text.UTF8Encoding]::new() [byte[]]$inputBytes = $encoder.GetBytes($InputString) $base64String = [Convert]::ToBase64String($inputBytes) [string]$base64UrlEncodedString = "" $base64UrlEncodedString = $base64String.Split('=')[0] # Remove any trailing '='s $base64UrlEncodedString = $base64UrlEncodedString.Replace('+', '-'); # 62nd char of encoding $base64UrlEncodedString = $base64UrlEncodedString.Replace('/', '_'); # 63rd char of encoding } return $base64UrlEncodedString } }
function Convert-DateTimeToEpoch { [CmdletBinding()] [OutputType([System.Int64])] Param( [Parameter(Mandatory)] [DateTime]$DateTime ) PROCESS { 'Calling method: Convert-DateTimeToEpoch' | Write-Debug $dtut = $DateTime.ToUniversalTime() [TimeSpan]$ts = New-TimeSpan -Start (Get-Date "01/01/1970") -End $dtut [Int64]$secondsSinceEpoch = [Math]::Floor($ts.TotalSeconds) return $secondsSinceEpoch } }
$cert = (Get-ChildItem -path 'Cert:\*23BA1FFD6E83B92529317F80B55CFADA00877E4A' -Recurse)[0] Get-IdentityServiceToken -IdentityServiceUri "https://identity.avepointonlineservices.com" -Scope cloudgovernance.fullcontrol.all -ClientId '{clientId}' -Cert $cert |
クライアント シークレットの場合:
function Get-IdentityServiceToken { [CmdletBinding()] [OutputType([string])] Param( [Parameter(Mandatory)] [string]$IdentityServiceUri, [Parameter(Mandatory)] [string]$Scope, [Parameter(Mandatory)] [string]$ClientId, [Parameter(Mandatory)] [string]$ClientSecret ) PROCESS { 'Calling method: Get-IdentityServiceToken' | Write-Debug $RequestUri = $IdentityServiceUri.TrimEnd('/') + "/connect/token" $Body = @{ grant_type = 'client_credentials' scope = $Scope username = '{username}' client_id = $ClientId client_secret = $ClientSecret } $Response = Invoke-WebRequest -Uri $RequestUri -Method 'POST' -Body $Body return (ConvertFrom-Json $Response).access_token } }
Get-IdentityServiceToken -IdentityServiceUri "https://identity.avepointonlineservices.com" -Scope cloudgovernance.fullcontrol.all -ClientId '{clientId}' -ClientSecret '******' |
3. AvePoint Cloud Governance API で実行できることの詳細、およびコーディングの詳細と例については、ここ (英語) を参照してください。