2017-07-18 8 views
1

以下のコードは、認証が機能するところで動作します。しかし、サービス原則を認証として使用しようとすると、認証は失敗します。Azureでサービス原則を使用して古典的なWebロールを取得できません

ワーキングスクリプト:

var context = new AuthenticationContext(azureAdUrl + azureADTenant); 
var credential = new UserPasswordCredential(azureUsername, azurePassword); 
var authParam = new PlatformParameters(PromptBehavior.RefreshSession, null); 
var tokenInfo = context.AcquireTokenAsync("https://management.core.windows.net/", azureADClientId, credential); 

TokenCloudCredentials tokencreds = new TokenCloudCredentials(subscriptionId, tokenInfo.Result.AccessToken); 

ComputeManagementClient computeClient = new ComputeManagementClient(tokencreds); 
string deploymentName = computeClient.Deployments.GetBySlot(serviceName, DeploymentSlot.Production).Name; 
string label = computeClient.Deployments.GetBySlot(serviceName, DeploymentSlot.Production).Label; 

が機能していない:

はAuthenticationFailed:JWTトークンが予想される観客 URI 'https://management.core.windows.net/' が含まれていません。

ClientCredential cc = new ClientCredential(applicationClientID, accessKey); 
var context = new AuthenticationContext("https://login.windows.net/" + AzureTenantId); 
var tokenInfo = context.AcquireTokenAsync("https://management.azure.com/", cc); 

tokenInfo.Wait(); 

if (tokenInfo == null) 
{ 
    throw new InvalidOperationException("Failed to obtain the JWT token"); 
} 

TokenCloudCredentials tokencreds = new TokenCloudCredentials(subscriptionId, tokenInfo.Result.AccessToken); 

ComputeManagementClient computeClient = new ComputeManagementClient(tokencreds); 
string deploymentName = computeClient.Deployments.GetBySlot(serviceName, DeploymentSlot.Production).Name; 

答えて

1

私はService Principalを使用して古典的なAzureのリソースにアクセスすることが可能であるとは思いません。

古典的なAzureリソースは、Service Principalの概念を持たないService Management APIで管理されています。トークンが管理者または共同管理者のために取得された場合にのみトークンをサポートします。

Service Management APIを使用するには、実際のユーザーのユーザー名とパスワードを使用する必要があります。

0

あなたのコードによれば、私は自分の側でそれをテストし、あなたが提供したのと同じ問題に遭遇する可能性があります。そしてGaurav Mantriは合理的な答えを提供しました。 AFAIKは、古典的なAzure Services(ASM)の場合、Authenticate using a management certificateを参照し、management API certificateをアップロードすることができます。ここで

は、あなたがそれを参照してください可能性があり、私のコードスニペットです:

CertificateCloudCredentials credential = new CertificateCloudCredentials("<subscriptionId>",GetStoreCertificate("<thumbprint>")); 
ComputeManagementClient computeClient = new ComputeManagementClient(credential); 
string deploymentName = computeClient.Deployments.GetBySlot("<serviceName>", DeploymentSlot.Production).Name; 

結果:

enter image description here

関連する問題