C#

AvePoint Cloud Governance は、C#言語用の Software Development Kit (SDK) を提供しています。利用を開始する方法については、以下の説明を参照してください。

1.   以下のコマンドを使用して、AvePoint Cloud Governance クライアントをインストールします。

Install-Package Cloud.Governance.Client

2.   AvePoint Cloud Governance API で認証するには、以下から方法を選択します。

    クライアント ID およびクライアント シークレットを使用した認証

i.    AvePoint Cloud Governance モダン管理センター > 設定 > システム設定 > API 認証プロファイル に移動し、リボン上で [作成] をクリックします。

ii.   名前 プロファイルの名前を入力します。

iii.  クライアント シークレットの期間を構成します。プロファイルの作成日が開始日になります。テキスト ボックスに数値を入力し、ドロップダウン リストから 日間週間か月間年間 を時間単位として選択します。

iv.   この Cloud Governance API アクセス トークンを使用して呼び出せるサービスを定義します。

v.    [保存] をクリックして構成を保存します。

vi.   API 認証の詳細を示す 注意 ウィンドウが表示されます。コピー (Button: Copy) ボタンをクリックして、クライアント シークレットをクリップボードにコピーします。

テキスト, 手紙

自動的に生成された説明

*注意: クライアント シークレットは 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://go-api.avepointonlineservices.com

インサイダー環境 米国東部 (バージニア) データ センター

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 です。

thumbprint

アプリの登録時に使用した .cer 証明書の対応する .pfx 証明書ファイルの拇印です。

TokenLifetimeInMinutes

取得したトークンの有効期限を指定します。時間の単位は分です

username

AvePoint Cloud Governance API の呼び出しに使用される委任ユーザーのユーザー名を指定します。

 

証明書の場合:

private static void GetTokenByClientCertificate()

{

    var client = new HttpClient();

    var disco = client.GetDiscoveryDocumentAsync("{identityServiceUrl}").GetAwaiter().GetResult(); ;

    if (disco.IsError)

    {

        Console.WriteLine(disco.Error);

        return;

    }

    var tokenResponse = client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest

    {

        Address = disco.TokenEndpoint,

        ClientAssertion = new ClientAssertion()

        {

            Type = OidcConstants.ClientAssertionTypes.JwtBearer,

            Value = CreateClientAuthJwt(disco)

        },

        Scope = "cloudgovernance.fullcontrol.all",

    }).GetAwaiter().GetResult();

    if (tokenResponse.IsError)

    {

        Console.WriteLine(tokenResponse.Error);

        return;

    }

    Console.WriteLine(tokenResponse.Json);

}

 

private static string CreateClientAuthJwt(DiscoveryDocumentResponse response)

{

    var clientId = "{client ID}";

    // set exp to 5 minutes

    var tokenHandler = new JwtSecurityTokenHandler { TokenLifetimeInMinutes = 5 };

    var securityToken = tokenHandler.CreateJwtSecurityToken(

        // iss must be the client_id of our application

        issuer: clientId,

        // aud must be the identity provider (token endpoint)

        audience: response.TokenEndpoint,

        // sub must be the client_id of our application

        subject: new ClaimsIdentity(

          new List<Claim> { new Claim("sub", clientId),

          new Claim("username", "{username}"),

          new Claim("jti", Guid.NewGuid().ToString())}),

        // sign with the private key (using RS256 for IdentityServer)

        signingCredentials: new SigningCredentials(

          new X509SecurityKey(new X509Certificate2(LoadCertificate())), "RS256")

    );

    return tokenHandler.WriteToken(securityToken);

}

 

private static X509Certificate2 LoadCertificate()

{

    //Gao certificate

    var store = new X509Store(StoreName.My, StoreLocation.LocalMachine);

    store.Open(OpenFlags.ReadOnly);

    var certificate = store.Certificates.Find(

            X509FindType.FindByThumbprint,

            "{thumbprint}",

            false)[0];

    return certificate;

}

 

クライアント シークレットの場合:

private static void GetTokenByClientSecret()

{

    var client = new HttpClient();

    var disco = client.GetDiscoveryDocumentAsync("https://identity.avepointonlineservices.com ").GetAwaiter().GetResult();

    if (disco.IsError)

    {

        Console.WriteLine(disco.Error);

        return;

    }

    var tokenResponse = client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest

    {

        Address = disco.TokenEndpoint,

        ClientId = "{client id}",

        ClientSecret = "{clientsecret}",

        Scope = "cloudgovernance.fullcontrol.all",

        Parameters = new Parameters() { new KeyValuePair<string, string>("username", "{user name}") }

    }).GetAwaiter().GetResult();

    if (tokenResponse.IsError)

    {

        Console.WriteLine(tokenResponse.Error);

        return;

    }

    Console.WriteLine(tokenResponse.Json);

}

 

3.   AvePoint Cloud Governance API で実行できることの詳細、およびコーディングの詳細と例については、ここ (英語) を参照してください。