私はAzureポータルでAzure Active Directoryアプリケーションを登録した後に生成したアプリケーションIDとキーを持っています。PowershellからAzure Active Directoryアクセストークンを取得
このペアとPowershellスクリプトから、私はHTTPリクエストでスクリプトで使用するアクセストークンを生成したいと思います。
C#(下のコードを参照)を使用してアクセストークンを取得できますが、Powershellで同様のことを行う方法がわかりません。 Powershellには既に何かが組み込まれていますか?そうでない場合、誰かが私に解決策を教えてもらえますか?私はこの質問の唯一の人ではないと確信しています。
public static async Task<string> GetAccessTokenAsync(string clientId, string appKey, string resourceId)
{
string aadInstance = "https://login.microsoftonline.com/{0}";
string tenant = "<TENANT>.onmicrosoft.com";
string authority = string.Format(CultureInfo.InvariantCulture, aadInstance, tenant);
AuthenticationContext authContext = new AuthenticationContext(authority);
ClientCredential clientCredential = new ClientCredential(clientId, appKey);
AuthenticationResult authenticationResult = null;
authenticationResult = await authContext.AcquireTokenAsync(resourceId, clientCredential);
return authenticationResult.AccessToken;
}
ありがとうございます!あなたが提供したものと似たこの他の文書を見つけるのを助けたので、これを有効な質問としてマークしてください。 https://gallery.technet.microsoft.com/scriptcenter/How-to-authenticate-Azure-4bb18b78 – user3587624